From 9c81f879d9ab93fae27654c993c0fc33195ef3f9 Mon Sep 17 00:00:00 2001
From: arieljovananda88 <jovanandaa@gmail.com>
Date: Mon, 10 Jun 2024 02:15:03 +0700
Subject: [PATCH] feat: full wiring for reka pendaftaran tim ta

---
 src/module/pendaftaran/entity/pendaftaran.go  | 10 +++++++
 .../internal/repository/pendaftaran.go        | 27 +++++++++++++++++++
 .../internal/usecase/pendaftaran.go           | 10 +++++++
 .../internal/usecase/repository.go            |  2 ++
 .../pendaftaran/transport/admin_handler.go    | 24 +++++++++++++++++
 5 files changed, 73 insertions(+)

diff --git a/src/module/pendaftaran/entity/pendaftaran.go b/src/module/pendaftaran/entity/pendaftaran.go
index 94fb813..9a93908 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 1fd535b..1d224aa 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 90f6c94..554a766 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 6cf957f..999d4b2 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 2f5aae3..97992c8 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 {
-- 
GitLab