|
@@ -1,12 +1,10 @@
|
|
|
from fastapi import APIRouter, Form, Depends, HTTPException, File, UploadFile
|
|
|
from typing import List
|
|
|
from fastapi.responses import FileResponse
|
|
|
-import os
|
|
|
from random import randint
|
|
|
-import uuid
|
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
|
from app.models.models import User,Favorite_course
|
|
|
-from app.models.models import Class_list,Schools,Class_detail,Class_name,Registration,School_group
|
|
|
+from app.models.models import Class_list,Schools,Class_detail,Class_name,Registration,Group_name
|
|
|
from app.api import deps
|
|
|
from sqlalchemy.orm import Session
|
|
|
from typing import Any, Dict
|
|
@@ -17,9 +15,7 @@ from datetime import timedelta,datetime
|
|
|
from app.config import settings
|
|
|
from pathlib import Path
|
|
|
from jose import jwt
|
|
|
-import emails
|
|
|
from emails.template import JinjaTemplate
|
|
|
-import logging
|
|
|
from tortoise.queryset import Q
|
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
|
@@ -106,6 +102,12 @@ async def insert_event(
|
|
|
remark : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
+
|
|
|
+ # 檢查是否有該課程
|
|
|
+ class_name_list = await Class_name.filter(id=name_id).all()
|
|
|
+ if class_name_list == []:
|
|
|
+ return {"msg": "沒有此課程", "code": 200}
|
|
|
+
|
|
|
new_class = await Class_list.create(
|
|
|
name_id=name_id,
|
|
|
event =event,
|
|
@@ -121,6 +123,7 @@ async def insert_event(
|
|
|
registration_way=registration_way,
|
|
|
remark=remark
|
|
|
)
|
|
|
+
|
|
|
return {"msg": "success", "code": 200, "class_id": new_class.id}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
@@ -328,7 +331,7 @@ async def delete_session(id: int):
|
|
|
await Class_detail.filter(id=id).delete()
|
|
|
return {"msg": "success", "code": 200}
|
|
|
|
|
|
-@classes.post("/delete_class")
|
|
|
+@classes.post("/delete_event")
|
|
|
async def delete(id: int):
|
|
|
if id:
|
|
|
await Class_detail.filter(class_list_id=id).delete()
|
|
@@ -398,10 +401,10 @@ async def get_school():
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
-@classes.get("/get_school_group")
|
|
|
+@classes.get("/get_group_name")
|
|
|
async def get_school_group():
|
|
|
try:
|
|
|
- school_group_list = await School_group.all()
|
|
|
+ school_group_list = await Group_name.all()
|
|
|
school_groups = []
|
|
|
for school_obj in school_group_list:
|
|
|
school_data = {
|
|
@@ -559,7 +562,7 @@ async def add_favorite_class(
|
|
|
user_id=user_id,
|
|
|
defaults={'time_stemp': time_stemp}
|
|
|
)
|
|
|
- return {"msg": "success", "code": 200,"id":new_favorite_class}
|
|
|
+ return {"msg": "success", "code": 200,"is exist": not new_favorite_class[1],"id":new_favorite_class[0].id}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
@@ -582,8 +585,6 @@ async def get_favorite_class(
|
|
|
return {"msg": "success", "code": 200, "school_groups": favorite_courses}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
@classes.post("/delete_favorite_class")
|
|
|
async def delete_favorite_class(
|