|
@@ -1,10 +1,10 @@
|
|
|
from fastapi import APIRouter, Form, Depends, HTTPException, File, UploadFile
|
|
|
-from typing import List
|
|
|
+from typing import List,Optional
|
|
|
from fastapi.responses import FileResponse
|
|
|
from random import randint
|
|
|
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,Group_name
|
|
|
+from app.models.models import Class_list,Schools,Class_detail,Class_name,Registration,Group_name,Online_course
|
|
|
from app.api import deps
|
|
|
from sqlalchemy.orm import Session
|
|
|
from typing import Any, Dict
|
|
@@ -99,6 +99,7 @@ async def insert_event(
|
|
|
people : str = Form(default=''),
|
|
|
fee_method: str = Form(default=''),
|
|
|
registration_way: str = Form(default=''),
|
|
|
+ registration_day: str = Form(default=''),
|
|
|
remark : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
@@ -121,6 +122,7 @@ async def insert_event(
|
|
|
people=people,
|
|
|
fee_method=fee_method,
|
|
|
registration_way=registration_way,
|
|
|
+ registration_day=registration_day,
|
|
|
remark=remark
|
|
|
)
|
|
|
|
|
@@ -133,10 +135,16 @@ async def insert_session(
|
|
|
class_event_id : int = Form(default=0),
|
|
|
start_time: datetime = Form(default=datetime.now()),
|
|
|
end_time: datetime = Form(default=datetime.now()),
|
|
|
- sessions: str = Form(default=0),
|
|
|
content : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
+ session_list = await Class_detail.filter(class_list_id=class_event_id).all()
|
|
|
+ session = 1
|
|
|
+ if session_list != []:
|
|
|
+ for session_obj in session_list:
|
|
|
+ if session <= session_obj.sessions:
|
|
|
+ session = session_obj.sessions
|
|
|
+
|
|
|
new_session = await Class_detail.create(
|
|
|
class_list_id=class_event_id,
|
|
|
start_time=start_time,
|
|
@@ -241,6 +249,7 @@ async def update_class(
|
|
|
people : str = Form(default=''),
|
|
|
fee_method: str = Form(default=''),
|
|
|
registration_way: str = Form(default=''),
|
|
|
+ registration_day: str = Form(default=''),
|
|
|
remark : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
@@ -279,6 +288,9 @@ async def update_class(
|
|
|
if registration_way.strip() != '':
|
|
|
class_obj.registration_way = registration_way
|
|
|
|
|
|
+ if registration_day.strip() != '':
|
|
|
+ class_obj.registration_day = registration_day
|
|
|
+
|
|
|
if remark.strip() != '':
|
|
|
class_obj.remark = remark
|
|
|
|
|
@@ -372,6 +384,7 @@ async def search_event(class_name_id: int = 0):
|
|
|
"people": class_obj.people,
|
|
|
"fee_method": class_obj.fee_method,
|
|
|
"registration_way": class_obj.registration_way,
|
|
|
+ "registration_day": class_obj.registration_day,
|
|
|
"remark": class_obj.remark
|
|
|
}
|
|
|
classes.append(class_data)
|
|
@@ -381,9 +394,15 @@ async def search_event(class_name_id: int = 0):
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
@classes.get("/get_school")
|
|
|
-async def get_school():
|
|
|
+async def get_school(
|
|
|
+ location_id : Optional[int] = None
|
|
|
+):
|
|
|
try:
|
|
|
- school_list = await Schools.all()
|
|
|
+ if location_id :
|
|
|
+ school_list = await Schools.filter(id = location_id).all()
|
|
|
+ else :
|
|
|
+ school_list = await Schools.all()
|
|
|
+
|
|
|
schools = []
|
|
|
for school_obj in school_list:
|
|
|
school_data = {
|
|
@@ -429,14 +448,17 @@ async def get_class_name(
|
|
|
else :
|
|
|
class_name_list = await Class_name.filter(id = class_name_id).all()
|
|
|
else:
|
|
|
- class_name_list = await Class_name.filter(school_id = location_id).all()
|
|
|
+ if class_name_id != 0 :
|
|
|
+ class_name_list = await Class_name.filter(school_id = location_id,id = class_name_id).all()
|
|
|
+ else:
|
|
|
+ class_name_list = await Class_name.filter(school_id = location_id).all()
|
|
|
|
|
|
classes_name = []
|
|
|
for class_name_obj in class_name_list:
|
|
|
school_obj = await Schools.filter(id=class_name_obj.school_id).all()
|
|
|
school_name = ""
|
|
|
if school_obj == []:
|
|
|
- school_name = "未設定據點"
|
|
|
+ school_name = "未設定該據點"
|
|
|
else :
|
|
|
school_obj = await Schools.get(id=class_name_obj.school_id)
|
|
|
school_name = school_obj.name
|
|
@@ -600,6 +622,98 @@ async def delete_favorite_class(
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
+@classes.post("/insert_online_course")
|
|
|
+async def insert_online_course(
|
|
|
+ title : str = Form(default=''),
|
|
|
+ category : str = Form(default=''),
|
|
|
+ create_time :str = Form(default=datetime.now()),
|
|
|
+ content : str = Form(default=''),
|
|
|
+ vedio_url :str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ new_online_course = await Online_course.create(
|
|
|
+ title=title,
|
|
|
+ create_time=create_time,
|
|
|
+ category=category,
|
|
|
+ content=content,
|
|
|
+ vedio_url=vedio_url,
|
|
|
+ group_id = 8
|
|
|
+ )
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "online_course_obj": new_online_course.id}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@classes.post("/update_online_course")
|
|
|
+async def update_online_course(
|
|
|
+ id : int = Form(default=0),
|
|
|
+ title : str = Form(default=''),
|
|
|
+ category : str = Form(default=''),
|
|
|
+ create_time :str = Form(default=datetime.now()),
|
|
|
+ content : str = Form(default=''),
|
|
|
+ vedio_url :str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ online_course_obj = await Online_course.get(id=id)
|
|
|
+
|
|
|
+ if title.strip() != '':
|
|
|
+ online_course_obj.title = title
|
|
|
+
|
|
|
+ if category.strip() != '':
|
|
|
+ online_course_obj.category = category
|
|
|
+
|
|
|
+ if create_time.strip() != '':
|
|
|
+ online_course_obj.create_time = create_time
|
|
|
+
|
|
|
+ if content.strip() != '':
|
|
|
+ online_course_obj.content = content
|
|
|
+
|
|
|
+ if vedio_url.strip() != '':
|
|
|
+ online_course_obj.vedio_url = vedio_url
|
|
|
+
|
|
|
+ await online_course_obj.save()
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@classes.get("/get_online_courese")
|
|
|
+async def get_online_courese(
|
|
|
+ online_courese_id : Optional[int] = None
|
|
|
+):
|
|
|
+ try:
|
|
|
+ if online_courese_id :
|
|
|
+ online_courese_list = await Online_course.filter(id = online_courese_id).all()
|
|
|
+ else :
|
|
|
+ online_courese_list = await Online_course.all()
|
|
|
+
|
|
|
+ online_coureses = []
|
|
|
+ for online_coures_obj in online_courese_list:
|
|
|
+ online_coures_data = {
|
|
|
+ "id": online_coures_obj.id,
|
|
|
+ "title": online_coures_obj.title,
|
|
|
+ "category":online_coures_obj.category,
|
|
|
+ "create_time": online_coures_obj.create_time,
|
|
|
+ "click_time": online_coures_obj.click_time,
|
|
|
+ "content": online_coures_obj.content,
|
|
|
+ "vedio_url":online_coures_obj.vedio_url
|
|
|
+ }
|
|
|
+ online_coureses.append(online_coures_data)
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "online_coures": online_coureses}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@classes.post("/delete_online_course")
|
|
|
+async def delete_online_course(
|
|
|
+ online_course_id : int
|
|
|
+):
|
|
|
+ try:
|
|
|
+ await Online_course.filter(id=online_course_id).delete()
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
@classes.post("/uploadfiles/")
|
|
|
async def create_upload_files(files: List[UploadFile]):
|
|
|
return {"filenames": [file.filename for file in files]}
|