add user service methods

This commit is contained in:
kandrusyak
2023-06-23 20:48:45 +03:00
parent 7d2aaf40e4
commit 7f4122360f
3 changed files with 100 additions and 6 deletions

View File

@@ -55,15 +55,57 @@ func Login(c echo.Context) (err error) {
}
func GetCurrentUser(c echo.Context) error {
u := new(model.User)
data, err := api.GetRequest(config.Env.MSHosts.UsersHost+"/me", c.Request().Header)
err = json.Unmarshal(data, &u)
if err != nil {
return c.NoContent(http.StatusBadGateway)
}
return c.JSON(http.StatusOK, u)
return c.JSONBlob(http.StatusOK, data)
}
func GetUsers(c echo.Context) error {
id := c.Param("id")
data, err := api.GetRequest(
config.Env.MSHosts.UsersHost+"/"+id,
c.Request().Header, c.Request().URL.RawQuery)
if err != nil {
return c.NoContent(http.StatusBadGateway)
}
return c.JSONBlob(http.StatusOK, data)
}
func DeleteUser(c echo.Context) error {
id := c.Param("id")
data, err := api.DeleteRequest(
config.Env.MSHosts.UsersHost+"/"+id,
c.Request().Header)
if err != nil {
return c.NoContent(http.StatusBadGateway)
}
return c.JSONBlob(http.StatusOK, data)
}
func UpdateUser(c echo.Context) (err error) {
id := c.Param("id")
// Bind
u := new(model.User)
if err = c.Bind(u); err != nil {
return
}
data, err := api.PatchRequest(config.Env.MSHosts.UsersHost+"/"+id, u, c.Request().Header)
if err != nil {
return c.NoContent(http.StatusBadGateway)
}
return c.JSONBlob(http.StatusOK, data)
}