first commit
This commit is contained in:
parent
b216a187bd
commit
f73c77f548
119 changed files with 4504 additions and 4829 deletions
0
backend/utils/__init__.py
Normal file
0
backend/utils/__init__.py
Normal file
BIN
backend/utils/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
backend/utils/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
backend/utils/__pycache__/data_loader.cpython-313.pyc
Normal file
BIN
backend/utils/__pycache__/data_loader.cpython-313.pyc
Normal file
Binary file not shown.
BIN
backend/utils/__pycache__/enums.cpython-313.pyc
Normal file
BIN
backend/utils/__pycache__/enums.cpython-313.pyc
Normal file
Binary file not shown.
BIN
backend/utils/__pycache__/json_crud.cpython-313.pyc
Normal file
BIN
backend/utils/__pycache__/json_crud.cpython-313.pyc
Normal file
Binary file not shown.
8
backend/utils/data_loader.py
Normal file
8
backend/utils/data_loader.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
DATA_DIR = os.path.join(os.path.dirname(__file__), '../data')
|
||||
|
||||
def load_data(filename):
|
||||
with open(os.path.join(DATA_DIR, filename), 'r') as f:
|
||||
return json.load(f)
|
||||
21
backend/utils/enums.py
Normal file
21
backend/utils/enums.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
enumerates = {
|
||||
"status": [
|
||||
"En cours",
|
||||
"Terminé",
|
||||
"Futur projet"
|
||||
],
|
||||
"technologies": [
|
||||
"HTML & CSS",
|
||||
"Python",
|
||||
"Django",
|
||||
"React",
|
||||
"NodeJS",
|
||||
"Angular",
|
||||
"C#",
|
||||
"PHP",
|
||||
"Javascript",
|
||||
"TypeScript",
|
||||
"Unity",
|
||||
"Godot"
|
||||
],
|
||||
}
|
||||
33
backend/utils/json_crud.py
Normal file
33
backend/utils/json_crud.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
def load_json(filename):
|
||||
if not os.path.exists(filename):
|
||||
return []
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
|
||||
def save_json(filename, data):
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||
|
||||
def add_entry(filename, entry):
|
||||
data = load_json(filename)
|
||||
data.append(entry)
|
||||
save_json(filename, data)
|
||||
return entry
|
||||
|
||||
def update_entry(filename, entry_id, new_entry):
|
||||
data = load_json(filename)
|
||||
for i, item in enumerate(data):
|
||||
if item.get('id') == entry_id:
|
||||
data[i] = new_entry
|
||||
save_json(filename, data)
|
||||
return new_entry
|
||||
return None
|
||||
|
||||
def delete_entry(filename, entry_id):
|
||||
data = load_json(filename)
|
||||
new_data = [item for item in data if item.get('id') != entry_id]
|
||||
save_json(filename, new_data)
|
||||
return len(data) != len(new_data)
|
||||
Loading…
Add table
Add a link
Reference in a new issue