审核用户type过滤
This commit is contained in:
父節點
865e6b6ce7
當前提交
a190e759c7
@ -86,16 +86,17 @@ func (c CheckinDAO) FindAllActivities(isTeacher bool) []po.Activity {
|
||||
}
|
||||
func getUserActivityExtendedSQL(where string) string {
|
||||
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"
|
||||
}
|
||||
func (c CheckinDAO) FindAllUserActivities(status int) []dto.UserActivityExtended {
|
||||
func (c CheckinDAO) FindUserActivitiesByStatusUserType(status int, userType int) []dto.UserActivityExtended {
|
||||
var arr []dto.UserActivityExtended
|
||||
var err error
|
||||
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 {
|
||||
err = c.Tx.Raw(getUserActivityExtendedSQL("")).Find(&arr).Error
|
||||
err = c.Tx.Raw(getUserActivityExtendedSQL("where u.type=?"), userType).Find(&arr).Error
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -71,6 +71,7 @@ func (c CheckinService) ListActivities(aw *app.Wrapper) app.Result {
|
||||
return aw.Success(checkinDAO.FindAllActivities(isTeacher))
|
||||
}
|
||||
func (c CheckinService) ListUserActivities(aw *app.Wrapper) app.Result {
|
||||
uc := aw.ExtractUserClaims()
|
||||
type StatusReq struct {
|
||||
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 {
|
||||
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 {
|
||||
id, err := strconv.Atoi(aw.Ctx.Query("id"))
|
||||
|
載入中…
x
新增問題並參考
Block a user