add personal information service

This commit is contained in:
andrusyakka
2023-07-24 16:00:56 +03:00
parent fdc25b46fb
commit f01ac2e42a
3 changed files with 61 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ type MSHostsConfig struct {
UsersHost string UsersHost string
StoreHost string StoreHost string
EventsHost string EventsHost string
PersonsHost string
} }
type ServerConfig struct { type ServerConfig struct {
@@ -26,6 +27,7 @@ func New() *Config {
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"),
}, },
Server: ServerConfig{ Server: ServerConfig{
Port: getEnv("PORT", "8080"), Port: getEnv("PORT", "8080"),

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"
"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"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@@ -51,6 +52,11 @@ func main() {
e.POST("/events", events.CreateEvent) e.POST("/events", events.CreateEvent)
e.DELETE("/events", events.DeleteEvent) 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
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 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)
}