From 4ea02e5d08f629d1601d04444fa1363ef4f40e34 Mon Sep 17 00:00:00 2001 From: kandrusyak Date: Mon, 24 Jul 2023 23:59:44 +0300 Subject: [PATCH] add medical card service --- config/config.go | 18 +++---- main.go | 11 +++++ services/medical-information/checkups.go | 47 +++++++++++++++++++ services/medical-information/medical-cards.go | 33 +++++++++++++ 4 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 services/medical-information/checkups.go create mode 100644 services/medical-information/medical-cards.go diff --git a/config/config.go b/config/config.go index 52a3060..fffeabc 100644 --- a/config/config.go +++ b/config/config.go @@ -5,10 +5,11 @@ import ( ) type MSHostsConfig struct { - UsersHost string - StoreHost string - EventsHost string - PersonsHost string + UsersHost string + StoreHost string + EventsHost string + PersonsHost string + MedicalCardHost string } type ServerConfig struct { @@ -24,10 +25,11 @@ 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"), - PersonsHost: getEnv("ASTRA-PESONAL-INFORMATION", "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"), + MedicalCardHost: getEnv("MEDICAL-INFORMATION", "http://localhost:8083"), }, Server: ServerConfig{ Port: getEnv("PORT", "8080"), diff --git a/main.go b/main.go index 14640c2..8e87305 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" + medical_information "astra-api-gateway/services/medical-information" "astra-api-gateway/services/personal-information" "astra-api-gateway/services/store" "astra-api-gateway/services/users" @@ -57,6 +58,16 @@ func main() { e.GET("/persons/:id", personal_information.GetPD) e.POST("/persons", personal_information.CreatePD) + // Checkups + e.GET("/checkups", medical_information.GetCheckupList) + e.GET("/checkups/:id", medical_information.GetCheckup) + e.POST("/checkups", medical_information.CreateCheckup) + + // Medical cards + + e.GET("/medical_cards", medical_information.GetMCList) + e.POST("/medical_cards", medical_information.CreateMC) + // Store store_g := e.Group("/store") store_g.GET("/*", store.GetFileFromStore) diff --git a/services/medical-information/checkups.go b/services/medical-information/checkups.go new file mode 100644 index 0000000..5a5121c --- /dev/null +++ b/services/medical-information/checkups.go @@ -0,0 +1,47 @@ +package medical_information + +import ( + "astra-api-gateway/config" + "astra-api-gateway/pkg/api" + "github.com/labstack/echo/v4" + "net/http" +) + +func GetCheckupList(c echo.Context) error { + data, err, resp := api.GetRequest( + config.Env.MSHosts.MedicalCardHost+"/checkups/", + 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 GetCheckup(c echo.Context) error { + id := c.Param("id") + + data, err, resp := api.GetRequest( + config.Env.MSHosts.MedicalCardHost+"/checkups/"+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 CreateCheckup(c echo.Context) error { + data, err, resp := api.PostRequest( + config.Env.MSHosts.MedicalCardHost+"/checkups/", + 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) +} diff --git a/services/medical-information/medical-cards.go b/services/medical-information/medical-cards.go new file mode 100644 index 0000000..5c2dc34 --- /dev/null +++ b/services/medical-information/medical-cards.go @@ -0,0 +1,33 @@ +package medical_information + +import ( + "astra-api-gateway/config" + "astra-api-gateway/pkg/api" + "github.com/labstack/echo/v4" + "net/http" +) + +func GetMCList(c echo.Context) error { + data, err, resp := api.GetRequest( + config.Env.MSHosts.MedicalCardHost+"/medical_cards/", + 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 CreateMC(c echo.Context) error { + data, err, resp := api.PostRequest( + config.Env.MSHosts.MedicalCardHost+"/medical_cards/", + 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) +}