|
|
@ -13,9 +13,9 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|
|
|
func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|
|
|
g.POST("/memo", func(c echo.Context) error {
|
|
|
|
g.POST("/memo", func(c echo.Context) error {
|
|
|
|
userId := c.Get(getUserIdContextKey()).(int)
|
|
|
|
userID := c.Get(getUserIDContextKey()).(int)
|
|
|
|
memoCreate := &api.MemoCreate{
|
|
|
|
memoCreate := &api.MemoCreate{
|
|
|
|
CreatorId: userId,
|
|
|
|
CreatorID: userID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
|
|
|
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request").SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request").SetInternal(err)
|
|
|
@ -35,13 +35,13 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
g.PATCH("/memo/:memoId", func(c echo.Context) error {
|
|
|
|
g.PATCH("/memo/:memoId", func(c echo.Context) error {
|
|
|
|
memoId, err := strconv.Atoi(c.Param("memoId"))
|
|
|
|
memoID, err := strconv.Atoi(c.Param("memoId"))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memoPatch := &api.MemoPatch{
|
|
|
|
memoPatch := &api.MemoPatch{
|
|
|
|
Id: memoId,
|
|
|
|
ID: memoID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := json.NewDecoder(c.Request().Body).Decode(memoPatch); err != nil {
|
|
|
|
if err := json.NewDecoder(c.Request().Body).Decode(memoPatch); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch memo request").SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch memo request").SetInternal(err)
|
|
|
@ -61,9 +61,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
g.GET("/memo", func(c echo.Context) error {
|
|
|
|
g.GET("/memo", func(c echo.Context) error {
|
|
|
|
userId := c.Get(getUserIdContextKey()).(int)
|
|
|
|
userID := c.Get(getUserIDContextKey()).(int)
|
|
|
|
memoFind := &api.MemoFind{
|
|
|
|
memoFind := &api.MemoFind{
|
|
|
|
CreatorId: &userId,
|
|
|
|
CreatorID: &userID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rowStatus := c.QueryParam("rowStatus")
|
|
|
|
rowStatus := c.QueryParam("rowStatus")
|
|
|
|
if rowStatus != "" {
|
|
|
|
if rowStatus != "" {
|
|
|
@ -84,21 +84,21 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
g.GET("/memo/:memoId", func(c echo.Context) error {
|
|
|
|
g.GET("/memo/:memoId", func(c echo.Context) error {
|
|
|
|
memoId, err := strconv.Atoi(c.Param("memoId"))
|
|
|
|
memoID, err := strconv.Atoi(c.Param("memoId"))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memoFind := &api.MemoFind{
|
|
|
|
memoFind := &api.MemoFind{
|
|
|
|
Id: &memoId,
|
|
|
|
ID: &memoID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memo, err := s.MemoService.FindMemo(memoFind)
|
|
|
|
memo, err := s.MemoService.FindMemo(memoFind)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if common.ErrorCode(err) == common.NotFound {
|
|
|
|
if common.ErrorCode(err) == common.NotFound {
|
|
|
|
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Memo ID not found: %d", memoId)).SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Memo ID not found: %d", memoID)).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete memo ID: %v", memoId)).SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find memo by ID: %v", memoID)).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
|
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
|
|
@ -110,18 +110,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
g.DELETE("/memo/:memoId", func(c echo.Context) error {
|
|
|
|
g.DELETE("/memo/:memoId", func(c echo.Context) error {
|
|
|
|
memoId, err := strconv.Atoi(c.Param("memoId"))
|
|
|
|
memoID, err := strconv.Atoi(c.Param("memoId"))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memoDelete := &api.MemoDelete{
|
|
|
|
memoDelete := &api.MemoDelete{
|
|
|
|
Id: &memoId,
|
|
|
|
ID: &memoID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = s.MemoService.DeleteMemo(memoDelete)
|
|
|
|
err = s.MemoService.DeleteMemo(memoDelete)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete memo ID: %v", memoId)).SetInternal(err)
|
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete memo ID: %v", memoID)).SetInternal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, true)
|
|
|
|
c.JSON(http.StatusOK, true)
|
|
|
|