|
@@ -4,7 +4,7 @@ from typing import List,Optional,Union
|
|
from fastapi.responses import FileResponse
|
|
from fastapi.responses import FileResponse
|
|
from random import randint
|
|
from random import randint
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
-from app.models.models import Registration,User,User_information,Class_list
|
|
|
|
|
|
+from app.models.models import Registration,User,User_information,Class_list,Class_name,Schools,Class_date
|
|
from app.api import deps
|
|
from app.api import deps
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.orm import Session
|
|
from typing import Any, Dict
|
|
from typing import Any, Dict
|
|
@@ -71,9 +71,9 @@ async def get_registration(
|
|
inform_list = inform_list.filter(reg_confirm=is_check)
|
|
inform_list = inform_list.filter(reg_confirm=is_check)
|
|
|
|
|
|
if registration_id:
|
|
if registration_id:
|
|
- reg_list_tmp = await inform_list.filter(id=registration_id,is_del=0).all()
|
|
|
|
|
|
+ reg_list_tmp = await inform_list.filter(id=registration_id,is_del=0).all().order_by("-event_id","create_time")
|
|
else:
|
|
else:
|
|
- reg_list_tmp = await inform_list.filter(is_del=0).all()
|
|
|
|
|
|
+ reg_list_tmp = await inform_list.filter(is_del=0).all().order_by("-event_id","create_time")
|
|
|
|
|
|
|
|
|
|
reg_list = []
|
|
reg_list = []
|
|
@@ -81,6 +81,7 @@ async def get_registration(
|
|
for infor in reg_list_tmp:
|
|
for infor in reg_list_tmp:
|
|
|
|
|
|
try :
|
|
try :
|
|
|
|
+
|
|
reg_data = {
|
|
reg_data = {
|
|
"Registration_id" : infor.id,
|
|
"Registration_id" : infor.id,
|
|
"event_id" : infor.event_id,
|
|
"event_id" : infor.event_id,
|
|
@@ -93,6 +94,29 @@ async def get_registration(
|
|
"msg" : "fail to get data"
|
|
"msg" : "fail to get data"
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ try :
|
|
|
|
+ class_obj = await Class_list.get(id = infor.event_id)
|
|
|
|
+ class_name_obj = await Class_name.get(id = class_obj.name_id)
|
|
|
|
+ school_obj = await Schools.get(id = class_name_obj.school_id)
|
|
|
|
+ reg_data["school_name"] = school_obj.name
|
|
|
|
+ reg_data["class_name"] = class_name_obj.name
|
|
|
|
+ reg_data["class_event"] = class_obj.event
|
|
|
|
+ reg_data["start_time"] = str(class_obj.start_time)
|
|
|
|
+ reg_data["end_time"] =str(class_obj.end_time)
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ reg_data["class_data"] = str(e)
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ user = await User.get(id=infor.user_id)
|
|
|
|
+ inform = await User_information.get(user_id=infor.user_id)
|
|
|
|
+ reg_data["real_name"] = inform.name
|
|
|
|
+ reg_data["phone"] = inform.phone
|
|
|
|
+ reg_data["email"] = user.email
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ reg_data["user_data"] = str(e)
|
|
|
|
+
|
|
reg_list.append(reg_data)
|
|
reg_list.append(reg_data)
|
|
|
|
|
|
|
|
|
|
@@ -103,7 +127,7 @@ async def get_registration(
|
|
@registration.post("/input_information")
|
|
@registration.post("/input_information")
|
|
async def input_information(
|
|
async def input_information(
|
|
name : str = Form(default=''),
|
|
name : str = Form(default=''),
|
|
- display_name : str = Form(default=''),
|
|
|
|
|
|
+ user_name : str = Form(default=''),
|
|
birthday : date = Form(default=datetime.now().date()),
|
|
birthday : date = Form(default=datetime.now().date()),
|
|
gender : str = Form(default=''),
|
|
gender : str = Form(default=''),
|
|
phone : str = Form(default=''),
|
|
phone : str = Form(default=''),
|
|
@@ -126,9 +150,9 @@ async def input_information(
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
- if display_name != '':
|
|
|
|
|
|
+ if user_name != '':
|
|
user = await User.get(id = user_id)
|
|
user = await User.get(id = user_id)
|
|
- user.username = display_name
|
|
|
|
|
|
+ user.username = user_name
|
|
await user.save()
|
|
await user.save()
|
|
|
|
|
|
|
|
|
|
@@ -139,8 +163,8 @@ async def input_information(
|
|
|
|
|
|
@registration.post("/update_information")
|
|
@registration.post("/update_information")
|
|
async def update_information(
|
|
async def update_information(
|
|
|
|
+ user_name : str = Form(default=''),
|
|
name : str = Form(default=''),
|
|
name : str = Form(default=''),
|
|
- display_name : str = Form(default=''),
|
|
|
|
birthday : date = Form(default=datetime.now().date()),
|
|
birthday : date = Form(default=datetime.now().date()),
|
|
gender : str = Form(default=''),
|
|
gender : str = Form(default=''),
|
|
phone : str = Form(default=''),
|
|
phone : str = Form(default=''),
|
|
@@ -169,8 +193,8 @@ async def update_information(
|
|
if address != '':
|
|
if address != '':
|
|
infor.address = address
|
|
infor.address = address
|
|
|
|
|
|
- if display_name != '':
|
|
|
|
- user.username = display_name
|
|
|
|
|
|
+ if user_name != '':
|
|
|
|
+ user.username = user_name
|
|
|
|
|
|
await infor.save()
|
|
await infor.save()
|
|
await user.save()
|
|
await user.save()
|
|
@@ -213,6 +237,8 @@ async def get_user_information(
|
|
user_inform["gender"] = inform.gender
|
|
user_inform["gender"] = inform.gender
|
|
user_inform["phone"] = inform.phone
|
|
user_inform["phone"] = inform.phone
|
|
user_inform["address"] = inform.address
|
|
user_inform["address"] = inform.address
|
|
|
|
+ user_inform["msg"] = "user information exist"
|
|
|
|
+ user_inform["exist"] = True
|
|
|
|
|
|
except:
|
|
except:
|
|
user_inform["msg"] = "no user information"
|
|
user_inform["msg"] = "no user information"
|
|
@@ -224,7 +250,34 @@ async def get_user_information(
|
|
return {"msg":"success","code":200,"user_inform": user_inform_list}
|
|
return {"msg":"success","code":200,"user_inform": user_inform_list}
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return {"msg": str(e), "code": 500}
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
+
|
|
|
|
+@registration.get("/change_class_reg_number")
|
|
|
|
+async def change_class_reg_number(
|
|
|
|
+ event_id: int = 0,
|
|
|
|
+ reduce_number : int = 1
|
|
|
|
+):
|
|
|
|
+ try:
|
|
|
|
+ if event_id:
|
|
|
|
+ try:
|
|
|
|
+ await Class_list.get(id = event_id)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return {"msg": "no this event", "code": 200}
|
|
|
|
+ try:
|
|
|
|
+ class_date = await Class_date.get(class_list_id = event_id)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return {"msg": "no this class' number limit", "code": 200}
|
|
|
|
+
|
|
|
|
+ if class_date.amount_left ==0 and reduce_number>0:
|
|
|
|
+ return {"msg": "class is full", "code": 200,"amount_left":-1}
|
|
|
|
+ elif class_date.amount_left == class_date.number_limit and reduce_number<0:
|
|
|
|
+ return {"msg": "class is empty", "code": 200,"amount_left":class_date.amount_left }
|
|
|
|
+ else:
|
|
|
|
+ class_date.amount_left = class_date.amount_left-reduce_number
|
|
|
|
+ await class_date.save()
|
|
|
|
|
|
|
|
+ return {"msg": "success", "code": 200,"amount_left":class_date.amount_left}
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
|
|
|
@registration.post("/input_registration")
|
|
@registration.post("/input_registration")
|
|
async def input_registration(
|
|
async def input_registration(
|
|
@@ -234,6 +287,11 @@ async def input_registration(
|
|
try :
|
|
try :
|
|
if not user_id :
|
|
if not user_id :
|
|
return {"msg": "please log in", "code": 200}
|
|
return {"msg": "please log in", "code": 200}
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ await Class_list.get(id = event_id)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return {"msg": "no this event", "code": 200}
|
|
|
|
|
|
# if check_if_id_exeit(User_information,user_inform_id):
|
|
# if check_if_id_exeit(User_information,user_inform_id):
|
|
# return {"msg": "no user information", "code": 200}
|
|
# return {"msg": "no user information", "code": 200}
|
|
@@ -245,15 +303,23 @@ async def input_registration(
|
|
except:
|
|
except:
|
|
return {"msg": "no user information", "code": 200}
|
|
return {"msg": "no user information", "code": 200}
|
|
|
|
|
|
- new_registration = await Registration.create(
|
|
|
|
|
|
+ new_registration = await Registration.get_or_create(
|
|
event_id = event_id,
|
|
event_id = event_id,
|
|
user_id = user_id,
|
|
user_id = user_id,
|
|
- reg_confirm = 0,
|
|
|
|
- is_del = 0 ,
|
|
|
|
- create_time = datetime.now()
|
|
|
|
|
|
+ defaults = {
|
|
|
|
+ "reg_confirm" : 0,
|
|
|
|
+ "is_del" : 0 ,
|
|
|
|
+ "create_time" : datetime.now()
|
|
|
|
+ }
|
|
)
|
|
)
|
|
|
|
|
|
- return {"msg": "success", "code": 200,"new_registration_id":new_registration.id}
|
|
|
|
|
|
+ if new_registration[1]:
|
|
|
|
+ amount_left_obj = await change_class_reg_number(event_id=event_id)
|
|
|
|
+ msg = amount_left_obj["msg"]
|
|
|
|
+ else:
|
|
|
|
+ msg = "already registrate"
|
|
|
|
+
|
|
|
|
+ return {"msg": msg, "code": 200,"new_registration_id":new_registration[0].id,"is_already_exist":not new_registration[1]}
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return {"msg": str(e), "code": 500}
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
@@ -285,11 +351,17 @@ async def delete_registration(
|
|
|
|
|
|
registration_obj = await Registration.get(event_id=event_id,user_id=user_id)
|
|
registration_obj = await Registration.get(event_id=event_id,user_id=user_id)
|
|
|
|
|
|
|
|
+ amount_left_obj = await change_class_reg_number(event_id=registration_obj.event_id)
|
|
|
|
+ msg = amount_left_obj["msg"]
|
|
|
|
+
|
|
|
|
+ if msg == "class is full":
|
|
|
|
+ return {"msg": msg+" cannot recover registration", "code": 200}
|
|
|
|
+
|
|
registration_obj.is_del = 0
|
|
registration_obj.is_del = 0
|
|
|
|
|
|
await registration_obj.save()
|
|
await registration_obj.save()
|
|
|
|
|
|
- return {"msg": "success", "code": 200}
|
|
|
|
|
|
+ return {"msg": msg, "code": 200}
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return {"msg": str(e), "code": 500}
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
@@ -311,8 +383,11 @@ async def delete_registration(
|
|
|
|
|
|
registration_obj.is_del = 1
|
|
registration_obj.is_del = 1
|
|
|
|
|
|
|
|
+ amount_left_obj = await change_class_reg_number(event_id=registration_obj.event_id,reduce_number=-1)
|
|
|
|
+ msg = amount_left_obj["msg"]
|
|
|
|
+
|
|
await registration_obj.save()
|
|
await registration_obj.save()
|
|
|
|
|
|
- return {"msg": "success", "code": 200}
|
|
|
|
|
|
+ return {"msg": msg , "code": 200}
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return {"msg": str(e), "code": 500}
|
|
return {"msg": str(e), "code": 500}
|