mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore(go): use json
instead of jsonapi
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"memos/api"
|
||||
"memos/common"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/jsonapi"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
@ -21,9 +21,35 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
||||
}
|
||||
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||
if err := jsonapi.MarshalPayload(c.Response().Writer, user); err != nil {
|
||||
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
g.POST("/user/rename_check", func(c echo.Context) error {
|
||||
userRenameCheck := &api.UserRenameCheck{}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(userRenameCheck); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user rename check request").SetInternal(err)
|
||||
}
|
||||
|
||||
if userRenameCheck.Name == "" {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user rename check request")
|
||||
}
|
||||
|
||||
userFind := &api.UserFind{
|
||||
Name: &userRenameCheck.Name,
|
||||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
|
||||
}
|
||||
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
g.PATCH("user/me", func(c echo.Context) error {
|
||||
@ -31,7 +57,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
||||
userPatch := &api.UserPatch{
|
||||
Id: userId,
|
||||
}
|
||||
if err := jsonapi.UnmarshalPayload(c.Request().Body, userPatch); err != nil {
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(userPatch); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch user request").SetInternal(err)
|
||||
}
|
||||
|
||||
@ -46,7 +72,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
||||
}
|
||||
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||
if err := jsonapi.MarshalPayload(c.Response().Writer, user); err != nil {
|
||||
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user