增加教职工支持
This commit is contained in:
父節點
79355bab7c
當前提交
865e6b6ce7
@ -71,9 +71,14 @@ func (c CheckinDAO) SaveUserActivity(userActivity *po.UserActivity) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (c CheckinDAO) FindAllActivities() []po.Activity {
|
func (c CheckinDAO) FindAllActivities(isTeacher bool) []po.Activity {
|
||||||
var arr []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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ func (u UserDAO) CreateUser(username string, realName string) *po.User {
|
|||||||
Username: username,
|
Username: username,
|
||||||
RealName: realName,
|
RealName: realName,
|
||||||
RoleID: 1,
|
RoleID: 1,
|
||||||
|
Type: 1,
|
||||||
}
|
}
|
||||||
err := u.Tx.Create(&user).Error
|
err := u.Tx.Create(&user).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,11 +7,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Activity struct {
|
type Activity struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Credit int `json:"credit"`
|
Credit int `json:"credit"`
|
||||||
|
TeacherAvailable int `json:"teacher_available"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Activity) TableName() string {
|
func (a Activity) TableName() string {
|
||||||
|
@ -6,4 +6,5 @@ type User struct {
|
|||||||
RealName string `json:"real_name"`
|
RealName string `json:"real_name"`
|
||||||
Credit int `json:"credit"`
|
Credit int `json:"credit"`
|
||||||
RoleID int `json:"role_id"`
|
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.POST("/login", app.HandlerFunc(hub.Login))
|
||||||
user.Use(middleware.JWT(1))
|
user.Use(middleware.JWT(1))
|
||||||
user.GET("/me", app.HandlerFunc(hub.Me))
|
user.GET("/me", app.HandlerFunc(hub.Me))
|
||||||
|
user.POST("/set_type", app.HandlerFunc(hub.SetType))
|
||||||
}
|
}
|
||||||
checkin := engine.Group("/checkin")
|
checkin := engine.Group("/checkin")
|
||||||
{
|
{
|
||||||
hub := service.ExCheckinService
|
hub := service.ExCheckinService
|
||||||
checkin.GET("/list_activities", app.HandlerFunc(hub.ListActivities))
|
|
||||||
checkin.Use(middleware.JWT(1))
|
checkin.Use(middleware.JWT(1))
|
||||||
|
checkin.GET("/list_activities", app.HandlerFunc(hub.ListActivities))
|
||||||
checkin.POST("/submit", app.HandlerFunc(hub.Submit))
|
checkin.POST("/submit", app.HandlerFunc(hub.Submit))
|
||||||
checkin.GET("/get_my_activities_today", app.HandlerFunc(hub.GetMyActivitiesToday))
|
checkin.GET("/get_my_activities_today", app.HandlerFunc(hub.GetMyActivitiesToday))
|
||||||
checkin.POST("/set_status", middleware.JWT(2), app.HandlerFunc(hub.SetStatus))
|
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)
|
return aw.Success(userActivity)
|
||||||
}
|
}
|
||||||
func (c CheckinService) ListActivities(aw *app.Wrapper) app.Result {
|
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 {
|
func (c CheckinService) ListUserActivities(aw *app.Wrapper) app.Result {
|
||||||
type StatusReq struct {
|
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 {
|
func (u UserService) Me(aw *app.Wrapper) app.Result {
|
||||||
return aw.Success(userDAO.FindUserByID(aw.ExtractUserClaims().UserID))
|
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