Spaces:
Running
Running
Update project_controller.py
Browse files- project_controller.py +24 -0
project_controller.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from fastapi import APIRouter, HTTPException, Request, Depends
|
2 |
from config_provider import get_config, service_config
|
3 |
from service_config import ServiceConfig
|
|
|
4 |
import datetime
|
5 |
import json
|
6 |
import copy
|
@@ -230,3 +231,26 @@ def clear_all(config: ServiceConfig = Depends(get_config)):
|
|
230 |
json.dump(config, f, indent=2)
|
231 |
|
232 |
return {"message": "All projects cleared"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import APIRouter, HTTPException, Request, Depends
|
2 |
from config_provider import get_config, service_config
|
3 |
from service_config import ServiceConfig
|
4 |
+
from utils import save_service_config, log
|
5 |
import datetime
|
6 |
import json
|
7 |
import copy
|
|
|
231 |
json.dump(config, f, indent=2)
|
232 |
|
233 |
return {"message": "All projects cleared"}
|
234 |
+
|
235 |
+
@router.post("/project/new-version")
|
236 |
+
def create_new_version(base_version_id: int, config: ServiceConfig = Depends(get_config)):
|
237 |
+
try:
|
238 |
+
project = config.get_current_project()
|
239 |
+
base_version = next((v for v in project['versions'] if v['no'] == base_version_id), None)
|
240 |
+
if not base_version:
|
241 |
+
raise HTTPException(status_code=404, detail="Base version not found")
|
242 |
+
|
243 |
+
new_version_no = max(v['no'] for v in project['versions']) + 1
|
244 |
+
new_version = copy.deepcopy(base_version)
|
245 |
+
new_version['no'] = new_version_no
|
246 |
+
new_version['published'] = False
|
247 |
+
project['versions'].append(new_version)
|
248 |
+
|
249 |
+
save_service_config(config)
|
250 |
+
log(f"✅ New version {new_version_no} created for project {project['name']}")
|
251 |
+
return { "status": "success", "new_version": new_version_no }
|
252 |
+
|
253 |
+
except Exception as e:
|
254 |
+
log(f"❌ Error creating new version: {str(e)}")
|
255 |
+
raise HTTPException(status_code=500, detail="Failed to create new version")
|
256 |
+
|