Skip to content
Snippets Groups Projects
Commit ec637989 authored by Fajar Herawan's avatar Fajar Herawan
Browse files

Merge branch 'main' of gitlab.informatika.org:k-01-11/graduit-be

parents 59af8cf8 6fe1cffe
1 merge request!7deploy
Pipeline #62307 failed with stages
in 7 minutes and 11 seconds
...@@ -59,7 +59,7 @@ func (s *Service) InitializeRoutes() *echo.Echo { ...@@ -59,7 +59,7 @@ func (s *Service) InitializeRoutes() *echo.Echo {
s.DosbingBimbinganLogHandler.MountDosbing(dosbingGroup) s.DosbingBimbinganLogHandler.MountDosbing(dosbingGroup)
TIMTAGroup := e.Group("api/TIMTA") TIMTAGroup := e.Group("api/TIMTA")
TIMTAGroup.Use(middleware.Validator("TIM_TA")) TIMTAGroup.Use(middleware.Validator("S1_TIM_TA"))
s.TIMTASchedulingHandler.MountTIMTA(TIMTAGroup) s.TIMTASchedulingHandler.MountTIMTA(TIMTAGroup)
s.TIMTAPendaftaranSidSemHandler.MountTIMTA(TIMTAGroup) s.TIMTAPendaftaranSidSemHandler.MountTIMTA(TIMTAGroup)
return e return e
......
package middleware package middleware
import ( import (
"encoding/json"
"net/http" "net/http"
"os" "os"
...@@ -8,8 +9,6 @@ import ( ...@@ -8,8 +9,6 @@ import (
"gitlab.informatika.org/k-01-11/graduit-be/src/utils" "gitlab.informatika.org/k-01-11/graduit-be/src/utils"
) )
// masih mentah baru raba2
func Validator(expectedRole string) echo.MiddlewareFunc { func Validator(expectedRole string) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc { return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
...@@ -37,10 +36,21 @@ func Validator(expectedRole string) echo.MiddlewareFunc { ...@@ -37,10 +36,21 @@ func Validator(expectedRole string) echo.MiddlewareFunc {
} }
defer resp.Body.Close() defer resp.Body.Close()
var payload utils.Payload
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Failed to decode response body", err))
}
if payload.Roles[0] != expectedRole {
return c.JSON(http.StatusForbidden, utils.ResponseDetailOutput(false, http.StatusForbidden, "Forbidden", err))
}
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return c.JSON(resp.StatusCode, utils.ResponseDetailOutput(false, resp.StatusCode, "Unauthorized", resp.Body)) return c.JSON(resp.StatusCode, utils.ResponseDetailOutput(false, resp.StatusCode, "Unauthorized", resp.Body))
} }
c.Set("authPayload", payload)
return next(c) return next(c)
} }
} }
......
...@@ -18,13 +18,22 @@ type ResponseDetail struct { ...@@ -18,13 +18,22 @@ type ResponseDetail struct {
} }
type PageLimitSearchID struct { type PageLimitSearchID struct {
Page int Page int
Limit int Limit int
Search string Search string
ID string ID string
Periode string Periode string
} }
type Payload struct {
ID string
Nama string
Email string
NIM string
Roles []string
Kontak string
}
func ResponseDetailOutput(success bool, code int, message string, data interface{}) ResponseDetail { func ResponseDetailOutput(success bool, code int, message string, data interface{}) ResponseDetail {
res := ResponseDetail{ res := ResponseDetail{
Success: success, Success: success,
...@@ -107,4 +116,4 @@ func GetPageLimitSearchID(urlValues url.Values) (output PageLimitSearchID, err e ...@@ -107,4 +116,4 @@ func GetPageLimitSearchID(urlValues url.Values) (output PageLimitSearchID, err e
} }
return *param, nil return *param, nil
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment