From 33d00ee5b449eb6705f7a2da06e098dd93eccef7 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Fri, 26 Jul 2024 09:41:00 +0700 Subject: [PATCH 1/2] add time check on get user --- cmd/main.go | 2 +- internal/user/user.handler.go | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 70916bc..b5a529d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -107,7 +107,7 @@ func main() { userClient := userProto.NewUserServiceClient(authConn) userSvc := user.NewService(userClient, objSvc, logger) - userHdr := user.NewHandler(userSvc, &conf.Img, constant.AllowedContentType, validate, logger) + userHdr := user.NewHandler(userSvc, &conf.Img, &conf.Reg, constant.AllowedContentType, validate, logger) groupClient := groupProto.NewGroupServiceClient(backendConn) groupSvc := group.NewService(groupClient, logger) diff --git a/internal/user/user.handler.go b/internal/user/user.handler.go index 86d622b..e27c96d 100644 --- a/internal/user/user.handler.go +++ b/internal/user/user.handler.go @@ -3,6 +3,7 @@ package user import ( "net/http" "strings" + "time" "github.com/isd-sgcu/rpkm67-gateway/config" "github.com/isd-sgcu/rpkm67-gateway/internal/context" @@ -20,15 +21,17 @@ type Handler interface { type handlerImpl struct { svc Service conf *config.ImageConfig + regConf *config.RegConfig allowedContentType map[string]struct{} validate validator.DtoValidator log *zap.Logger } -func NewHandler(svc Service, conf *config.ImageConfig, allowedContentType map[string]struct{}, validate validator.DtoValidator, log *zap.Logger) Handler { +func NewHandler(svc Service, conf *config.ImageConfig, regConf *config.RegConfig, allowedContentType map[string]struct{}, validate validator.DtoValidator, log *zap.Logger) Handler { return &handlerImpl{ svc: svc, conf: conf, + regConf: regConf, allowedContentType: allowedContentType, validate: validate, log: log, @@ -68,7 +71,13 @@ func (h *handlerImpl) FindOne(c context.Ctx) { return } - c.JSON(http.StatusOK, &dto.FindOneUserResponse{User: res.User}) + resUser := &dto.FindOneUserResponse{User: res.User} + ok, _ := h.checkRegTime() + if !ok { + resUser.User.Baan = "" + } + + c.JSON(http.StatusOK, resUser) } // UpdateProfile godoc @@ -184,3 +193,15 @@ func (h *handlerImpl) createUpdateUserRequestDto(id string, body *dto.UpdateUser GroupId: body.GroupId, } } + +func (h *handlerImpl) checkRegTime() (bool, string) { + nowUTC := time.Now().UTC() + gmtPlus7Location := time.FixedZone("GMT+7", 7*60*60) + nowGMTPlus7 := nowUTC.In(gmtPlus7Location) + if nowGMTPlus7.Before(h.regConf.BaanResultStart) { + h.log.Named("checkRegTime").Warn("Forbidden: Baan Selection Result starts at", zap.Time("time", h.regConf.BaanResultStart)) + return false, "Baan Selection Result starts at " + h.regConf.BaanResultStart.String() + } + + return true, "" +} From 99c18ec18394ea64346ed3473514517d6c87664e Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Fri, 26 Jul 2024 09:42:38 +0700 Subject: [PATCH 2/2] updateprofile cannot upate baan --- internal/user/user.handler.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/user/user.handler.go b/internal/user/user.handler.go index e27c96d..ec23ffd 100644 --- a/internal/user/user.handler.go +++ b/internal/user/user.handler.go @@ -116,6 +116,7 @@ func (h *handlerImpl) UpdateProfile(c context.Ctx) { return } + body.Baan = "" req := h.createUpdateUserRequestDto(id, body) res, appErr := h.svc.UpdateProfile(req)