审核用户type过滤

This commit is contained in:
juzeon 2023-01-30 12:12:53 +08:00
父節點 865e6b6ce7
當前提交 a190e759c7
共有 2 個檔案被更改,包括 8 行新增5 行删除

查看文件

@ -86,16 +86,17 @@ func (c CheckinDAO) FindAllActivities(isTeacher bool) []po.Activity {
} }
func getUserActivityExtendedSQL(where string) string { func getUserActivityExtendedSQL(where string) string {
return "select ua.*,a.category activity_category," + return "select ua.*,a.category activity_category," +
"a.name activity_name from user_activity ua left join activities a on a.id=ua.activity_id " + where + "a.name activity_name from user_activity ua left join activities a on a.id=ua.activity_id " +
"left join users u on u.id=ua.user_id " + where +
" order by created_at desc" " order by created_at desc"
} }
func (c CheckinDAO) FindAllUserActivities(status int) []dto.UserActivityExtended { func (c CheckinDAO) FindUserActivitiesByStatusUserType(status int, userType int) []dto.UserActivityExtended {
var arr []dto.UserActivityExtended var arr []dto.UserActivityExtended
var err error var err error
if status != 0 { if status != 0 {
err = c.Tx.Raw(getUserActivityExtendedSQL("where status=?"), status).Find(&arr).Error err = c.Tx.Raw(getUserActivityExtendedSQL("where status=? and u.type=?"), status, userType).Find(&arr).Error
} else { } else {
err = c.Tx.Raw(getUserActivityExtendedSQL("")).Find(&arr).Error err = c.Tx.Raw(getUserActivityExtendedSQL("where u.type=?"), userType).Find(&arr).Error
} }
if err != nil { if err != nil {
panic(err) panic(err)

查看文件

@ -71,6 +71,7 @@ func (c CheckinService) ListActivities(aw *app.Wrapper) app.Result {
return aw.Success(checkinDAO.FindAllActivities(isTeacher)) return aw.Success(checkinDAO.FindAllActivities(isTeacher))
} }
func (c CheckinService) ListUserActivities(aw *app.Wrapper) app.Result { func (c CheckinService) ListUserActivities(aw *app.Wrapper) app.Result {
uc := aw.ExtractUserClaims()
type StatusReq struct { type StatusReq struct {
Status int `form:"status"` Status int `form:"status"`
} }
@ -78,7 +79,8 @@ func (c CheckinService) ListUserActivities(aw *app.Wrapper) app.Result {
if err := aw.Ctx.ShouldBind(&req); err != nil { if err := aw.Ctx.ShouldBind(&req); err != nil {
return aw.Error(err.Error()) return aw.Error(err.Error())
} }
return aw.Success(checkinDAO.FindAllUserActivities(req.Status)) user := userDAO.FindUserByID(uc.UserID)
return aw.Success(checkinDAO.FindUserActivitiesByStatusUserType(req.Status, user.Type))
} }
func (c CheckinService) GetUserActivity(aw *app.Wrapper) app.Result { func (c CheckinService) GetUserActivity(aw *app.Wrapper) app.Result {
id, err := strconv.Atoi(aw.Ctx.Query("id")) id, err := strconv.Atoi(aw.Ctx.Query("id"))