|
@@ -5,7 +5,7 @@ from random import randint
|
|
|
import uuid
|
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
|
from app.models.models import User
|
|
|
-from app.models.models import Class_list
|
|
|
+from app.models.models import Class_list,Schools,Class_detail,Class_name,Registration
|
|
|
from app.api import deps
|
|
|
from sqlalchemy.orm import Session
|
|
|
from typing import Any, Dict
|
|
@@ -26,39 +26,47 @@ classes = APIRouter()
|
|
|
IMAGEDIR = "/var/www/html/ntcri/assets/"
|
|
|
IMAGEDIR_short = "assets/"
|
|
|
|
|
|
-# SECRET: str = secrets.token_urlsafe(32)
|
|
|
-# manager = LoginManager(SECRET, '/login',default_expiry=timedelta(hours=72))
|
|
|
-
|
|
|
-
|
|
|
-# @manager.user_loader()
|
|
|
-# async def query_user(user_id: str):
|
|
|
-# """
|
|
|
-# Get a user from the db
|
|
|
-# :param user_id: E-Mail of the user
|
|
|
-# :return: None or the user object
|
|
|
-# """
|
|
|
-# result = await User.filter(username=user_id).first()
|
|
|
-# if not result:
|
|
|
-# print('[]')
|
|
|
-# return []
|
|
|
-# return result
|
|
|
-# # return DB['users'].get(user_id)
|
|
|
+@classes.post("/insert_school")
|
|
|
+async def insert_school(
|
|
|
+ id: int = Form(default=0),
|
|
|
+ name: str = Form(default=''),
|
|
|
+ longitude: str = Form(default=''),
|
|
|
+ latitude: str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ new_school = await Schools.create(
|
|
|
+ id=id,
|
|
|
+ name=name,
|
|
|
+ longitude=longitude,
|
|
|
+ latitude=latitude
|
|
|
+ )
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "class_id": new_school.id}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
@classes.post("/insert_class")
|
|
|
async def insert_class(
|
|
|
id: int = Form(default=0),
|
|
|
- name: str = Form(default=''),
|
|
|
+ name: int = Form(default=''),
|
|
|
+ school_id: int = Form(default=''),
|
|
|
+ category: str = Form(default=''),
|
|
|
+ introduction: str = Form(default=''),
|
|
|
+ organizer: str = Form(default=''),
|
|
|
+ cover_img_file:UploadFile = File(default=''),
|
|
|
+ event: str = Form(default=''),
|
|
|
start_time: datetime = Form(default=datetime.now()),
|
|
|
end_time: datetime = Form(default=datetime.now()),
|
|
|
- location: str = Form(default=''),
|
|
|
- lecturer: str = Form(default=''),
|
|
|
- organizer: str = Form(default=''),
|
|
|
contact: str = Form(default=''),
|
|
|
- introduction: str = Form(default=''),
|
|
|
+ lecturer: str = Form(default=''),
|
|
|
+ location: str = Form(default=''),
|
|
|
content: str = Form(default=''),
|
|
|
- #cover_img: str = Form(default=''),
|
|
|
- cover_img_file:UploadFile = File(default='')
|
|
|
-
|
|
|
-):
|
|
|
+ URL: str = Form(default=''),
|
|
|
+ people : str = Form(default=''),
|
|
|
+ fee_method: str = Form(default=''),
|
|
|
+ registration_way: str = Form(default=''),
|
|
|
+ remark : str = Form(default='')
|
|
|
+):
|
|
|
try:
|
|
|
contents = await cover_img_file.read()
|
|
|
|
|
@@ -68,72 +76,141 @@ async def insert_class(
|
|
|
|
|
|
cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
|
|
|
|
- new_class = await Class_list.create(
|
|
|
+ new_class_name = await Class_name.create(
|
|
|
id=id,
|
|
|
name=name,
|
|
|
+ school_id =school_id ,
|
|
|
+ category=category,
|
|
|
+ introduction=introduction,
|
|
|
+ organizer=organizer,
|
|
|
+ cover_img=cover_img
|
|
|
+ )
|
|
|
+
|
|
|
+ new_class = await Class_list.create(
|
|
|
+ id=id,
|
|
|
+ name_id=new_class_name.id,
|
|
|
+ event =event ,
|
|
|
start_time=start_time,
|
|
|
end_time=end_time,
|
|
|
- location=location,
|
|
|
+ contact=contact,
|
|
|
lecturer=lecturer,
|
|
|
- organizer=organizer,
|
|
|
+ location=location,
|
|
|
+ content=content,
|
|
|
+ URL=URL,
|
|
|
+ people=people,
|
|
|
+ fee_method=fee_method,
|
|
|
+ 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}
|
|
|
+
|
|
|
+@classes.event("/insert_event")
|
|
|
+async def insert_event(
|
|
|
+ id: int = Form(default=0),
|
|
|
+ name_id: int = Form(default=''),
|
|
|
+ event: str = Form(default=''),
|
|
|
+ start_time: datetime = Form(default=datetime.now()),
|
|
|
+ end_time: datetime = Form(default=datetime.now()),
|
|
|
+ contact: str = Form(default=''),
|
|
|
+ lecturer: str = Form(default=''),
|
|
|
+ location: str = Form(default=''),
|
|
|
+ content: str = Form(default=''),
|
|
|
+ URL: str = Form(default=''),
|
|
|
+ people : str = Form(default=''),
|
|
|
+ fee_method: str = Form(default=''),
|
|
|
+ registration_way: str = Form(default=''),
|
|
|
+ remark : str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ new_class = await Class_list.create(
|
|
|
+ id=id,
|
|
|
+ name_id=name_id,
|
|
|
+ event =event,
|
|
|
+ start_time=start_time,
|
|
|
+ end_time=end_time,
|
|
|
contact=contact,
|
|
|
- introduction=introduction,
|
|
|
+ lecturer=lecturer,
|
|
|
+ location=location,
|
|
|
content=content,
|
|
|
- cover_img=cover_img
|
|
|
+ URL=URL,
|
|
|
+ people=people,
|
|
|
+ fee_method=fee_method,
|
|
|
+ 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}
|
|
|
|
|
|
-# @classes.post("/update_class")
|
|
|
-# async def update_class(
|
|
|
-# id: int = Form(default=0),
|
|
|
-# name: str = Form(default=''),
|
|
|
-# start_time: datetime = Form(default=datetime.now()),
|
|
|
-# end_time: datetime = Form(default=datetime.now()),
|
|
|
-# location: str = Form(default=''),
|
|
|
-# lecturer: str = Form(default=''),
|
|
|
-# organizer: str = Form(default=''),
|
|
|
-# contact: str = Form(default=''),
|
|
|
-# introduction: str = Form(default=''),
|
|
|
-# content: str = Form(default='')
|
|
|
-# ):
|
|
|
-# try:
|
|
|
-# await Class_list.filter(id=id).update(
|
|
|
-# name=name,
|
|
|
-# start_time=start_time,
|
|
|
-# end_time=end_time,
|
|
|
-# location=location,
|
|
|
-# lecturer=lecturer,
|
|
|
-# organizer=organizer,
|
|
|
-# contact=contact,
|
|
|
-# introduction=introduction,
|
|
|
-# content=content
|
|
|
-# )
|
|
|
-# return {"msg": "success", "code": 200}
|
|
|
-# except Exception as e:
|
|
|
-# return {"msg": str(e), "code": 500}
|
|
|
+@classes.post("/update_class_name")
|
|
|
+async def update_class_name(
|
|
|
+ id: int = Form(default=0),
|
|
|
+ name: int = Form(default=''),
|
|
|
+ school_id: int = Form(default=''),
|
|
|
+ category: str = Form(default=''),
|
|
|
+ introduction: str = Form(default=''),
|
|
|
+ organizer: str = Form(default=''),
|
|
|
+ cover_img_file:UploadFile = File(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ class_name = await Class_name.get(id=id)
|
|
|
+
|
|
|
+ if name.strip() != '':
|
|
|
+ class_name.name = name
|
|
|
+
|
|
|
+ if school_id.strip() != '':
|
|
|
+ class_name.school_id = school_id
|
|
|
+
|
|
|
+ if category.strip() != '':
|
|
|
+ class_name.category = category
|
|
|
+
|
|
|
+ if introduction.strip() != '':
|
|
|
+ class_name.introduction = introduction
|
|
|
|
|
|
+ if organizer.strip() != '':
|
|
|
+ class_name.organizer = organizer
|
|
|
+
|
|
|
+ if cover_img_file != '':
|
|
|
+ contents = await cover_img_file.read()
|
|
|
+
|
|
|
+ with open(f"{IMAGEDIR}{cover_img_file.filename}", "wb") as f:
|
|
|
+ f.write(contents)
|
|
|
+
|
|
|
+ class_name.cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
|
+
|
|
|
+
|
|
|
+ await class_name.save()
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
@classes.post("/update_class")
|
|
|
async def update_class(
|
|
|
id: int = Form(default=0),
|
|
|
- name: str = Form(default=''),
|
|
|
+ name_id: int = Form(default=''),
|
|
|
+ event: str = Form(default=''),
|
|
|
start_time: datetime = Form(default=datetime.now()),
|
|
|
end_time: datetime = Form(default=datetime.now()),
|
|
|
- location: str = Form(default=''),
|
|
|
- lecturer: str = Form(default=''),
|
|
|
- organizer: str = Form(default=''),
|
|
|
contact: str = Form(default=''),
|
|
|
- introduction: str = Form(default=''),
|
|
|
+ lecturer: str = Form(default=''),
|
|
|
+ location: str = Form(default=''),
|
|
|
content: str = Form(default=''),
|
|
|
- #cover_img: str = Form(default=''),
|
|
|
- cover_img_file:UploadFile = File(default='')
|
|
|
+ URL: str = Form(default=''),
|
|
|
+ people : str = Form(default=''),
|
|
|
+ fee_method: str = Form(default=''),
|
|
|
+ registration_way: str = Form(default=''),
|
|
|
+ remark : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
|
class_obj = await Class_list.get(id=id)
|
|
|
|
|
|
- if name.strip() != '':
|
|
|
- class_obj.name = name
|
|
|
+ if name_id.strip() != '':
|
|
|
+ class_obj.name_id = name_id
|
|
|
+
|
|
|
+ if event.strip() != '':
|
|
|
+ class_obj.event = event
|
|
|
|
|
|
if start_time:
|
|
|
class_obj.start_time = start_time
|
|
@@ -147,27 +224,27 @@ async def update_class(
|
|
|
if lecturer.strip() != '':
|
|
|
class_obj.lecturer = lecturer
|
|
|
|
|
|
- if organizer.strip() != '':
|
|
|
- class_obj.organizer = organizer
|
|
|
-
|
|
|
if contact.strip() != '':
|
|
|
class_obj.contact = contact
|
|
|
|
|
|
- if introduction.strip() != '':
|
|
|
- class_obj.introduction = introduction
|
|
|
-
|
|
|
if content.strip() != '':
|
|
|
class_obj.content = content
|
|
|
|
|
|
-
|
|
|
- if cover_img_file != '':
|
|
|
- contents = await cover_img_file.read()
|
|
|
-
|
|
|
- with open(f"{IMAGEDIR}{cover_img_file.filename}", "wb") as f:
|
|
|
- f.write(contents)
|
|
|
+ if URL.strip() != '':
|
|
|
+ class_obj.URL = URL
|
|
|
|
|
|
- class_obj.cover_img = f"{IMAGEDIR_short}{cover_img_file.filename}"
|
|
|
+ if people.strip() != '':
|
|
|
+ class_obj.people = people
|
|
|
+
|
|
|
+ if fee_method.strip() != '':
|
|
|
+ class_obj.fee_method = fee_method
|
|
|
+
|
|
|
+ if registration_way.strip() != '':
|
|
|
+ class_obj.registration_way = registration_way
|
|
|
|
|
|
+ if remark.strip() != '':
|
|
|
+ class_obj.remark = remark
|
|
|
+
|
|
|
await class_obj.save()
|
|
|
return {"msg": "success", "code": 200}
|
|
|
except Exception as e:
|
|
@@ -178,50 +255,98 @@ async def delete(id: int):
|
|
|
if id:
|
|
|
await Class_list.filter(id=id).delete()
|
|
|
return {"msg": "success", "code": 200}
|
|
|
+
|
|
|
+@classes.post("/delete_class_name")
|
|
|
+async def delete(id: int):
|
|
|
+ if id:
|
|
|
+ await Class_list.filter(name_id=id).delete()
|
|
|
+ await Class_name.filter(id=id).delete()
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
|
|
|
|
|
|
@classes.get("/search_class")
|
|
|
async def search_class(id: int):
|
|
|
try:
|
|
|
class_obj = await Class_list.get(id=id)
|
|
|
+ class_name = await Class_name.get(id=class_obj.name_id)
|
|
|
+ school_obj = await Schools.get(id=class_name.school_id)
|
|
|
return {
|
|
|
"msg": "success",
|
|
|
"code": 200,
|
|
|
"class_id": class_obj.id,
|
|
|
- "name": class_obj.name,
|
|
|
+ "name": class_name.name,
|
|
|
+ "school":school_obj.name,
|
|
|
+ "category": class_name.category,
|
|
|
+ "introduction": class_name.introduction,
|
|
|
+ "organizer": class_name.organizer,
|
|
|
+ "cover_img": class_name.cover_img,
|
|
|
+ "event": class_obj.event,
|
|
|
"start_time": class_obj.start_time,
|
|
|
"end_time": class_obj.end_time,
|
|
|
"location": class_obj.location,
|
|
|
"lecturer": class_obj.lecturer,
|
|
|
"organizer": class_obj.organizer,
|
|
|
"contact": class_obj.contact,
|
|
|
- "introduction": class_obj.introduction,
|
|
|
"content": class_obj.content,
|
|
|
- "cover_img": class_obj.cover_img,
|
|
|
-
|
|
|
+ "URL": class_obj.URL,
|
|
|
+ "people": class_obj.people,
|
|
|
+ "fee_method": class_obj.fee_method,
|
|
|
+ "registration_way": class_obj.registration_way,
|
|
|
+ "remark": class_obj.remark
|
|
|
}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
+@classes.get("/get_school")
|
|
|
+async def get_school():
|
|
|
+ try:
|
|
|
+ school_list = await Schools.all()
|
|
|
+ schools = []
|
|
|
+ for school_obj in school_list:
|
|
|
+ school_data = {
|
|
|
+ "school_id": school_obj.id,
|
|
|
+ "name": school_obj.name,
|
|
|
+ "longitude": school_obj.longitude,
|
|
|
+ "latitude": school_obj.latitude,
|
|
|
+ }
|
|
|
+ schools.append(school_data)
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "schools": schools}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
@classes.get("/get_class")
|
|
|
async def get_class():
|
|
|
try:
|
|
|
class_list = await Class_list.all()
|
|
|
classes = []
|
|
|
for class_obj in class_list:
|
|
|
+ class_name = await Class_name.get(id=class_obj.name_id)
|
|
|
+ school_obj = await Schools.get(id=class_name.school_id)
|
|
|
class_data = {
|
|
|
- "class_id": class_obj.id,
|
|
|
- "name": class_obj.name,
|
|
|
- "start_time": class_obj.start_time,
|
|
|
- "end_time": class_obj.end_time,
|
|
|
- "location": class_obj.location,
|
|
|
- "lecturer": class_obj.lecturer,
|
|
|
- "organizer": class_obj.organizer,
|
|
|
- "contact": class_obj.contact,
|
|
|
- "introduction": class_obj.introduction,
|
|
|
- "content": class_obj.content,
|
|
|
- "cover_img": class_obj.cover_img
|
|
|
- }
|
|
|
+ "msg": "success",
|
|
|
+ "code": 200,
|
|
|
+ "class_id": class_obj.id,
|
|
|
+ "name": class_name.name,
|
|
|
+ "school":school_obj.name,
|
|
|
+ "category": class_name.category,
|
|
|
+ "introduction": class_name.introduction,
|
|
|
+ "organizer": class_name.organizer,
|
|
|
+ "cover_img": class_name.cover_img,
|
|
|
+ "event": class_obj.event,
|
|
|
+ "start_time": class_obj.start_time,
|
|
|
+ "end_time": class_obj.end_time,
|
|
|
+ "location": class_obj.location,
|
|
|
+ "lecturer": class_obj.lecturer,
|
|
|
+ "organizer": class_obj.organizer,
|
|
|
+ "contact": class_obj.contact,
|
|
|
+ "content": class_obj.content,
|
|
|
+ "URL": class_obj.URL,
|
|
|
+ "people": class_obj.people,
|
|
|
+ "fee_method": class_obj.fee_method,
|
|
|
+ "registration_way": class_obj.registration_way,
|
|
|
+ "remark": class_obj.remark
|
|
|
+ }
|
|
|
classes.append(class_data)
|
|
|
|
|
|
return {"msg": "success", "code": 200, "classes": classes}
|