add user service methods
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user