Skip to content

Commit

Permalink
Merge pull request #60 from isd-sgcu/dev
Browse files Browse the repository at this point in the history
update main
  • Loading branch information
bookpanda authored Jul 26, 2024
2 parents 3af0bb5 + 99c18ec commit 4772318
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 24 additions & 2 deletions internal/user/user.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -107,6 +116,7 @@ func (h *handlerImpl) UpdateProfile(c context.Ctx) {
return
}

body.Baan = ""
req := h.createUpdateUserRequestDto(id, body)

res, appErr := h.svc.UpdateProfile(req)
Expand Down Expand Up @@ -184,3 +194,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, ""
}

0 comments on commit 4772318

Please sign in to comment.