add medical card service

This commit is contained in:
kandrusyak
2023-07-24 23:59:44 +03:00
parent f01ac2e42a
commit 4ea02e5d08
4 changed files with 101 additions and 8 deletions

View File

@@ -5,10 +5,11 @@ import (
) )
type MSHostsConfig struct { type MSHostsConfig struct {
UsersHost string UsersHost string
StoreHost string StoreHost string
EventsHost string EventsHost string
PersonsHost string PersonsHost string
MedicalCardHost string
} }
type ServerConfig struct { type ServerConfig struct {
@@ -24,10 +25,11 @@ type Config struct {
func New() *Config { func New() *Config {
return &Config{ return &Config{
MSHosts: MSHostsConfig{ MSHosts: MSHostsConfig{
UsersHost: getEnv("ASTRA-USERS", "http://localhost:8082"), UsersHost: getEnv("ASTRA-USERS", "http://localhost:8082"),
StoreHost: getEnv("ASTRA-FILE-STORAGE", "http://localhost:8081"), StoreHost: getEnv("ASTRA-FILE-STORAGE", "http://localhost:8081"),
EventsHost: getEnv("ASTRA-EVENTS", "http://localhost:8083"), EventsHost: getEnv("ASTRA-EVENTS", "http://localhost:8083"),
PersonsHost: getEnv("ASTRA-PESONAL-INFORMATION", "http://localhost:8083"), PersonsHost: getEnv("ASTRA-PESONAL-INFORMATION", "http://localhost:8083"),
MedicalCardHost: getEnv("MEDICAL-INFORMATION", "http://localhost:8083"),
}, },
Server: ServerConfig{ Server: ServerConfig{
Port: getEnv("PORT", "8080"), Port: getEnv("PORT", "8080"),

11
main.go
View File

@@ -5,6 +5,7 @@ import (
"astra-api-gateway/handler" "astra-api-gateway/handler"
"astra-api-gateway/mw" "astra-api-gateway/mw"
"astra-api-gateway/services/events" "astra-api-gateway/services/events"
medical_information "astra-api-gateway/services/medical-information"
"astra-api-gateway/services/personal-information" "astra-api-gateway/services/personal-information"
"astra-api-gateway/services/store" "astra-api-gateway/services/store"
"astra-api-gateway/services/users" "astra-api-gateway/services/users"
@@ -57,6 +58,16 @@ func main() {
e.GET("/persons/:id", personal_information.GetPD) e.GET("/persons/:id", personal_information.GetPD)
e.POST("/persons", personal_information.CreatePD) 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
store_g := e.Group("/store") store_g := e.Group("/store")
store_g.GET("/*", store.GetFileFromStore) store_g.GET("/*", store.GetFileFromStore)

View File

@@ -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)
}

View File

@@ -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)
}