|
@@ -3,7 +3,7 @@ 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,Article_list
|
|
|
+from app.models.models import User,Favorite_course,Article_list,Class_date
|
|
|
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
|
|
@@ -35,7 +35,7 @@ async def check_token(access_token: str):
|
|
|
|
|
|
return user_id
|
|
|
|
|
|
-IMAGEDIR = "/var/www/ntcri/ntcri/assets/"
|
|
|
+IMAGEDIR = "/var/www/ntcri/assets/"
|
|
|
IMAGEDIR_short = "assets/"
|
|
|
|
|
|
async def update_location_time(location_id: int):
|
|
@@ -117,7 +117,9 @@ async def insert_event(
|
|
|
people : str = Form(default=''),
|
|
|
fee_method: str = Form(default=''),
|
|
|
registration_way: str = Form(default=''),
|
|
|
- registration_day: str = Form(default=''),
|
|
|
+ registration_start: datetime = Form(default=datetime.now()),
|
|
|
+ registration_end: datetime = Form(default=datetime.now()),
|
|
|
+ number_limit: int = Form(default=0),
|
|
|
remark : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
@@ -140,10 +142,17 @@ async def insert_event(
|
|
|
people=people,
|
|
|
fee_method=fee_method,
|
|
|
registration_way=registration_way,
|
|
|
- registration_day=registration_day,
|
|
|
remark=remark
|
|
|
)
|
|
|
|
|
|
+ await Class_date.create(
|
|
|
+ class_list_id = new_class.id,
|
|
|
+ registration_start = registration_start,
|
|
|
+ registration_end = registration_end,
|
|
|
+ number_limit = number_limit,
|
|
|
+ amount_left = number_limit
|
|
|
+ )
|
|
|
+
|
|
|
return {"msg": "success", "code": 200, "class_id": new_class.id}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
@@ -272,7 +281,9 @@ async def update_event(
|
|
|
people : str = Form(default=''),
|
|
|
fee_method: str = Form(default=''),
|
|
|
registration_way: str = Form(default=''),
|
|
|
- registration_day: str = Form(default=''),
|
|
|
+ registration_start: datetime = Form(default=datetime.now()),
|
|
|
+ registration_end: datetime = Form(default=datetime.now()),
|
|
|
+ number_limit: int = Form(default=0),
|
|
|
remark : str = Form(default='')
|
|
|
):
|
|
|
try:
|
|
@@ -314,13 +325,23 @@ async def update_event(
|
|
|
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
|
|
|
+
|
|
|
+ class_date_obj = await Class_date.get(class_list_id=id)
|
|
|
+
|
|
|
+ if registration_start != datetime.now():
|
|
|
+ class_date_obj.registration_start = registration_start
|
|
|
+
|
|
|
+ if registration_end != datetime.now():
|
|
|
+ class_date_obj.registration_end = registration_end
|
|
|
+
|
|
|
+ if number_limit != 0:
|
|
|
+ class_date_obj.number_limit = number_limit
|
|
|
|
|
|
await class_obj.save()
|
|
|
+ await class_date_obj.save()
|
|
|
+
|
|
|
return {"msg": "success", "code": 200}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
@@ -374,6 +395,7 @@ async def delete(id: int):
|
|
|
if id:
|
|
|
await Class_detail.filter(class_list_id=id).delete()
|
|
|
await Class_list.filter(id=id).delete()
|
|
|
+ await Class_date.filter(class_list_id=id).delete()
|
|
|
return {"msg": "success", "code": 200}
|
|
|
|
|
|
@classes.post("/delete_class_name")
|
|
@@ -382,9 +404,11 @@ async def delete(id: int):
|
|
|
class_event_list = await Class_list.filter(name_id=id).all()
|
|
|
for class_event_obj in class_event_list:
|
|
|
await Class_detail.filter(class_list_id=class_event_obj.id).delete()
|
|
|
+ await Class_date.filter(class_list_id=class_event_obj.id).delete()
|
|
|
|
|
|
await Class_list.filter(name_id=id).delete()
|
|
|
await Class_name.filter(id=id).delete()
|
|
|
+
|
|
|
return {"msg": "success", "code": 200}
|
|
|
|
|
|
@classes.get("/get_event")
|
|
@@ -405,25 +429,50 @@ async def search_event(
|
|
|
class_name_obj = await Class_name.get(id=class_obj.name_id)
|
|
|
class_name = class_name_obj.name
|
|
|
|
|
|
- class_data = {
|
|
|
- "class_name" : class_name,
|
|
|
- "event_id": class_obj.id,
|
|
|
- "name_id": class_obj.name_id,
|
|
|
- "event": class_obj.event,
|
|
|
- "start_time": class_obj.start_time,
|
|
|
- "end_time": class_obj.end_time,
|
|
|
- "location": class_obj.location,
|
|
|
- "lecturer": class_obj.lecturer,
|
|
|
- "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,
|
|
|
- "registration_day": class_obj.registration_day,
|
|
|
- "remark": class_obj.remark
|
|
|
- }
|
|
|
- classes.append(class_data)
|
|
|
+ try:
|
|
|
+ class_date_obj = await Class_date.get(class_list_id=class_obj.id)
|
|
|
+ class_data = {
|
|
|
+ "class_name" : class_name,
|
|
|
+ "event_id": class_obj.id,
|
|
|
+ "name_id": class_obj.name_id,
|
|
|
+ "event": class_obj.event,
|
|
|
+ "start_time": class_obj.start_time,
|
|
|
+ "end_time": class_obj.end_time,
|
|
|
+ "location": class_obj.location,
|
|
|
+ "lecturer": class_obj.lecturer,
|
|
|
+ "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,
|
|
|
+ "registration_start": class_date_obj.registration_start,
|
|
|
+ "registration_end": class_date_obj.registration_end,
|
|
|
+ "number_limit": class_date_obj.number_limit,
|
|
|
+ "amount_left": class_date_obj.amount_left,
|
|
|
+ "remark": class_obj.remark
|
|
|
+ }
|
|
|
+ classes.append(class_data)
|
|
|
+ except:
|
|
|
+
|
|
|
+ class_data = {
|
|
|
+ "class_name" : class_name,
|
|
|
+ "event_id": class_obj.id,
|
|
|
+ "name_id": class_obj.name_id,
|
|
|
+ "event": class_obj.event,
|
|
|
+ "start_time": class_obj.start_time,
|
|
|
+ "end_time": class_obj.end_time,
|
|
|
+ "location": class_obj.location,
|
|
|
+ "lecturer": class_obj.lecturer,
|
|
|
+ "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}
|
|
|
except Exception as e:
|