diff --git a/src/module/pendaftaran/entity/pendaftaran.go b/src/module/pendaftaran/entity/pendaftaran.go index 94fb813fca4af68afd817855c37dc0b068030fc0..9a93908c228e846b3c770fe170a68de5f96c1a66 100644 --- a/src/module/pendaftaran/entity/pendaftaran.go +++ b/src/module/pendaftaran/entity/pendaftaran.go @@ -84,6 +84,11 @@ type DosenPembimbing struct { Nama string `json:"nama"` } +type DosenPembimbings struct { + ID string `json:"id"` + Nama string `json:"nama"` + Email string `json:"email"` +} type RiwayatPendaftaranRes struct { ID string `json:"id"` InterviewAt string `json:"jadwalInterview"` @@ -114,6 +119,11 @@ type UpdateStatusReq struct { Status string `json:"status"` } +type UpdateDosbingReq struct { + IdDosen []string `json:"pembimbing_ids"` + IDPendaftaran string `json:"id_pendaftaran"` +} + type UpdateStatusByIdReq struct { IDPendaftaran string `json:"id_pendaftaran"` Status string `json:"status"` diff --git a/src/module/pendaftaran/internal/repository/pendaftaran.go b/src/module/pendaftaran/internal/repository/pendaftaran.go index 1fd535b639b0c42c9159931eb4606f40f29d10bc..1d224aa3cad097834e17b3b031361c8922fe32a0 100644 --- a/src/module/pendaftaran/internal/repository/pendaftaran.go +++ b/src/module/pendaftaran/internal/repository/pendaftaran.go @@ -224,6 +224,20 @@ func (repo *PendaftaranRepo) UpdateStatusById(status string, idPendaftaran strin return nil } +func (repo *PendaftaranRepo) UpdateDosbing(idDosbing string, idPendaftaran string) error { + updates := map[string]interface{}{ + "id_dosen": idDosbing, + } + + if err := repo.DBWrite.Table("pendaftaran_ta"). + Where("id = ?", idPendaftaran). + Updates(updates).Error; err != nil { + return err + } + + return nil +} + func (repo *PendaftaranRepo) CountApproved(idDosen string) (int64, error) { var count int64 @@ -356,3 +370,16 @@ func (repo *PendaftaranRepo) GetDosbingForPendaftaran(idMahasiswa string) ([]ent return res, nil } + +func (repo *PendaftaranRepo) GetAllDosbing() ([]entity.DosenPembimbings, error) { + var res []entity.DosenPembimbings + err := repo.DBRead.Table("pengguna"). + Select("pengguna.id, pengguna.nama, pengguna.email"). + Where("? = ANY(pengguna.roles)", "S1_PEMBIMBING"). + Scan(&res).Error + if err != nil { + return nil, err + } + + return res, nil +} diff --git a/src/module/pendaftaran/internal/usecase/pendaftaran.go b/src/module/pendaftaran/internal/usecase/pendaftaran.go index 90f6c946d1dede4557067b150196292f0361411e..554a76619551ed61bcb69a46901ca760349482bb 100644 --- a/src/module/pendaftaran/internal/usecase/pendaftaran.go +++ b/src/module/pendaftaran/internal/usecase/pendaftaran.go @@ -26,6 +26,8 @@ type PendaftaranUsecase interface { GetStatisticsPendaftaranTimta() (entity.Stats, error) UpdateStatusById(status string, idPendaftaran string) error GetRiwayatPendaftaran(idMahasiswa string) ([]entity.RiwayatPendaftaranRes, error) + GetAllDosbing() ([]entity.DosenPembimbings, error) + UpdateDosbing(idDosen []string, idPendaftaran string) error } type PendaftaranUc struct { @@ -85,6 +87,10 @@ func (uc *PendaftaranUc) GetDetailRekapPendafataran(idDosen string, idMahasiswa return uc.pendaftaranRepo.GetDetailRekapPendafataran(idDosen, idMahasiswa) } +func (uc *PendaftaranUc) GetAllDosbing() ([]entity.DosenPembimbings, error) { + return uc.pendaftaranRepo.GetAllDosbing() +} + func (uc *PendaftaranUc) UpdateInterview(interviewAt string, idDosen string, idMahasiswa string) error { if interviewAt == "" { return errors.New("interview timestamp cannot be empty") @@ -99,6 +105,10 @@ func (uc *PendaftaranUc) UpdateStatus(status string, idDosen string, idMahasiswa return uc.pendaftaranRepo.UpdateStatus(status, idDosen, idMahasiswa) } +func (uc *PendaftaranUc) UpdateDosbing(idDosen []string, idPendaftaran string) error { + return uc.pendaftaranRepo.UpdateDosbing(idDosen[0], idPendaftaran) +} + func (uc *PendaftaranUc) UpdateStatusById(status string, idPendaftaran string) error { if status == "" { return errors.New("interview timestamp cannot be empty") diff --git a/src/module/pendaftaran/internal/usecase/repository.go b/src/module/pendaftaran/internal/usecase/repository.go index 6cf957f115d861f0faca65c8a2697ca4424b8878..999d4b28aca174c077f5fde624083bf9d34563d0 100644 --- a/src/module/pendaftaran/internal/usecase/repository.go +++ b/src/module/pendaftaran/internal/usecase/repository.go @@ -31,4 +31,6 @@ type PendaftaranRepository interface { UpdateStatusById(status string, idPendaftaran string) error GetRiwayatPendaftaran(idMahasiswa string) ([]entity.RiwayatPendaftaran, error) GetDosbingForPendaftaran(idMahasiswa string) ([]entity.DosenPembimbing, error) + GetAllDosbing() ([]entity.DosenPembimbings, error) + UpdateDosbing(idDosbing string, idPendaftaran string) error } diff --git a/src/module/pendaftaran/transport/admin_handler.go b/src/module/pendaftaran/transport/admin_handler.go index 2f5aae3e5fac5405d43fb755b238b2965137effc..97992c8b30e1f5269f4bf2162d5d14d8383ca040 100644 --- a/src/module/pendaftaran/transport/admin_handler.go +++ b/src/module/pendaftaran/transport/admin_handler.go @@ -44,6 +44,8 @@ func (t *AdminPendaftaranHandler) MountAdmin(group *echo.Group) { group.GET("/statistics", t.GetStatistics) group.GET("/statistics-timta", t.GetStatisticsTimta) group.GET("/riwayat-pendaftaran", t.GetRiwayatPendaftaran) + group.GET("/all-dosbing", t.GetAllDosbing) + group.PUT("/update-dosbing", t.UpdateDosbing) } // AddPendaftaran adds a new pendaftaran record. @@ -93,6 +95,15 @@ func (t *AdminPendaftaranHandler) GetPendaftaran(c echo.Context) error { return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Pendaftaran successfully retreived", listGroupLimit)) } +func (t *AdminPendaftaranHandler) GetAllDosbing(c echo.Context) error { + dosbings, err := t.pendaftaranUsecase.GetAllDosbing() + 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, "All dosbing successfully retreived", dosbings)) +} + func (t *AdminPendaftaranHandler) GetPendaftaranByIdDosen(c echo.Context) error { payload, ok := c.Get("authPayload").(utils.Payload) if !ok { @@ -186,6 +197,19 @@ func (t *AdminPendaftaranHandler) UpdateStatus(c echo.Context) error { return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Interview successfully updated", err)) } +func (t *AdminPendaftaranHandler) UpdateDosbing(c echo.Context) error { + request := new(entity.UpdateDosbingReq) + if err := c.Bind(&request); err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + err := t.pendaftaranUsecase.UpdateDosbing(request.IdDosen, request.IDPendaftaran) + 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, "Interview successfully updated", err)) +} + func (t *AdminPendaftaranHandler) UpdateStatusById(c echo.Context) error { request := new(entity.UpdateStatusByIdReq) if err := c.Bind(&request); err != nil {