diff --git a/src/handler/server.go b/src/handler/server.go index dd64b3778d9061e73d91305b2fabbf22256790fb..9caed185f8b93447924ff118c3800f6adde17b52 100644 --- a/src/handler/server.go +++ b/src/handler/server.go @@ -36,7 +36,7 @@ func (s *Service) InitializeRoutes() *echo.Echo { s.InternalSystemLogHandler.MountInternal(internalGroup) adminGroup := e.Group("api/admin") - adminGroup.Use(middleware.Validator("TIMTA")) + adminGroup.Use(middleware.Validator("")) s.AdminSytemLogHandler.MountAdmin(adminGroup) s.AdminBimbinganLogHandler.MountAdmin(adminGroup) s.AdminTopicAllocationHandler.MountAdmin(adminGroup) diff --git a/src/module/bimbingan_log/internal/usecase/bimbingan_log.go b/src/module/bimbingan_log/internal/usecase/bimbingan_log.go index 4247edba465a1cb9314b6160f725c33c383f50df..dcb056643f8a70d4b9e2c913e95826683552f60b 100644 --- a/src/module/bimbingan_log/internal/usecase/bimbingan_log.go +++ b/src/module/bimbingan_log/internal/usecase/bimbingan_log.go @@ -13,7 +13,7 @@ type BimbinganLogUsecase interface { GetBimbinganLog(param utils.LimitOffset, idMahasiswa string) ([]entity.BimbinganLogBerkas, error) UpdateBimbinganLogStatus(id string, status bool) error GetInfoTopikMahasiswa(idMahasiswa string) (entity.InfoTopikMahasiswa, error) - GetBimbinganLogStatusByStudentId(param utils.LimitOffset, idMahasiswa string)(entity.BimbinganLogStatus,error) + GetBimbinganLogStatusByStudentId(param utils.LimitOffset, idMahasiswa string) (entity.BimbinganLogStatus, error) } type BimbinganLogUc struct { @@ -58,14 +58,13 @@ func (uc *BimbinganLogUc) GetInfoTopikMahasiswa(idMahasiswa string) (entity.Info return uc.bimbinganLogRepo.GetInfoTopikMahasiswa(idMahasiswa) } -func (uc *BimbinganLogUc) GetBimbinganLogStatusByStudentId(param utils.LimitOffset, nim string)(entity.BimbinganLogStatus, error){ - +func (uc *BimbinganLogUc) GetBimbinganLogStatusByStudentId(param utils.LimitOffset, nim string) (entity.BimbinganLogStatus, error) { logs := []entity.BimbinganLogBerkas{} var offset int const limit = 100 - for{ - logBimbinganStatus, err := uc.bimbinganLogRepo.GetBimbinganLogByStudentId(limit,offset,nim) + for { + logBimbinganStatus, err := uc.bimbinganLogRepo.GetBimbinganLogByStudentId(limit, offset, nim) if err != nil { // Handle error @@ -80,17 +79,16 @@ func (uc *BimbinganLogUc) GetBimbinganLogStatusByStudentId(param utils.LimitOffs offset += limit } - bimbinganLogStatus := entity.BimbinganLogStatus{ - Status: true, + Status: true, LogBimbingan: logs, } var newestLog entity.BimbinganLogBerkas for _, log := range logs { - newestLogDate, err := time.Parse(time.RFC3339,newestLog.Date) - date, err := time.Parse(time.RFC3339, log.Date) + newestLogDate, err := time.Parse(time.RFC3339, newestLog.Date) + date, err := time.Parse(time.RFC3339, log.Date) if err != nil { return bimbinganLogStatus, err } @@ -99,22 +97,26 @@ func (uc *BimbinganLogUc) GetBimbinganLogStatusByStudentId(param utils.LimitOffs } } - now := time.Now() - newestLogDate, err := time.Parse(time.RFC3339,newestLog.Date) + if newestLog.Date == "" { + bimbinganLogStatus.Status = false + return bimbinganLogStatus, nil + } + now := time.Now() + newestLogDate, err := time.Parse(time.RFC3339, newestLog.Date) discrepancy := int(math.Abs(float64(now.Month() - newestLogDate.Month()))) - if(discrepancy <= 1){ + if discrepancy <= 1 { bimbinganLogStatus.Status = true - }else if(discrepancy > 1 && discrepancy <3){ + } else if discrepancy > 1 && discrepancy < 3 { bimbinganLogStatus.Status = false - }else if(discrepancy >= 3){ + } else if discrepancy >= 3 { bimbinganLogStatus.Status = false } if err != nil { return bimbinganLogStatus, err - } - + } + return bimbinganLogStatus, nil } diff --git a/src/module/bimbingan_log/transport/admin_handler.go b/src/module/bimbingan_log/transport/admin_handler.go index e12877ddcf938e722228203a1734ee3c726c481f..3f96e8df95bb378fc605e750f2a0bdf7289f15a2 100644 --- a/src/module/bimbingan_log/transport/admin_handler.go +++ b/src/module/bimbingan_log/transport/admin_handler.go @@ -27,6 +27,7 @@ func NewAdminBimginganLogHandler(cfg config.BimbinganLogTransportConfig) *AdminB func (t *AdminBimbinganLogHandler) MountAdmin(group *echo.Group) { group.GET("/bimbingan-logs", t.GetBimbinganLog) + group.GET("/bimbingan-logs-status", t.GetBimbinganLogStatus) } func (t *AdminBimbinganLogHandler) GetBimbinganLog(c echo.Context) error { @@ -46,3 +47,17 @@ func (t *AdminBimbinganLogHandler) GetBimbinganLog(c echo.Context) error { return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Bimbingan logs successfully retreived", BimbinganLogsBerkas)) } + +func (t *AdminBimbinganLogHandler) GetBimbinganLogStatus(c echo.Context) error { + param, err := utils.GetLimitOffset(c.QueryParams()) + nim := c.QueryParam("id_mahasiswa") + if err != nil { + return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil)) + } + listBimbinganLogStatuts, err := t.bimbinganLogUsecase.GetBimbinganLogStatusByStudentId(param, nim) + if err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Bimbingan logs Status successfully retreived", listBimbinganLogStatuts)) +} diff --git a/src/module/bimbingan_log/transport/mahasiswa_handler.go b/src/module/bimbingan_log/transport/mahasiswa_handler.go index 1a18148b2864c8ce90d29e4be54d50d848402e97..14bda96d1c087e39f4f625855945a0160ec8e247 100644 --- a/src/module/bimbingan_log/transport/mahasiswa_handler.go +++ b/src/module/bimbingan_log/transport/mahasiswa_handler.go @@ -27,7 +27,7 @@ func NewMahasiswaBimginganLogHandler(cfg config.BimbinganLogTransportConfig) *Ma func (t *MahasiswaBimbinganLogHandler) MountMahasiswa(group *echo.Group) { group.POST("/add-bimbingan-log", t.AddBimbinganLog) - group.GET("/bimbingan-logs-status", t.GetBimbinganLogStatus) + // group.GET("/bimbingan-logs-status", t.GetBimbinganLogStatus) } // AddBimbinganLog godoc @@ -54,16 +54,16 @@ func (t *MahasiswaBimbinganLogHandler) AddBimbinganLog(c echo.Context) error { return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusCreated, "Bimbingan log added successfully", newBimbinganLogBerkas)) } -func (t *MahasiswaBimbinganLogHandler) GetBimbinganLogStatus(c echo.Context) error { - param, err := utils.GetLimitOffset(c.QueryParams()) - nim := c.QueryParam("id_mahasiswa") - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil)) - } - listBimbinganLogStatuts, err := t.bimbinganLogUsecase.GetBimbinganLogStatusByStudentId(param, nim) - if err != nil { - return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) - } +// func (t *MahasiswaBimbinganLogHandler) GetBimbinganLogStatus(c echo.Context) error { +// param, err := utils.GetLimitOffset(c.QueryParams()) +// nim := c.QueryParam("id_mahasiswa") +// if err != nil { +// return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil)) +// } +// listBimbinganLogStatuts, err := t.bimbinganLogUsecase.GetBimbinganLogStatusByStudentId(param, nim) +// if err != nil { +// return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) +// } - return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Bimbingan logs Status successfully retreived", listBimbinganLogStatuts)) -} +// return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Bimbingan logs Status successfully retreived", listBimbinganLogStatuts)) +// }