mirror of
https://github.com/usememos/memos.git
synced 2024-12-26 23:22:47 +08:00
chore: typo Id
to ID
This commit is contained in:
parent
13093b6f62
commit
d947a512e6
15 changed files with 143 additions and 142 deletions
14
api/memo.go
14
api/memo.go
|
@ -1,23 +1,23 @@
|
|||
package api
|
||||
|
||||
type Memo struct {
|
||||
Id int `json:"id"`
|
||||
ID int `json:"id"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
RowStatus string `json:"rowStatus"`
|
||||
|
||||
Content string `json:"content"`
|
||||
CreatorId int `json:"creatorId"`
|
||||
CreatorID int `json:"creatorId"`
|
||||
}
|
||||
|
||||
type MemoCreate struct {
|
||||
CreatorId int
|
||||
CreatorID int
|
||||
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type MemoPatch struct {
|
||||
Id int
|
||||
ID int
|
||||
|
||||
Content *string `json:"content"`
|
||||
RowStatus *string `json:"rowStatus"`
|
||||
|
@ -25,13 +25,13 @@ type MemoPatch struct {
|
|||
}
|
||||
|
||||
type MemoFind struct {
|
||||
Id *int `json:"id"`
|
||||
CreatorId *int `json:"creatorId"`
|
||||
ID *int `json:"id"`
|
||||
CreatorID *int `json:"creatorId"`
|
||||
RowStatus *string `json:"rowStatus"`
|
||||
}
|
||||
|
||||
type MemoDelete struct {
|
||||
Id *int `json:"id"`
|
||||
ID *int `json:"id"`
|
||||
}
|
||||
|
||||
type MemoService interface {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package api
|
||||
|
||||
type Resource struct {
|
||||
Id int `json:"id"`
|
||||
ID int `json:"id"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
|
||||
|
@ -10,7 +10,7 @@ type Resource struct {
|
|||
Type string `json:"type"`
|
||||
Size int64 `json:"size"`
|
||||
|
||||
CreatorId int `json:"creatorId"`
|
||||
CreatorID int `json:"creatorId"`
|
||||
}
|
||||
|
||||
type ResourceCreate struct {
|
||||
|
@ -19,17 +19,17 @@ type ResourceCreate struct {
|
|||
Type string `json:"type"`
|
||||
Size int64 `json:"size"`
|
||||
|
||||
CreatorId int
|
||||
CreatorID int
|
||||
}
|
||||
|
||||
type ResourceFind struct {
|
||||
Id *int `json:"id"`
|
||||
CreatorId *int `json:"creatorId"`
|
||||
ID *int `json:"id"`
|
||||
CreatorID *int `json:"creatorId"`
|
||||
Filename *string `json:"filename"`
|
||||
}
|
||||
|
||||
type ResourceDelete struct {
|
||||
Id int
|
||||
ID int
|
||||
}
|
||||
|
||||
type ResourceService interface {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package api
|
||||
|
||||
type Shortcut struct {
|
||||
Id int `json:"id"`
|
||||
ID int `json:"id"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
|
||||
Title string `json:"title"`
|
||||
Payload string `json:"payload"`
|
||||
RowStatus string `json:"rowStatus"`
|
||||
CreatorId int
|
||||
CreatorID int
|
||||
}
|
||||
|
||||
type ShortcutCreate struct {
|
||||
// Standard fields
|
||||
CreatorId int
|
||||
CreatorID int
|
||||
|
||||
// Domain specific fields
|
||||
Title string `json:"title"`
|
||||
|
@ -21,7 +21,7 @@ type ShortcutCreate struct {
|
|||
}
|
||||
|
||||
type ShortcutPatch struct {
|
||||
Id int
|
||||
ID int
|
||||
|
||||
Title *string `json:"title"`
|
||||
Payload *string `json:"payload"`
|
||||
|
@ -29,17 +29,17 @@ type ShortcutPatch struct {
|
|||
}
|
||||
|
||||
type ShortcutFind struct {
|
||||
Id *int
|
||||
ID *int
|
||||
|
||||
// Standard fields
|
||||
CreatorId *int
|
||||
CreatorID *int
|
||||
|
||||
// Domain specific fields
|
||||
Title *string `json:"title"`
|
||||
}
|
||||
|
||||
type ShortcutDelete struct {
|
||||
Id int
|
||||
ID int
|
||||
}
|
||||
|
||||
type ShortcutService interface {
|
||||
|
|
16
api/user.go
16
api/user.go
|
@ -1,37 +1,37 @@
|
|||
package api
|
||||
|
||||
type User struct {
|
||||
Id int `json:"id"`
|
||||
ID int `json:"id"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
|
||||
OpenId string `json:"openId"`
|
||||
OpenID string `json:"openId"`
|
||||
Name string `json:"name"`
|
||||
PasswordHash string `json:"-"`
|
||||
}
|
||||
|
||||
type UserCreate struct {
|
||||
OpenId string
|
||||
OpenID string
|
||||
Name string
|
||||
PasswordHash string
|
||||
}
|
||||
|
||||
type UserPatch struct {
|
||||
Id int
|
||||
ID int
|
||||
|
||||
OpenId *string
|
||||
OpenID *string
|
||||
PasswordHash *string
|
||||
|
||||
Name *string `json:"name"`
|
||||
Password *string `json:"password"`
|
||||
ResetOpenId *bool `json:"resetOpenId"`
|
||||
ResetOpenID *bool `json:"resetOpenId"`
|
||||
}
|
||||
|
||||
type UserFind struct {
|
||||
Id *int `json:"id"`
|
||||
ID *int `json:"id"`
|
||||
|
||||
Name *string `json:"name"`
|
||||
OpenId *string
|
||||
OpenID *string
|
||||
}
|
||||
|
||||
type UserRenameCheck struct {
|
||||
|
|
|
@ -91,7 +91,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
|||
userCreate := &api.UserCreate{
|
||||
Name: signup.Name,
|
||||
PasswordHash: string(passwordHash),
|
||||
OpenId: common.GenUUID(),
|
||||
OpenID: common.GenUUID(),
|
||||
}
|
||||
user, err = s.UserService.CreateUser(userCreate)
|
||||
if err != nil {
|
||||
|
|
|
@ -13,11 +13,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
userIdContextKey = "user-id"
|
||||
userIDContextKey = "user-id"
|
||||
)
|
||||
|
||||
func getUserIdContextKey() string {
|
||||
return userIdContextKey
|
||||
func getUserIDContextKey() string {
|
||||
return userIDContextKey
|
||||
}
|
||||
|
||||
func setUserSession(c echo.Context, user *api.User) error {
|
||||
|
@ -27,7 +27,7 @@ func setUserSession(c echo.Context, user *api.User) error {
|
|||
MaxAge: 1000 * 3600 * 24 * 30,
|
||||
HttpOnly: true,
|
||||
}
|
||||
sess.Values[userIdContextKey] = user.Id
|
||||
sess.Values[userIDContextKey] = user.ID
|
||||
err := sess.Save(c.Request(), c.Response())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set session, err: %w", err)
|
||||
|
@ -43,7 +43,7 @@ func removeUserSession(c echo.Context) error {
|
|||
MaxAge: 0,
|
||||
HttpOnly: true,
|
||||
}
|
||||
sess.Values[userIdContextKey] = nil
|
||||
sess.Values[userIDContextKey] = nil
|
||||
err := sess.Save(c.Request(), c.Response())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set session, err: %w", err)
|
||||
|
@ -65,30 +65,30 @@ func BasicAuthMiddleware(us api.UserService, next echo.HandlerFunc) echo.Handler
|
|||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing session").SetInternal(err)
|
||||
}
|
||||
|
||||
userIdValue := sess.Values[userIdContextKey]
|
||||
if userIdValue == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing userId in session")
|
||||
userIDValue := sess.Values[userIDContextKey]
|
||||
if userIDValue == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing userID in session")
|
||||
}
|
||||
|
||||
userId, err := strconv.Atoi(fmt.Sprintf("%v", userIdValue))
|
||||
userID, err := strconv.Atoi(fmt.Sprintf("%v", userIDValue))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to malformatted user id in the session.").SetInternal(err)
|
||||
}
|
||||
|
||||
// Even if there is no error, we still need to make sure the user still exists.
|
||||
userFind := &api.UserFind{
|
||||
Id: &userId,
|
||||
ID: &userID,
|
||||
}
|
||||
user, err := us.FindUser(userFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by ID: %d", userId)).SetInternal(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by ID: %d", userID)).SetInternal(err)
|
||||
}
|
||||
if user == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Not found user ID: %d", userId))
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Not found user ID: %d", userID))
|
||||
}
|
||||
|
||||
// Stores userId into context.
|
||||
c.Set(getUserIdContextKey(), userId)
|
||||
// Stores userID into context.
|
||||
c.Set(getUserIDContextKey(), userID)
|
||||
|
||||
return next(c)
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import (
|
|||
|
||||
func (s *Server) registerMemoRoutes(g *echo.Group) {
|
||||
g.POST("/memo", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
memoCreate := &api.MemoCreate{
|
||||
CreatorId: userId,
|
||||
CreatorID: userID,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
||||
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 {
|
||||
memoId, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
memoPatch := &api.MemoPatch{
|
||||
Id: memoId,
|
||||
ID: memoID,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(memoPatch); err != nil {
|
||||
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 {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
memoFind := &api.MemoFind{
|
||||
CreatorId: &userId,
|
||||
CreatorID: &userID,
|
||||
}
|
||||
rowStatus := c.QueryParam("rowStatus")
|
||||
if rowStatus != "" {
|
||||
|
@ -84,21 +84,21 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
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 {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
memoFind := &api.MemoFind{
|
||||
Id: &memoId,
|
||||
ID: &memoID,
|
||||
}
|
||||
memo, err := s.MemoService.FindMemo(memoFind)
|
||||
if err != nil {
|
||||
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)
|
||||
|
@ -110,18 +110,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
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 {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
memoDelete := &api.MemoDelete{
|
||||
Id: &memoId,
|
||||
ID: &memoID,
|
||||
}
|
||||
|
||||
err = s.MemoService.DeleteMemo(memoDelete)
|
||||
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)
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
func (s *Server) registerResourceRoutes(g *echo.Group) {
|
||||
g.POST("/resource", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
|
||||
err := c.Request().ParseMultipartForm(5 << 20)
|
||||
if err != nil {
|
||||
|
@ -44,7 +44,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||
Type: filetype,
|
||||
Size: size,
|
||||
Blob: fileBytes,
|
||||
CreatorId: userId,
|
||||
CreatorID: userID,
|
||||
}
|
||||
|
||||
resource, err := s.ResourceService.CreateResource(resourceCreate)
|
||||
|
@ -54,16 +54,16 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(resource)); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode shortcut response").SetInternal(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode resource response").SetInternal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
g.GET("/resource", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
resourceFind := &api.ResourceFind{
|
||||
CreatorId: &userId,
|
||||
CreatorID: &userID,
|
||||
}
|
||||
list, err := s.ResourceService.FindResourceList(resourceFind)
|
||||
if err != nil {
|
||||
|
@ -79,13 +79,13 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.DELETE("/resource/:resourceId", func(c echo.Context) error {
|
||||
resourceId, err := strconv.Atoi(c.Param("resourceId"))
|
||||
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
resourceDelete := &api.ResourceDelete{
|
||||
Id: resourceId,
|
||||
ID: resourceID,
|
||||
}
|
||||
if err := s.ResourceService.DeleteResource(resourceDelete); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete resource").SetInternal(err)
|
||||
|
|
|
@ -12,9 +12,9 @@ import (
|
|||
|
||||
func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
||||
g.POST("/shortcut", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
shortcutCreate := &api.ShortcutCreate{
|
||||
CreatorId: userId,
|
||||
CreatorID: userID,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(shortcutCreate); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post shortcut request").SetInternal(err)
|
||||
|
@ -34,13 +34,13 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.PATCH("/shortcut/:shortcutId", func(c echo.Context) error {
|
||||
shortcutId, err := strconv.Atoi(c.Param("shortcutId"))
|
||||
shortcutID, err := strconv.Atoi(c.Param("shortcutId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("shortcutId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
shortcutPatch := &api.ShortcutPatch{
|
||||
Id: shortcutId,
|
||||
ID: shortcutID,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(shortcutPatch); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch shortcut request").SetInternal(err)
|
||||
|
@ -60,9 +60,9 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.GET("/shortcut", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
shortcutFind := &api.ShortcutFind{
|
||||
CreatorId: &userId,
|
||||
CreatorID: &userID,
|
||||
}
|
||||
list, err := s.ShortcutService.FindShortcutList(shortcutFind)
|
||||
if err != nil {
|
||||
|
@ -78,17 +78,17 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.GET("/shortcut/:shortcutId", func(c echo.Context) error {
|
||||
shortcutId, err := strconv.Atoi(c.Param("shortcutId"))
|
||||
shortcutID, err := strconv.Atoi(c.Param("shortcutId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("shortcutId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
shortcutFind := &api.ShortcutFind{
|
||||
Id: &shortcutId,
|
||||
ID: &shortcutID,
|
||||
}
|
||||
shortcut, err := s.ShortcutService.FindShortcut(shortcutFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch shortcut").SetInternal(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch shortcut by ID %d", *shortcutFind.ID)).SetInternal(err)
|
||||
}
|
||||
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||
|
@ -100,13 +100,13 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.DELETE("/shortcut/:shortcutId", func(c echo.Context) error {
|
||||
shortcutId, err := strconv.Atoi(c.Param("shortcutId"))
|
||||
shortcutID, err := strconv.Atoi(c.Param("shortcutId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("shortcutId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
shortcutDelete := &api.ShortcutDelete{
|
||||
Id: shortcutId,
|
||||
ID: shortcutID,
|
||||
}
|
||||
if err := s.ShortcutService.DeleteShortcut(shortcutDelete); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete shortcut").SetInternal(err)
|
||||
|
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"memos/api"
|
||||
"memos/common"
|
||||
"net/http"
|
||||
|
@ -13,14 +14,14 @@ import (
|
|||
func (s *Server) registerUserRoutes(g *echo.Group) {
|
||||
// GET /api/user/me is used to check if the user is logged in.
|
||||
g.GET("/user/me", func(c echo.Context) error {
|
||||
userSessionId := c.Get(getUserIdContextKey())
|
||||
if userSessionId == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing session")
|
||||
userSessionID := c.Get(getUserIDContextKey())
|
||||
if userSessionID == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing auth session")
|
||||
}
|
||||
|
||||
userId := userSessionId.(int)
|
||||
userID := userSessionID.(int)
|
||||
userFind := &api.UserFind{
|
||||
Id: &userId,
|
||||
ID: &userID,
|
||||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
if err != nil {
|
||||
|
@ -42,7 +43,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
|||
}
|
||||
|
||||
if userRenameCheck.Name == "" {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user rename check request")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "New name needed")
|
||||
}
|
||||
|
||||
userFind := &api.UserFind{
|
||||
|
@ -50,7 +51,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
|||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by name %s", *userFind.Name)).SetInternal(err)
|
||||
}
|
||||
|
||||
isUsable := true
|
||||
|
@ -67,22 +68,22 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.POST("/user/password_check", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
userPasswordCheck := &api.UserPasswordCheck{}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(userPasswordCheck); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user password check request").SetInternal(err)
|
||||
}
|
||||
|
||||
if userPasswordCheck.Password == "" {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post user password check request")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Password needed")
|
||||
}
|
||||
|
||||
userFind := &api.UserFind{
|
||||
Id: &userId,
|
||||
ID: &userID,
|
||||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user by password").SetInternal(err)
|
||||
}
|
||||
|
||||
isValid := false
|
||||
|
@ -100,17 +101,17 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.PATCH("/user/me", func(c echo.Context) error {
|
||||
userId := c.Get(getUserIdContextKey()).(int)
|
||||
userID := c.Get(getUserIDContextKey()).(int)
|
||||
userPatch := &api.UserPatch{
|
||||
Id: userId,
|
||||
ID: userID,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(userPatch); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch user request").SetInternal(err)
|
||||
}
|
||||
|
||||
if userPatch.ResetOpenId != nil && *userPatch.ResetOpenId {
|
||||
openId := common.GenUUID()
|
||||
userPatch.OpenId = &openId
|
||||
if userPatch.ResetOpenID != nil && *userPatch.ResetOpenID {
|
||||
openID := common.GenUUID()
|
||||
userPatch.OpenID = &openID
|
||||
}
|
||||
|
||||
if userPatch.Password != nil && *userPatch.Password != "" {
|
||||
|
|
|
@ -16,21 +16,21 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.POST("/:openId/memo", func(c echo.Context) error {
|
||||
openId := c.Param("openId")
|
||||
openID := c.Param("openId")
|
||||
|
||||
userFind := &api.UserFind{
|
||||
OpenId: &openId,
|
||||
OpenID: &openID,
|
||||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user by open_id").SetInternal(err)
|
||||
}
|
||||
if user == nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("User openId not found: %s", openId))
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("User openId not found: %s", openID))
|
||||
}
|
||||
|
||||
memoCreate := &api.MemoCreate{
|
||||
CreatorId: user.Id,
|
||||
CreatorID: user.ID,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request by open api").SetInternal(err)
|
||||
|
@ -50,21 +50,21 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.GET("/:openId/memo", func(c echo.Context) error {
|
||||
openId := c.Param("openId")
|
||||
openID := c.Param("openId")
|
||||
|
||||
userFind := &api.UserFind{
|
||||
OpenId: &openId,
|
||||
OpenID: &openID,
|
||||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user by open_id").SetInternal(err)
|
||||
}
|
||||
if user == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Unauthorized: %s", openId))
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Unauthorized: %s", openID))
|
||||
}
|
||||
|
||||
memoFind := &api.MemoFind{
|
||||
CreatorId: &user.Id,
|
||||
CreatorID: &user.ID,
|
||||
}
|
||||
rowStatus := c.QueryParam("rowStatus")
|
||||
if rowStatus != "" {
|
||||
|
@ -85,7 +85,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
|||
})
|
||||
|
||||
g.GET("/r/:resourceId/:filename", func(c echo.Context) error {
|
||||
resourceId, err := strconv.Atoi(c.Param("resourceId"))
|
||||
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
|
@ -93,13 +93,13 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
|||
filename := c.Param("filename")
|
||||
|
||||
resourceFind := &api.ResourceFind{
|
||||
Id: &resourceId,
|
||||
ID: &resourceID,
|
||||
Filename: &filename,
|
||||
}
|
||||
|
||||
resource, err := s.ResourceService.FindResource(resourceFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch resource ID: %v", resourceId)).SetInternal(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch resource ID: %v", resourceID)).SetInternal(err)
|
||||
}
|
||||
|
||||
c.Response().Writer.WriteHeader(http.StatusOK)
|
||||
|
|
|
@ -73,7 +73,7 @@ func createMemo(db *DB, create *api.MemoCreate) (*api.Memo, error) {
|
|||
VALUES (?, ?)
|
||||
RETURNING id, creator_id, created_ts, updated_ts, content, row_status
|
||||
`,
|
||||
create.CreatorId,
|
||||
create.CreatorID,
|
||||
create.Content,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -87,8 +87,8 @@ func createMemo(db *DB, create *api.MemoCreate) (*api.Memo, error) {
|
|||
|
||||
var memo api.Memo
|
||||
if err := row.Scan(
|
||||
&memo.Id,
|
||||
&memo.CreatorId,
|
||||
&memo.ID,
|
||||
&memo.CreatorID,
|
||||
&memo.CreatedTs,
|
||||
&memo.UpdatedTs,
|
||||
&memo.Content,
|
||||
|
@ -113,7 +113,7 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
|
|||
set, args = append(set, "created_ts = ?"), append(args, *v)
|
||||
}
|
||||
|
||||
args = append(args, patch.Id)
|
||||
args = append(args, patch.ID)
|
||||
|
||||
row, err := db.Db.Query(`
|
||||
UPDATE memo
|
||||
|
@ -132,7 +132,7 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
|
|||
|
||||
var memo api.Memo
|
||||
if err := row.Scan(
|
||||
&memo.Id,
|
||||
&memo.ID,
|
||||
&memo.CreatedTs,
|
||||
&memo.UpdatedTs,
|
||||
&memo.Content,
|
||||
|
@ -147,10 +147,10 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
|
|||
func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
|
||||
where, args := []string{"1 = 1"}, []interface{}{}
|
||||
|
||||
if v := find.Id; v != nil {
|
||||
if v := find.ID; v != nil {
|
||||
where, args = append(where, "id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.CreatorId; v != nil {
|
||||
if v := find.CreatorID; v != nil {
|
||||
where, args = append(where, "creator_id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.RowStatus; v != nil {
|
||||
|
@ -178,8 +178,8 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
|
|||
for rows.Next() {
|
||||
var memo api.Memo
|
||||
if err := rows.Scan(
|
||||
&memo.Id,
|
||||
&memo.CreatorId,
|
||||
&memo.ID,
|
||||
&memo.CreatorID,
|
||||
&memo.CreatedTs,
|
||||
&memo.UpdatedTs,
|
||||
&memo.Content,
|
||||
|
@ -199,14 +199,14 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
|
|||
}
|
||||
|
||||
func deleteMemo(db *DB, delete *api.MemoDelete) error {
|
||||
result, err := db.Db.Exec(`DELETE FROM memo WHERE id = ?`, delete.Id)
|
||||
result, err := db.Db.Exec(`DELETE FROM memo WHERE id = ?`, delete.ID)
|
||||
if err != nil {
|
||||
return FormatError(err)
|
||||
}
|
||||
|
||||
rows, _ := result.RowsAffected()
|
||||
if rows == 0 {
|
||||
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("memo ID not found: %d", delete.Id)}
|
||||
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("memo ID not found: %d", delete.ID)}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -71,7 +71,7 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
|
|||
create.Blob,
|
||||
create.Type,
|
||||
create.Size,
|
||||
create.CreatorId,
|
||||
create.CreatorID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, FormatError(err)
|
||||
|
@ -84,7 +84,7 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
|
|||
|
||||
var resource api.Resource
|
||||
if err := row.Scan(
|
||||
&resource.Id,
|
||||
&resource.ID,
|
||||
&resource.Filename,
|
||||
&resource.Blob,
|
||||
&resource.Type,
|
||||
|
@ -101,10 +101,10 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
|
|||
func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
|
||||
where, args := []string{"1 = 1"}, []interface{}{}
|
||||
|
||||
if v := find.Id; v != nil {
|
||||
if v := find.ID; v != nil {
|
||||
where, args = append(where, "id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.CreatorId; v != nil {
|
||||
if v := find.CreatorID; v != nil {
|
||||
where, args = append(where, "creator_id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.Filename; v != nil {
|
||||
|
@ -133,7 +133,7 @@ func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
|
|||
for rows.Next() {
|
||||
var resource api.Resource
|
||||
if err := rows.Scan(
|
||||
&resource.Id,
|
||||
&resource.ID,
|
||||
&resource.Filename,
|
||||
&resource.Blob,
|
||||
&resource.Type,
|
||||
|
@ -155,14 +155,14 @@ func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
|
|||
}
|
||||
|
||||
func deleteResource(db *DB, delete *api.ResourceDelete) error {
|
||||
result, err := db.Db.Exec(`DELETE FROM resource WHERE id = ?`, delete.Id)
|
||||
result, err := db.Db.Exec(`DELETE FROM resource WHERE id = ?`, delete.ID)
|
||||
if err != nil {
|
||||
return FormatError(err)
|
||||
}
|
||||
|
||||
rows, _ := result.RowsAffected()
|
||||
if rows == 0 {
|
||||
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("resource ID not found: %d", delete.Id)}
|
||||
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("resource ID not found: %d", delete.ID)}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -76,7 +76,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
|
|||
`,
|
||||
create.Title,
|
||||
create.Payload,
|
||||
create.CreatorId,
|
||||
create.CreatorID,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -87,10 +87,10 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
|
|||
row.Next()
|
||||
var shortcut api.Shortcut
|
||||
if err := row.Scan(
|
||||
&shortcut.Id,
|
||||
&shortcut.ID,
|
||||
&shortcut.Title,
|
||||
&shortcut.Payload,
|
||||
&shortcut.CreatorId,
|
||||
&shortcut.CreatorID,
|
||||
&shortcut.CreatedTs,
|
||||
&shortcut.UpdatedTs,
|
||||
&shortcut.RowStatus,
|
||||
|
@ -114,7 +114,7 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
|
|||
set, args = append(set, "row_status = ?"), append(args, *v)
|
||||
}
|
||||
|
||||
args = append(args, patch.Id)
|
||||
args = append(args, patch.ID)
|
||||
|
||||
row, err := db.Db.Query(`
|
||||
UPDATE shortcut
|
||||
|
@ -133,7 +133,7 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
|
|||
|
||||
var shortcut api.Shortcut
|
||||
if err := row.Scan(
|
||||
&shortcut.Id,
|
||||
&shortcut.ID,
|
||||
&shortcut.Title,
|
||||
&shortcut.Payload,
|
||||
&shortcut.CreatedTs,
|
||||
|
@ -149,10 +149,10 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
|
|||
func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
|
||||
where, args := []string{"1 = 1"}, []interface{}{}
|
||||
|
||||
if v := find.Id; v != nil {
|
||||
if v := find.ID; v != nil {
|
||||
where, args = append(where, "id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.CreatorId; v != nil {
|
||||
if v := find.CreatorID; v != nil {
|
||||
where, args = append(where, "creator_id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.Title; v != nil {
|
||||
|
@ -181,10 +181,10 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
|
|||
for rows.Next() {
|
||||
var shortcut api.Shortcut
|
||||
if err := rows.Scan(
|
||||
&shortcut.Id,
|
||||
&shortcut.ID,
|
||||
&shortcut.Title,
|
||||
&shortcut.Payload,
|
||||
&shortcut.CreatorId,
|
||||
&shortcut.CreatorID,
|
||||
&shortcut.CreatedTs,
|
||||
&shortcut.UpdatedTs,
|
||||
&shortcut.RowStatus,
|
||||
|
@ -203,14 +203,14 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
|
|||
}
|
||||
|
||||
func deleteShortcut(db *DB, delete *api.ShortcutDelete) error {
|
||||
result, err := db.Db.Exec(`DELETE FROM shortcut WHERE id = ?`, delete.Id)
|
||||
result, err := db.Db.Exec(`DELETE FROM shortcut WHERE id = ?`, delete.ID)
|
||||
if err != nil {
|
||||
return FormatError(err)
|
||||
}
|
||||
|
||||
rows, _ := result.RowsAffected()
|
||||
if rows == 0 {
|
||||
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("shortcut ID not found: %d", delete.Id)}
|
||||
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("shortcut ID not found: %d", delete.ID)}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -60,7 +60,7 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
|
|||
`,
|
||||
create.Name,
|
||||
create.PasswordHash,
|
||||
create.OpenId,
|
||||
create.OpenID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, FormatError(err)
|
||||
|
@ -70,10 +70,10 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
|
|||
row.Next()
|
||||
var user api.User
|
||||
if err := row.Scan(
|
||||
&user.Id,
|
||||
&user.ID,
|
||||
&user.Name,
|
||||
&user.PasswordHash,
|
||||
&user.OpenId,
|
||||
&user.OpenID,
|
||||
&user.CreatedTs,
|
||||
&user.UpdatedTs,
|
||||
); err != nil {
|
||||
|
@ -92,11 +92,11 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
|
|||
if v := patch.PasswordHash; v != nil {
|
||||
set, args = append(set, "password_hash = ?"), append(args, v)
|
||||
}
|
||||
if v := patch.OpenId; v != nil {
|
||||
if v := patch.OpenID; v != nil {
|
||||
set, args = append(set, "open_id = ?"), append(args, v)
|
||||
}
|
||||
|
||||
args = append(args, patch.Id)
|
||||
args = append(args, patch.ID)
|
||||
|
||||
row, err := db.Db.Query(`
|
||||
UPDATE user
|
||||
|
@ -112,10 +112,10 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
|
|||
if row.Next() {
|
||||
var user api.User
|
||||
if err := row.Scan(
|
||||
&user.Id,
|
||||
&user.ID,
|
||||
&user.Name,
|
||||
&user.PasswordHash,
|
||||
&user.OpenId,
|
||||
&user.OpenID,
|
||||
&user.CreatedTs,
|
||||
&user.UpdatedTs,
|
||||
); err != nil {
|
||||
|
@ -125,19 +125,19 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
|
|||
return &user, nil
|
||||
}
|
||||
|
||||
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("user ID not found: %d", patch.Id)}
|
||||
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("user ID not found: %d", patch.ID)}
|
||||
}
|
||||
|
||||
func findUserList(db *DB, find *api.UserFind) ([]*api.User, error) {
|
||||
where, args := []string{"1 = 1"}, []interface{}{}
|
||||
|
||||
if v := find.Id; v != nil {
|
||||
if v := find.ID; v != nil {
|
||||
where, args = append(where, "id = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.Name; v != nil {
|
||||
where, args = append(where, "name = ?"), append(args, *v)
|
||||
}
|
||||
if v := find.OpenId; v != nil {
|
||||
if v := find.OpenID; v != nil {
|
||||
where, args = append(where, "open_id = ?"), append(args, *v)
|
||||
}
|
||||
|
||||
|
@ -162,10 +162,10 @@ func findUserList(db *DB, find *api.UserFind) ([]*api.User, error) {
|
|||
for rows.Next() {
|
||||
var user api.User
|
||||
if err := rows.Scan(
|
||||
&user.Id,
|
||||
&user.ID,
|
||||
&user.Name,
|
||||
&user.PasswordHash,
|
||||
&user.OpenId,
|
||||
&user.OpenID,
|
||||
&user.CreatedTs,
|
||||
&user.UpdatedTs,
|
||||
); err != nil {
|
||||
|
|
Loading…
Reference in a new issue