增加教职工支持
This commit is contained in:
父節點
79355bab7c
當前提交
865e6b6ce7
@ -71,9 +71,14 @@ func (c CheckinDAO) SaveUserActivity(userActivity *po.UserActivity) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
func (c CheckinDAO) FindAllActivities() []po.Activity {
|
||||
func (c CheckinDAO) FindAllActivities(isTeacher bool) []po.Activity {
|
||||
var arr []po.Activity
|
||||
err := c.Tx.Find(&arr).Error
|
||||
var err error
|
||||
if isTeacher {
|
||||
err = c.Tx.Find(&arr, "teacher_available=?", true).Error
|
||||
} else {
|
||||
err = c.Tx.Find(&arr).Error
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ func (u UserDAO) CreateUser(username string, realName string) *po.User {
|
||||
Username: username,
|
||||
RealName: realName,
|
||||
RoleID: 1,
|
||||
Type: 1,
|
||||
}
|
||||
err := u.Tx.Create(&user).Error
|
||||
if err != nil {
|
||||
|
@ -12,6 +12,7 @@ type Activity struct {
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
Credit int `json:"credit"`
|
||||
TeacherAvailable int `json:"teacher_available"`
|
||||
}
|
||||
|
||||
func (a Activity) TableName() string {
|
||||
|
@ -6,4 +6,5 @@ type User struct {
|
||||
RealName string `json:"real_name"`
|
||||
Credit int `json:"credit"`
|
||||
RoleID int `json:"role_id"`
|
||||
Type int `json:"type"`
|
||||
}
|
||||
|
@ -16,12 +16,13 @@ func Setup(engine *gin.Engine) {
|
||||
user.POST("/login", app.HandlerFunc(hub.Login))
|
||||
user.Use(middleware.JWT(1))
|
||||
user.GET("/me", app.HandlerFunc(hub.Me))
|
||||
user.POST("/set_type", app.HandlerFunc(hub.SetType))
|
||||
}
|
||||
checkin := engine.Group("/checkin")
|
||||
{
|
||||
hub := service.ExCheckinService
|
||||
checkin.GET("/list_activities", app.HandlerFunc(hub.ListActivities))
|
||||
checkin.Use(middleware.JWT(1))
|
||||
checkin.GET("/list_activities", app.HandlerFunc(hub.ListActivities))
|
||||
checkin.POST("/submit", app.HandlerFunc(hub.Submit))
|
||||
checkin.GET("/get_my_activities_today", app.HandlerFunc(hub.GetMyActivitiesToday))
|
||||
checkin.POST("/set_status", middleware.JWT(2), app.HandlerFunc(hub.SetStatus))
|
||||
|
@ -63,7 +63,12 @@ func (c CheckinService) SetStatus(aw *app.Wrapper) app.Result {
|
||||
return aw.Success(userActivity)
|
||||
}
|
||||
func (c CheckinService) ListActivities(aw *app.Wrapper) app.Result {
|
||||
return aw.Success(checkinDAO.FindAllActivities())
|
||||
user := userDAO.FindUserByID(aw.ExtractUserClaims().UserID)
|
||||
isTeacher := false
|
||||
if user.Type == 2 {
|
||||
isTeacher = true
|
||||
}
|
||||
return aw.Success(checkinDAO.FindAllActivities(isTeacher))
|
||||
}
|
||||
func (c CheckinService) ListUserActivities(aw *app.Wrapper) app.Result {
|
||||
type StatusReq struct {
|
||||
|
@ -31,3 +31,16 @@ func (u UserService) Login(aw *app.Wrapper) app.Result {
|
||||
func (u UserService) Me(aw *app.Wrapper) app.Result {
|
||||
return aw.Success(userDAO.FindUserByID(aw.ExtractUserClaims().UserID))
|
||||
}
|
||||
func (u UserService) SetType(aw *app.Wrapper) app.Result {
|
||||
type TypeReq struct {
|
||||
Type int `form:"type" binding:"required,gte=1,lte=2"`
|
||||
}
|
||||
var req TypeReq
|
||||
if err := aw.Ctx.ShouldBind(&req); err != nil {
|
||||
return aw.Error(err.Error())
|
||||
}
|
||||
user := userDAO.FindUserByID(aw.ExtractUserClaims().UserID)
|
||||
user.Type = req.Type
|
||||
userDAO.SaveUser(user)
|
||||
return aw.Success(user)
|
||||
}
|
||||
|
載入中…
x
新增問題並參考
Block a user