diff --git a/src/module/dashboard_dosbing/transport/dosbing_handler.go b/src/module/dashboard_dosbing/transport/dosbing_handler.go index 05d2a49aa863a0a43ce6015435bda0848272b802..3473f406adf86200c9ecc3d372cf5b55c0297601 100644 --- a/src/module/dashboard_dosbing/transport/dosbing_handler.go +++ b/src/module/dashboard_dosbing/transport/dosbing_handler.go @@ -1,9 +1,7 @@ package transport import ( - "encoding/json" "net/http" - "os" "strconv" "github.com/labstack/echo/v4" @@ -44,43 +42,13 @@ func (t *DosbingDashboardHandler) MountDosbing(group *echo.Group) { // @Success 200 {object} []entity.MahasiswaBimbingan "List mahasiswa successfully retrieved" // @Router /api/dosbing/dashboard [get] func (t *DosbingDashboardHandler) GetMahasiswa(c echo.Context) error { - cookie, err := c.Cookie("gradu-it.access-token") + payload, ok := c.Get("authPayload").(utils.Payload) - if err != nil { - return c.JSON(http.StatusUnauthorized, utils.ResponseDetailOutput(false, http.StatusUnauthorized, "Unauthorized", nil)) - } - - tokenString := cookie.Value - - client := &http.Client{} - - auth_url := os.Getenv("LOGIN_API_URL") + "/auth/self" - - req, err := http.NewRequest(http.MethodGet, auth_url, nil) - - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Internal Server Error", err)) - } - - req.Header.Set("Authorization", "Bearer "+tokenString) - - resp, err := client.Do(req) - - defer resp.Body.Close() - - // Decode JSON response - var response map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&response) - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error decoding response", err)) - } - - // Accessing the "id" field - idDosen, ok := response["id"].(string) if !ok { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error parsing id", nil)) } + idDosen := payload.ID sizeStr := c.QueryParam("size") offsetStr := c.QueryParam("offset") search := c.QueryParam("search") @@ -119,43 +87,14 @@ func (t *DosbingDashboardHandler) GetMahasiswa(c echo.Context) error { // @Success 200 {object} entity.JumlahMahasiswa "List mahasiswa successfully retreived" // @Router /api/dosbing/dashboard/statistic [get] func (t *DosbingDashboardHandler) GetAmountMahasiswa(c echo.Context) error { - cookie, err := c.Cookie("gradu-it.access-token") - - if err != nil { - return c.JSON(http.StatusUnauthorized, utils.ResponseDetailOutput(false, http.StatusUnauthorized, "Unauthorized", nil)) - } - - tokenString := cookie.Value - - client := &http.Client{} - - auth_url := os.Getenv("LOGIN_API_URL") + "/auth/self" - - req, err := http.NewRequest(http.MethodGet, auth_url, nil) - - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Internal Server Error", err)) - } - - req.Header.Set("Authorization", "Bearer "+tokenString) - - resp, err := client.Do(req) - - defer resp.Body.Close() - - // Decode JSON response - var response map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&response) - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error decoding response", err)) - } + payload, ok := c.Get("authPayload").(utils.Payload) - // Accessing the "id" field - idDosen, ok := response["id"].(string) if !ok { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error parsing id", nil)) } + idDosen := payload.ID + if idDosen == "" { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "insert id_dosen", nil)) } @@ -178,43 +117,14 @@ func (t *DosbingDashboardHandler) GetAmountMahasiswa(c echo.Context) error { // @Success 200 {object} entity.StatusBimbinganMahasiswa "List mahasiswa successfully retreived" // @Router /api/dosbing/dashboard/status-bimbingan [get] func (t *DosbingDashboardHandler) GetAmountStatusBimbinganMahasiswa(c echo.Context) error { - cookie, err := c.Cookie("gradu-it.access-token") - - if err != nil { - return c.JSON(http.StatusUnauthorized, utils.ResponseDetailOutput(false, http.StatusUnauthorized, "Unauthorized", nil)) - } - - tokenString := cookie.Value - - client := &http.Client{} + payload, ok := c.Get("authPayload").(utils.Payload) - auth_url := os.Getenv("LOGIN_API_URL") + "/auth/self" - - req, err := http.NewRequest(http.MethodGet, auth_url, nil) - - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Internal Server Error", err)) - } - - req.Header.Set("Authorization", "Bearer "+tokenString) - - resp, err := client.Do(req) - - defer resp.Body.Close() - - // Decode JSON response - var response map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&response) - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error decoding response", err)) - } - - // Accessing the "id" field - idDosen, ok := response["id"].(string) if !ok { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error parsing id", nil)) } + idDosen := payload.ID + if idDosen == "" { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "insert id_dosen", nil)) } diff --git a/src/module/dashboard_mahasiswa/internal/repository/dashboard_mahasiswa.go b/src/module/dashboard_mahasiswa/internal/repository/dashboard_mahasiswa.go index 9ee048b96f734384a114ec20c6a609542aae9d29..860e699751252ed180710c66e5b45453546b063f 100644 --- a/src/module/dashboard_mahasiswa/internal/repository/dashboard_mahasiswa.go +++ b/src/module/dashboard_mahasiswa/internal/repository/dashboard_mahasiswa.go @@ -93,16 +93,6 @@ func (repo *DashboardMahasiswaRepo) GetDashboardMahasiswaById(IdMahasiswa string result = repo.DBRead.Where("id_mahasiswa = ?", dashboardMahasiswa.Mahasiswa.IdMahasiswa). Find(&logBimbinganModel) - // repo.DBRead.Table("bimbingan_logs"). - // Select(`bimbingan_logs.id AS id, - // bimbingan_logs.date AS waktu_bimbingan, - // bimbingan_logs.laporan_kemajuan AS laporan_kemajuan, - // bimbingan_logs.todo AS todo, - // bimbingan_logs.next_bimbingan AS next_bimbingan, - // bimbingan_logs.status AS status`). - // Where("bimbingan_logs.id_mahasiswa = ?", dashboardMahasiswa.Mahasiswa.IdMahasiswa). - // Scan(&logBimbingan) - for i := range logBimbinganModel { repo.DBRead.Table("berkas"). Select("id, nama, link"). diff --git a/src/module/dashboard_mahasiswa/transport/mahasiswa_handler.go b/src/module/dashboard_mahasiswa/transport/mahasiswa_handler.go index 4fb708df2d4782fc9542754ced3acf76aef98444..ebfceadc734d851bd718cdce2027a35d9063faf2 100644 --- a/src/module/dashboard_mahasiswa/transport/mahasiswa_handler.go +++ b/src/module/dashboard_mahasiswa/transport/mahasiswa_handler.go @@ -1,9 +1,7 @@ package transport import ( - "encoding/json" "net/http" - "os" "github.com/labstack/echo/v4" "gitlab.informatika.org/k-01-11/graduit-be/src/module/dashboard_mahasiswa/config" @@ -39,44 +37,13 @@ func (t *MahasiswaDashboardHandler) MountMahasiswa(group *echo.Group) { // @Success 200 {object} entity.DashboardMahasiswaRet // @Router /api/mahasiswa/dashboard [get] func (t *MahasiswaDashboardHandler) GetStatusMahasiswa(c echo.Context) error { - cookie, err := c.Cookie("gradu-it.access-token") + payload, ok := c.Get("authPayload").(utils.Payload) - if err != nil { - return c.JSON(http.StatusUnauthorized, utils.ResponseDetailOutput(false, http.StatusUnauthorized, "Unauthorized", nil)) - } - - tokenString := cookie.Value - - client := &http.Client{} - - auth_url := os.Getenv("LOGIN_API_URL") + "/auth/self" - - req, err := http.NewRequest(http.MethodGet, auth_url, nil) - - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Internal Server Error", err)) - } - - req.Header.Set("Authorization", "Bearer "+tokenString) - - resp, err := client.Do(req) - - defer resp.Body.Close() - - // Decode JSON response - var response map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&response) - if err != nil { - return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error decoding response", err)) - } - - // Accessing the "id" field - IdMahasiswa, ok := response["id"].(string) if !ok { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Error parsing id", nil)) } - dashboardMahasiswa, err := t.dashboardMahasiswaUsecase.GetDashboardMahasiswa(IdMahasiswa) + dashboardMahasiswa, err := t.dashboardMahasiswaUsecase.GetDashboardMahasiswa(payload.ID) if err != nil { return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) }