From a190e759c77ac470205137c608b7262769b3b22c Mon Sep 17 00:00:00 2001 From: juzeon <812312770@qq.com> Date: Mon, 30 Jan 2023 12:12:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E7=94=A8=E6=88=B7type?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/checkin.go | 9 +++++---- service/checkin.go | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dao/checkin.go b/dao/checkin.go index 8f7cf71..c69a7d0 100644 --- a/dao/checkin.go +++ b/dao/checkin.go @@ -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) diff --git a/service/checkin.go b/service/checkin.go index 3d146cc..645adc7 100644 --- a/service/checkin.go +++ b/service/checkin.go @@ -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"))