diff --git a/config/config.go b/config/config.go index cd75613..52a3060 100644 --- a/config/config.go +++ b/config/config.go @@ -5,9 +5,10 @@ import ( ) type MSHostsConfig struct { - UsersHost string - StoreHost string - EventsHost string + UsersHost string + StoreHost string + EventsHost string + PersonsHost string } type ServerConfig struct { @@ -23,9 +24,10 @@ type Config struct { func New() *Config { return &Config{ MSHosts: MSHostsConfig{ - UsersHost: getEnv("ASTRA-USERS", "http://localhost:8082"), - StoreHost: getEnv("ASTRA-FILE-STORAGE", "http://localhost:8081"), - EventsHost: getEnv("ASTRA-EVENTS", "http://localhost:8083"), + UsersHost: getEnv("ASTRA-USERS", "http://localhost:8082"), + StoreHost: getEnv("ASTRA-FILE-STORAGE", "http://localhost:8081"), + EventsHost: getEnv("ASTRA-EVENTS", "http://localhost:8083"), + PersonsHost: getEnv("ASTRA-PESONAL-INFORMATION", "http://localhost:8083"), }, Server: ServerConfig{ Port: getEnv("PORT", "8080"), diff --git a/main.go b/main.go index 8c67de9..14640c2 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "astra-api-gateway/handler" "astra-api-gateway/mw" "astra-api-gateway/services/events" + "astra-api-gateway/services/personal-information" "astra-api-gateway/services/store" "astra-api-gateway/services/users" "github.com/joho/godotenv" @@ -51,6 +52,11 @@ func main() { e.POST("/events", events.CreateEvent) e.DELETE("/events", events.DeleteEvent) + // Persons + e.GET("/persons", personal_information.GetPDList) + e.GET("/persons/:id", personal_information.GetPD) + e.POST("/persons", personal_information.CreatePD) + // Store store_g := e.Group("/store") store_g.GET("/*", store.GetFileFromStore) diff --git a/services/personal-information/personal-information.go b/services/personal-information/personal-information.go new file mode 100644 index 0000000..aa11bb0 --- /dev/null +++ b/services/personal-information/personal-information.go @@ -0,0 +1,47 @@ +package personal_information + +import ( + "astra-api-gateway/config" + "astra-api-gateway/pkg/api" + "github.com/labstack/echo/v4" + "net/http" +) + +func GetPDList(c echo.Context) error { + data, err, resp := api.GetRequest( + config.Env.MSHosts.PersonsHost+"/persons/", + c.Request().Header, c.Request().URL.RawQuery) + + if err != nil { + return c.NoContent(http.StatusBadGateway) + } + + return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data) +} + +func GetPD(c echo.Context) error { + id := c.Param("id") + + data, err, resp := api.GetRequest( + config.Env.MSHosts.PersonsHost+"/persons/"+id, + c.Request().Header, c.Request().URL.RawQuery) + + if err != nil { + return c.NoContent(http.StatusBadGateway) + } + + return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data) +} + +func CreatePD(c echo.Context) error { + data, err, resp := api.PostRequest( + config.Env.MSHosts.EventsHost+"/persons/", + c.Request().Body, + c.Request().Header) + + if err != nil { + return c.NoContent(http.StatusBadGateway) + } + + return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data) +}