add events

This commit is contained in:
andrusyakka
2023-07-17 14:30:22 +03:00
parent 9234b577bb
commit c8ce5a910e
5 changed files with 99 additions and 29 deletions

61
services/events/events.go Normal file
View File

@@ -0,0 +1,61 @@
package events
import (
"astra-api-gateway/config"
"astra-api-gateway/pkg/api"
"github.com/labstack/echo/v4"
"net/http"
)
func GetEvents(c echo.Context) error {
data, err, resp := api.GetRequest(
config.Env.MSHosts.EventsHost+"/",
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 GetEvent(c echo.Context) error {
id := c.Param("id")
data, err, resp := api.GetRequest(
config.Env.MSHosts.EventsHost+"/"+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 CreateEvent(c echo.Context) error {
data, err, resp := api.PostRequest(
config.Env.MSHosts.EventsHost+"/",
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)
}
func DeleteEvent(c echo.Context) error {
id := c.Param("id")
data, err, resp := api.DeleteRequest(
config.Env.MSHosts.EventsHost+"/"+id,
c.Request().Header)
if err != nil {
return c.NoContent(http.StatusBadGateway)
}
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
}