|
@@ -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
|
|
@@ -36,16 +36,16 @@ async def insert_school(
|
|
|
location_name: str = Form(default=''),
|
|
|
Lng: str = Form(default=''),
|
|
|
Lat: str = Form(default=''),
|
|
|
- group_id : int = Form(default=1),
|
|
|
- address : str = Form(default='')
|
|
|
+ address : str = Form(default=''),
|
|
|
+ update_time : datetime = Form(default=datetime.now())
|
|
|
):
|
|
|
try:
|
|
|
new_school = await Schools.create(
|
|
|
name=location_name,
|
|
|
longitude=Lng,
|
|
|
latitude=Lat,
|
|
|
- group_id = group_id,
|
|
|
- address = address
|
|
|
+ address = address,
|
|
|
+ update_time = update_time
|
|
|
)
|
|
|
|
|
|
return {"msg": "success", "code": 200, "location_id": new_school.id}
|
|
@@ -59,7 +59,8 @@ async def insert_class_name(
|
|
|
category: str = Form(default=''),
|
|
|
introduction: str = Form(default=''),
|
|
|
organizer: str = Form(default=''),
|
|
|
- cover_img_file:UploadFile = File(default='')
|
|
|
+ cover_img_file:UploadFile = File(default=''),
|
|
|
+ group_id : int = Form(default=1)
|
|
|
):
|
|
|
try:
|
|
|
cover_img = ''
|
|
@@ -78,7 +79,8 @@ async def insert_class_name(
|
|
|
category=category,
|
|
|
introduction=introduction,
|
|
|
organizer=organizer,
|
|
|
- cover_img=cover_img
|
|
|
+ cover_img=cover_img,
|
|
|
+ group_id=group_id
|
|
|
)
|
|
|
update_location_time(location_id= location_id)
|
|
|
return {"msg": "success", "code": 200, "new_class_name_id": new_class_name.id}
|
|
@@ -99,6 +101,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 +124,7 @@ async def insert_event(
|
|
|
people=people,
|
|
|
fee_method=fee_method,
|
|
|
registration_way=registration_way,
|
|
|
+ registration_day=registration_day,
|
|
|
remark=remark
|
|
|
)
|
|
|
|
|
@@ -133,15 +137,21 @@ 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 = 0
|
|
|
+ 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,
|
|
|
end_time=end_time,
|
|
|
- sessions=sessions,
|
|
|
+ sessions=session +1,
|
|
|
content = content
|
|
|
)
|
|
|
|
|
@@ -155,7 +165,6 @@ async def update_school(
|
|
|
location_name: str = Form(default=''),
|
|
|
Lng: str = Form(default=''),
|
|
|
Lat: str = Form(default=''),
|
|
|
- group_id : int = Form(default=1),
|
|
|
address : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
@@ -170,9 +179,6 @@ async def update_school(
|
|
|
if Lat.strip() != '':
|
|
|
school.latitude = Lat
|
|
|
|
|
|
- if group_id != 1 :
|
|
|
- school.group_id = group_id
|
|
|
-
|
|
|
if address.strip() != '':
|
|
|
school.address = address
|
|
|
|
|
@@ -187,11 +193,12 @@ async def update_school(
|
|
|
async def update_class_name(
|
|
|
class_name_id: int = Form(default=0),
|
|
|
name: str = Form(default=''),
|
|
|
- location_id: int = Form(default=''),
|
|
|
+ location_id: int = Form(default=0),
|
|
|
category: str = Form(default=''),
|
|
|
introduction: str = Form(default=''),
|
|
|
organizer: str = Form(default=''),
|
|
|
- cover_img_file:UploadFile = File(default='')
|
|
|
+ cover_img_file:UploadFile = File(default=''),
|
|
|
+ group_id : int = Form(default=0)
|
|
|
):
|
|
|
try:
|
|
|
class_name = await Class_name.get(id=class_name_id)
|
|
@@ -199,8 +206,9 @@ async def update_class_name(
|
|
|
if name.strip() != '':
|
|
|
class_name.name = name
|
|
|
|
|
|
- if location_id != '':
|
|
|
+ if location_id != 0:
|
|
|
class_name.school_id = location_id
|
|
|
+ update_location_time(location_id= location_id)
|
|
|
|
|
|
if category.strip() != '':
|
|
|
class_name.category = category
|
|
@@ -211,6 +219,9 @@ async def update_class_name(
|
|
|
if organizer.strip() != '':
|
|
|
class_name.organizer = organizer
|
|
|
|
|
|
+ if group_id != 0 :
|
|
|
+ class_name.group_id = group_id
|
|
|
+
|
|
|
if cover_img_file != '':
|
|
|
contents = await cover_img_file.read()
|
|
|
|
|
@@ -222,7 +233,7 @@ async def update_class_name(
|
|
|
|
|
|
await class_name.save()
|
|
|
|
|
|
- update_location_time(location_id= location_id)
|
|
|
+
|
|
|
return {"msg": "success", "code": 200}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
@@ -241,6 +252,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 +291,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
|
|
|
|
|
@@ -350,15 +365,25 @@ async def delete(id: int):
|
|
|
return {"msg": "success", "code": 200}
|
|
|
|
|
|
@classes.get("/get_event")
|
|
|
-async def search_event(name_id: int = 0):
|
|
|
+async def search_event(
|
|
|
+ class_name_id: Optional[int] = None,
|
|
|
+ event_id : Optional[int] = None
|
|
|
+):
|
|
|
try:
|
|
|
- class_list = await Class_list.filter(name_id=name_id).all()
|
|
|
+ if event_id :
|
|
|
+ class_list = await Class_list.filter(id=event_id).all()
|
|
|
+ elif class_name_id:
|
|
|
+ class_list = await Class_list.filter(name_id=class_name_id).all()
|
|
|
+ else :
|
|
|
+ return {"msg": "please input class_name_id or event_id", "code": 200}
|
|
|
|
|
|
classes = []
|
|
|
for class_obj in class_list:
|
|
|
+ class_name_obj = await Class_name.get(id=class_obj.name_id)
|
|
|
+ class_name = class_name_obj.name
|
|
|
+
|
|
|
class_data = {
|
|
|
- "msg": "success",
|
|
|
- "code": 200,
|
|
|
+ "class_name" : class_name,
|
|
|
"event_id": class_obj.id,
|
|
|
"name_id": class_obj.name_id,
|
|
|
"event": class_obj.event,
|
|
@@ -372,6 +397,7 @@ async def search_event(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 +407,15 @@ async def search_event(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 = {
|
|
@@ -391,7 +423,6 @@ async def get_school():
|
|
|
"location_name": school_obj.name,
|
|
|
"Lng": school_obj.longitude,
|
|
|
"Lat": school_obj.latitude,
|
|
|
- "group_id": school_obj.group_id,
|
|
|
"address": school_obj.address,
|
|
|
"update_time":school_obj.update_time
|
|
|
}
|
|
@@ -429,14 +460,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
|
|
@@ -447,6 +481,7 @@ async def get_class_name(
|
|
|
"category": class_name_obj.category,
|
|
|
"introduction": class_name_obj.introduction,
|
|
|
"organizer": class_name_obj.organizer,
|
|
|
+ "group_id": class_name_obj.group_id,
|
|
|
"cover_img": class_name_obj.cover_img
|
|
|
}
|
|
|
classes_name.append(class_data)
|
|
@@ -458,7 +493,7 @@ async def get_class_name(
|
|
|
|
|
|
@classes.get("/get_session")
|
|
|
async def get_session(
|
|
|
- event_id : int = 0
|
|
|
+ event_id : Optional[int] = None
|
|
|
):
|
|
|
try:
|
|
|
class_session_list = await Class_detail.filter(class_list_id=event_id).all()
|
|
@@ -574,10 +609,13 @@ async def get_favorite_class(
|
|
|
class_list = await Favorite_course.filter(user_id = user_id).all()
|
|
|
favorite_courses = []
|
|
|
for class_obj in class_list:
|
|
|
+ class_event = await Class_list.get(id = class_obj.class_event_id)
|
|
|
+ class_name = await Class_name.get(id = class_event.name_id)
|
|
|
class_data = {
|
|
|
"id": class_obj.id,
|
|
|
"user_id": class_obj.user_id,
|
|
|
"class_event_id":class_obj.class_event_id,
|
|
|
+ "class_name_id" : class_name.id,
|
|
|
"time_stemp":class_obj.time_stemp
|
|
|
}
|
|
|
favorite_courses.append(class_data)
|
|
@@ -597,6 +635,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]}
|