add events
This commit is contained in:
61
services/events/events.go
Normal file
61
services/events/events.go
Normal 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)
|
||||
}
|
||||
@@ -13,15 +13,9 @@ import (
|
||||
)
|
||||
|
||||
func Login(c echo.Context) (err error) {
|
||||
// Bind
|
||||
u := new(model.User)
|
||||
if err = c.Bind(u); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := api.PostRequest(config.Env.MSHosts.UsersHost+"/login", u, c.Request().Header)
|
||||
|
||||
u.Password = ""
|
||||
data, err, _ := api.PostRequest(config.Env.MSHosts.UsersHost+"/login", c.Request().Body, c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
@@ -85,7 +79,7 @@ func GetUsers(c echo.Context) error {
|
||||
func DeleteUser(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err := api.DeleteRequest(
|
||||
data, err, resp := api.DeleteRequest(
|
||||
config.Env.MSHosts.UsersHost+"/"+id,
|
||||
c.Request().Header)
|
||||
|
||||
@@ -93,7 +87,7 @@ func DeleteUser(c echo.Context) error {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.JSONBlob(http.StatusOK, data)
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
|
||||
func UpdateUser(c echo.Context) (err error) {
|
||||
@@ -125,3 +119,15 @@ func GetOrganizations(c echo.Context) error {
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
|
||||
func GetPositions(c echo.Context) error {
|
||||
data, err, resp := api.GetRequest(
|
||||
config.Env.MSHosts.UsersHost+"/positions",
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user