mirror of
https://github.com/usememos/memos.git
synced 2025-01-02 19:23:30 +03:00
chore: update id type to int32 (#2076)
This commit is contained in:
parent
cbe27923b3
commit
7c5296cf35
@ -71,13 +71,13 @@ func (l ActivityLevel) String() string {
|
||||
}
|
||||
|
||||
type ActivityUserCreatePayload struct {
|
||||
UserID int `json:"userId"`
|
||||
UserID int32 `json:"userId"`
|
||||
Username string `json:"username"`
|
||||
Role Role `json:"role"`
|
||||
}
|
||||
|
||||
type ActivityUserAuthSignInPayload struct {
|
||||
UserID int `json:"userId"`
|
||||
UserID int32 `json:"userId"`
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
|
||||
@ -107,10 +107,10 @@ type ActivityServerStartPayload struct {
|
||||
}
|
||||
|
||||
type Activity struct {
|
||||
ID int `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
|
||||
// Standard fields
|
||||
CreatorID int `json:"creatorId"`
|
||||
CreatorID int32 `json:"creatorId"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
|
||||
// Domain specific fields
|
||||
@ -122,7 +122,7 @@ type Activity struct {
|
||||
// ActivityCreate is the API message for creating an activity.
|
||||
type ActivityCreate struct {
|
||||
// Standard fields
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
|
||||
// Domain specific fields
|
||||
Type ActivityType `json:"type"`
|
||||
|
@ -21,7 +21,7 @@ type SignIn struct {
|
||||
}
|
||||
|
||||
type SSOSignIn struct {
|
||||
IdentityProviderID int `json:"identityProviderId"`
|
||||
IdentityProviderID int32 `json:"identityProviderId"`
|
||||
Code string `json:"code"`
|
||||
RedirectURI string `json:"redirectUri"`
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/usememos/memos/api/auth"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
@ -42,7 +42,7 @@ type FieldMapping struct {
|
||||
}
|
||||
|
||||
type IdentityProvider struct {
|
||||
ID int `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type IdentityProviderType `json:"type"`
|
||||
IdentifierFilter string `json:"identifierFilter"`
|
||||
@ -57,7 +57,7 @@ type CreateIdentityProviderRequest struct {
|
||||
}
|
||||
|
||||
type UpdateIdentityProviderRequest struct {
|
||||
ID int `json:"-"`
|
||||
ID int32 `json:"-"`
|
||||
Type IdentityProviderType `json:"type"`
|
||||
Name *string `json:"name"`
|
||||
IdentifierFilter *string `json:"identifierFilter"`
|
||||
@ -67,7 +67,7 @@ type UpdateIdentityProviderRequest struct {
|
||||
func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
g.POST("/idp", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -101,7 +101,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
|
||||
g.PATCH("/idp/:idpId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -116,7 +116,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
||||
}
|
||||
|
||||
identityProviderID, err := strconv.Atoi(c.Param("idpId"))
|
||||
identityProviderID, err := util.ConvertStringToInt32(c.Param("idpId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("idpId"))).SetInternal(err)
|
||||
}
|
||||
@ -148,7 +148,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find identity provider list").SetInternal(err)
|
||||
}
|
||||
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
isHostUser := false
|
||||
if ok {
|
||||
user, err := s.Store.GetUser(ctx, &store.FindUser{
|
||||
@ -176,7 +176,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/idp/:idpId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
||||
}
|
||||
|
||||
identityProviderID, err := strconv.Atoi(c.Param("idpId"))
|
||||
identityProviderID, err := util.ConvertStringToInt32(c.Param("idpId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("idpId"))).SetInternal(err)
|
||||
}
|
||||
@ -210,7 +210,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
|
||||
g.DELETE("/idp/:idpId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -225,7 +225,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
||||
}
|
||||
|
||||
identityProviderID, err := strconv.Atoi(c.Param("idpId"))
|
||||
identityProviderID, err := util.ConvertStringToInt32(c.Param("idpId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("idpId"))).SetInternal(err)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package v1
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -21,7 +20,7 @@ type claimsMessage struct {
|
||||
}
|
||||
|
||||
// GenerateAccessToken generates an access token for web.
|
||||
func GenerateAccessToken(username string, userID int, secret string) (string, error) {
|
||||
func GenerateAccessToken(username string, userID int32, secret string) (string, error) {
|
||||
expirationTime := time.Now().Add(auth.AccessTokenDuration)
|
||||
return generateToken(username, userID, auth.AccessTokenAudienceName, expirationTime, []byte(secret))
|
||||
}
|
||||
@ -58,7 +57,7 @@ func setTokenCookie(c echo.Context, name, token string, expiration time.Time) {
|
||||
}
|
||||
|
||||
// generateToken generates a jwt token.
|
||||
func generateToken(username string, userID int, aud string, expirationTime time.Time, secret []byte) (string, error) {
|
||||
func generateToken(username string, userID int32, aud string, expirationTime time.Time, secret []byte) (string, error) {
|
||||
// Create the JWT claims, which includes the username and expiry time.
|
||||
claims := &claimsMessage{
|
||||
Name: username,
|
||||
@ -68,7 +67,7 @@ func generateToken(username string, userID int, aud string, expirationTime time.
|
||||
ExpiresAt: jwt.NewNumericDate(expirationTime),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
Issuer: auth.Issuer,
|
||||
Subject: strconv.Itoa(userID),
|
||||
Subject: fmt.Sprintf("%d", userID),
|
||||
},
|
||||
}
|
||||
|
||||
@ -174,7 +173,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
|
||||
}
|
||||
|
||||
// We either have a valid access token or we will attempt to generate new access token and refresh token
|
||||
userID, err := strconv.Atoi(claims.Subject)
|
||||
userID, err := util.ConvertStringToInt32(claims.Subject)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Malformed ID in the token.")
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/usememos/memos/api/auth"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
@ -39,11 +40,11 @@ func (v Visibility) String() string {
|
||||
}
|
||||
|
||||
type Memo struct {
|
||||
ID int `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
|
||||
// Standard fields
|
||||
RowStatus RowStatus `json:"rowStatus"`
|
||||
CreatorID int `json:"creatorId"`
|
||||
CreatorID int32 `json:"creatorId"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
|
||||
@ -62,7 +63,7 @@ type Memo struct {
|
||||
|
||||
type CreateMemoRequest struct {
|
||||
// Standard fields
|
||||
CreatorID int `json:"-"`
|
||||
CreatorID int32 `json:"-"`
|
||||
CreatedTs *int64 `json:"createdTs"`
|
||||
|
||||
// Domain specific fields
|
||||
@ -70,12 +71,12 @@ type CreateMemoRequest struct {
|
||||
Content string `json:"content"`
|
||||
|
||||
// Related fields
|
||||
ResourceIDList []int `json:"resourceIdList"`
|
||||
ResourceIDList []int32 `json:"resourceIdList"`
|
||||
RelationList []*UpsertMemoRelationRequest `json:"relationList"`
|
||||
}
|
||||
|
||||
type PatchMemoRequest struct {
|
||||
ID int `json:"-"`
|
||||
ID int32 `json:"-"`
|
||||
|
||||
// Standard fields
|
||||
CreatedTs *int64 `json:"createdTs"`
|
||||
@ -87,16 +88,16 @@ type PatchMemoRequest struct {
|
||||
Visibility *Visibility `json:"visibility"`
|
||||
|
||||
// Related fields
|
||||
ResourceIDList []int `json:"resourceIdList"`
|
||||
ResourceIDList []int32 `json:"resourceIdList"`
|
||||
RelationList []*UpsertMemoRelationRequest `json:"relationList"`
|
||||
}
|
||||
|
||||
type FindMemoRequest struct {
|
||||
ID *int
|
||||
ID *int32
|
||||
|
||||
// Standard fields
|
||||
RowStatus *RowStatus
|
||||
CreatorID *int
|
||||
CreatorID *int32
|
||||
|
||||
// Domain specific fields
|
||||
Pinned *bool
|
||||
@ -114,7 +115,7 @@ const maxContentLength = 1 << 30
|
||||
func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
g.POST("/memo", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -225,12 +226,12 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
|
||||
g.PATCH("/memo/:memoId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
@ -352,7 +353,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
g.GET("/memo", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
findMemoMessage := &store.FindMemo{}
|
||||
if userID, err := strconv.Atoi(c.QueryParam("creatorId")); err == nil {
|
||||
if userID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil {
|
||||
findMemoMessage.CreatorID = &userID
|
||||
}
|
||||
|
||||
@ -363,7 +364,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
}
|
||||
}
|
||||
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
// Anonymous use should only fetch PUBLIC memos with specified user
|
||||
if findMemoMessage.CreatorID == nil {
|
||||
@ -435,7 +436,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/memo/:memoId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
@ -450,7 +451,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Memo not found: %d", memoID))
|
||||
}
|
||||
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if memo.Visibility == store.Private {
|
||||
if !ok || memo.CreatorID != userID {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "this memo is private only")
|
||||
@ -473,7 +474,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
findMemoMessage := &store.FindMemo{
|
||||
RowStatus: &normalStatus,
|
||||
}
|
||||
if creatorID, err := strconv.Atoi(c.QueryParam("creatorId")); err == nil {
|
||||
if creatorID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil {
|
||||
findMemoMessage.CreatorID = &creatorID
|
||||
}
|
||||
|
||||
@ -488,7 +489,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo")
|
||||
}
|
||||
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public}
|
||||
} else {
|
||||
@ -590,11 +591,11 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||
|
||||
g.DELETE("/memo/:memoId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
@ -757,12 +758,12 @@ func getMemoRelationListDiff(oldList, newList []*store.MemoRelation) (addedList,
|
||||
return addedList, removedList
|
||||
}
|
||||
|
||||
func getIDListDiff(oldList, newList []int) (addedList, removedList []int) {
|
||||
oldMap := map[int]bool{}
|
||||
func getIDListDiff(oldList, newList []int32) (addedList, removedList []int32) {
|
||||
oldMap := map[int32]bool{}
|
||||
for _, id := range oldList {
|
||||
oldMap[id] = true
|
||||
}
|
||||
newMap := map[int]bool{}
|
||||
newMap := map[int32]bool{}
|
||||
for _, id := range newList {
|
||||
newMap[id] = true
|
||||
}
|
||||
|
@ -4,17 +4,17 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/usememos/memos/api/auth"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
type MemoOrganizer struct {
|
||||
MemoID int `json:"memoId"`
|
||||
UserID int `json:"userId"`
|
||||
Pinned bool `json:"pinned"`
|
||||
MemoID int32 `json:"memoId"`
|
||||
UserID int32 `json:"userId"`
|
||||
Pinned bool `json:"pinned"`
|
||||
}
|
||||
|
||||
type UpsertMemoOrganizerRequest struct {
|
||||
@ -24,12 +24,12 @@ type UpsertMemoOrganizerRequest struct {
|
||||
func (s *APIV1Service) registerMemoOrganizerRoutes(g *echo.Group) {
|
||||
g.POST("/memo/:memoId/organizer", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
@ -18,20 +18,20 @@ const (
|
||||
)
|
||||
|
||||
type MemoRelation struct {
|
||||
MemoID int `json:"memoId"`
|
||||
RelatedMemoID int `json:"relatedMemoId"`
|
||||
MemoID int32 `json:"memoId"`
|
||||
RelatedMemoID int32 `json:"relatedMemoId"`
|
||||
Type MemoRelationType `json:"type"`
|
||||
}
|
||||
|
||||
type UpsertMemoRelationRequest struct {
|
||||
RelatedMemoID int `json:"relatedMemoId"`
|
||||
RelatedMemoID int32 `json:"relatedMemoId"`
|
||||
Type MemoRelationType `json:"type"`
|
||||
}
|
||||
|
||||
func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
|
||||
g.POST("/memo/:memoId/relation", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
@ -54,7 +54,7 @@ func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/memo/:memoId/relation", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
@ -70,11 +70,11 @@ func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
|
||||
|
||||
g.DELETE("/memo/:memoId/relation/:relatedMemoId/type/:relationType", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Memo ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
relatedMemoID, err := strconv.Atoi(c.Param("relatedMemoId"))
|
||||
relatedMemoID, err := util.ConvertStringToInt32(c.Param("relatedMemoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Related memo ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
|
@ -4,45 +4,45 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/usememos/memos/api/auth"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
type MemoResource struct {
|
||||
MemoID int `json:"memoId"`
|
||||
ResourceID int `json:"resourceId"`
|
||||
MemoID int32 `json:"memoId"`
|
||||
ResourceID int32 `json:"resourceId"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
}
|
||||
|
||||
type UpsertMemoResourceRequest struct {
|
||||
ResourceID int `json:"resourceId"`
|
||||
ResourceID int32 `json:"resourceId"`
|
||||
UpdatedTs *int64 `json:"updatedTs"`
|
||||
}
|
||||
|
||||
type MemoResourceFind struct {
|
||||
MemoID *int
|
||||
ResourceID *int
|
||||
MemoID *int32
|
||||
ResourceID *int32
|
||||
}
|
||||
|
||||
type MemoResourceDelete struct {
|
||||
MemoID *int
|
||||
ResourceID *int
|
||||
MemoID *int32
|
||||
ResourceID *int32
|
||||
}
|
||||
|
||||
func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
|
||||
g.POST("/memo/:memoId/resource", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -78,7 +78,7 @@ func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/memo/:memoId/resource", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
@ -98,15 +98,15 @@ func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
|
||||
|
||||
g.DELETE("/memo/:memoId/resource/:resourceId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
memoID, err := strconv.Atoi(c.Param("memoId"))
|
||||
memoID, err := util.ConvertStringToInt32(c.Param("memoId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Memo ID is not a number: %s", c.Param("memoId"))).SetInternal(err)
|
||||
}
|
||||
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
||||
resourceID, err := util.ConvertStringToInt32(c.Param("resourceId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Resource ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ import (
|
||||
)
|
||||
|
||||
type Resource struct {
|
||||
ID int `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
|
||||
// Standard fields
|
||||
CreatorID int `json:"creatorId"`
|
||||
CreatorID int32 `json:"creatorId"`
|
||||
CreatedTs int64 `json:"createdTs"`
|
||||
UpdatedTs int64 `json:"updatedTs"`
|
||||
|
||||
@ -58,8 +58,8 @@ type CreateResourceRequest struct {
|
||||
}
|
||||
|
||||
type FindResourceRequest struct {
|
||||
ID *int `json:"id"`
|
||||
CreatorID *int `json:"creatorId"`
|
||||
ID *int32 `json:"id"`
|
||||
CreatorID *int32 `json:"creatorId"`
|
||||
Filename *string `json:"filename"`
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ var fileKeyPattern = regexp.MustCompile(`\{[a-z]{1,9}\}`)
|
||||
func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
|
||||
g.POST("/resource", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -157,7 +157,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
|
||||
|
||||
g.POST("/resource/blob", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -217,7 +217,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/resource", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -244,12 +244,12 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
|
||||
|
||||
g.PATCH("/resource/:resourceId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
||||
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
||||
resourceID, err := util.ConvertStringToInt32(c.Param("resourceId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
@ -290,12 +290,12 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
|
||||
|
||||
g.DELETE("/resource/:resourceId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
||||
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
||||
resourceID, err := util.ConvertStringToInt32(c.Param("resourceId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
@ -335,7 +335,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
|
||||
func (s *APIV1Service) registerResourcePublicRoutes(g *echo.Group) {
|
||||
f := func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
resourceID, err := strconv.Atoi(c.Param("resourceId"))
|
||||
resourceID, err := util.ConvertStringToInt32(c.Param("resourceId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("resourceId"))).SetInternal(err)
|
||||
}
|
||||
@ -346,7 +346,7 @@ func (s *APIV1Service) registerResourcePublicRoutes(g *echo.Group) {
|
||||
}
|
||||
|
||||
// Protected resource require a logined user
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if resourceVisibility == store.Protected && (!ok || userID <= 0) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Resource visibility not match").SetInternal(err)
|
||||
}
|
||||
@ -501,7 +501,7 @@ func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error)
|
||||
return dstBlob, nil
|
||||
}
|
||||
|
||||
func checkResourceVisibility(ctx context.Context, s *store.Store, resourceID int) (store.Visibility, error) {
|
||||
func checkResourceVisibility(ctx context.Context, s *store.Store, resourceID int32) (store.Visibility, error) {
|
||||
memoResources, err := s.ListMemoResources(ctx, &store.FindMemoResource{
|
||||
ResourceID: &resourceID,
|
||||
})
|
||||
@ -514,7 +514,7 @@ func checkResourceVisibility(ctx context.Context, s *store.Store, resourceID int
|
||||
return store.Private, nil
|
||||
}
|
||||
|
||||
memoIDs := make([]int, 0, len(memoResources))
|
||||
memoIDs := make([]int32, 0, len(memoResources))
|
||||
for _, memoResource := range memoResources {
|
||||
memoIDs = append(memoIDs, memoResource.MemoID)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (s *APIV1Service) registerRSSRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/u/:id/rss.xml", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
id, err := util.ConvertStringToInt32(c.Param("id"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "User id is not a number").SetInternal(err)
|
||||
}
|
||||
@ -94,10 +94,10 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
|
||||
memo := memoList[i]
|
||||
feed.Items[i] = &feeds.Item{
|
||||
Title: getRSSItemTitle(memo.Content),
|
||||
Link: &feeds.Link{Href: baseURL + "/m/" + strconv.Itoa(memo.ID)},
|
||||
Link: &feeds.Link{Href: baseURL + "/m/" + fmt.Sprintf("%d", memo.ID)},
|
||||
Description: getRSSItemDescription(memo.Content),
|
||||
Created: time.Unix(memo.CreatedTs, 0),
|
||||
Enclosure: &feeds.Enclosure{Url: baseURL + "/m/" + strconv.Itoa(memo.ID) + "/image"},
|
||||
Enclosure: &feeds.Enclosure{Url: baseURL + "/m/" + fmt.Sprintf("%d", memo.ID) + "/image"},
|
||||
}
|
||||
if len(memo.ResourceIDList) > 0 {
|
||||
resourceID := memo.ResourceIDList[0]
|
||||
@ -114,7 +114,7 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
|
||||
if resource.ExternalLink != "" {
|
||||
enclosure.Url = resource.ExternalLink
|
||||
} else {
|
||||
enclosure.Url = baseURL + "/o/r/" + strconv.Itoa(resource.ID)
|
||||
enclosure.Url = baseURL + "/o/r/" + fmt.Sprintf("%d", resource.ID)
|
||||
}
|
||||
enclosure.Length = strconv.Itoa(int(resource.Size))
|
||||
enclosure.Type = resource.Type
|
||||
|
@ -4,18 +4,18 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/usememos/memos/api/auth"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
const (
|
||||
// LocalStorage means the storage service is local file system.
|
||||
LocalStorage = -1
|
||||
LocalStorage int32 = -1
|
||||
// DatabaseStorage means the storage service is database.
|
||||
DatabaseStorage = 0
|
||||
DatabaseStorage int32 = 0
|
||||
)
|
||||
|
||||
type StorageType string
|
||||
@ -44,7 +44,7 @@ type StorageS3Config struct {
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
ID int `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type StorageType `json:"type"`
|
||||
Config *StorageConfig `json:"config"`
|
||||
@ -65,7 +65,7 @@ type UpdateStorageRequest struct {
|
||||
func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
|
||||
g.POST("/storage", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -111,7 +111,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
|
||||
|
||||
g.PATCH("/storage/:storageId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -126,7 +126,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
||||
}
|
||||
|
||||
storageID, err := strconv.Atoi(c.Param("storageId"))
|
||||
storageID, err := util.ConvertStringToInt32(c.Param("storageId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("storageId"))).SetInternal(err)
|
||||
}
|
||||
@ -165,7 +165,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/storage", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -199,7 +199,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
|
||||
|
||||
g.DELETE("/storage/:storageId", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -214,7 +214,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
|
||||
}
|
||||
|
||||
storageID, err := strconv.Atoi(c.Param("storageId"))
|
||||
storageID, err := util.ConvertStringToInt32(c.Param("storageId"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("storageId"))).SetInternal(err)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type SystemStatus struct {
|
||||
// Customized server profile, including server name and external url.
|
||||
CustomizedProfile CustomizedProfile `json:"customizedProfile"`
|
||||
// Storage service ID.
|
||||
StorageServiceID int `json:"storageServiceId"`
|
||||
StorageServiceID int32 `json:"storageServiceId"`
|
||||
// Local storage path.
|
||||
LocalStoragePath string `json:"localStoragePath"`
|
||||
// Memo display with updated timestamp.
|
||||
@ -126,7 +126,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
|
||||
}
|
||||
systemStatus.CustomizedProfile = customizedProfile
|
||||
case SystemSettingStorageServiceIDName.String():
|
||||
systemStatus.StorageServiceID = int(baseValue.(float64))
|
||||
systemStatus.StorageServiceID = int32(baseValue.(float64))
|
||||
case SystemSettingLocalStoragePathName.String():
|
||||
systemStatus.LocalStoragePath = baseValue.(string)
|
||||
case SystemSettingMemoDisplayWithUpdatedTsName.String():
|
||||
@ -141,7 +141,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
|
||||
|
||||
g.POST("/system/vacuum", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
|
||||
func (s *APIV1Service) registerSystemSettingRoutes(g *echo.Group) {
|
||||
g.POST("/system/setting", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -237,7 +237,7 @@ func (s *APIV1Service) registerSystemSettingRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/system/setting", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
|
||||
type Tag struct {
|
||||
Name string
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
}
|
||||
|
||||
type UpsertTagRequest struct {
|
||||
@ -30,7 +30,7 @@ type DeleteTagRequest struct {
|
||||
func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
|
||||
g.POST("/tag", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -59,7 +59,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/tag", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find tag")
|
||||
}
|
||||
@ -80,7 +80,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
|
||||
|
||||
g.GET("/tag/suggestion", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Missing user session")
|
||||
}
|
||||
@ -125,7 +125,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
|
||||
|
||||
g.POST("/tag/delete", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -32,7 +31,7 @@ func (role Role) String() string {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int `json:"id"`
|
||||
ID int32 `json:"id"`
|
||||
|
||||
// Standard fields
|
||||
RowStatus RowStatus `json:"rowStatus"`
|
||||
@ -133,7 +132,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
|
||||
// POST /user - Create a new user.
|
||||
g.POST("/user", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing auth session")
|
||||
}
|
||||
@ -208,7 +207,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
|
||||
// GET /user/me - Get current user.
|
||||
g.GET("/user/me", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing auth session")
|
||||
}
|
||||
@ -239,7 +238,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
|
||||
// GET /user/:id - Get user by id.
|
||||
g.GET("/user/:id", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
id, err := util.ConvertStringToInt32(c.Param("id"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted user id").SetInternal(err)
|
||||
}
|
||||
@ -282,12 +281,12 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
|
||||
// PUT /user/:id - Update user by id.
|
||||
g.PATCH("/user/:id", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, err := strconv.Atoi(c.Param("id"))
|
||||
userID, err := util.ConvertStringToInt32(c.Param("id"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
|
||||
}
|
||||
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -367,7 +366,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
|
||||
// DELETE /user/:id - Delete user by id.
|
||||
g.DELETE("/user/:id", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
currentUserID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||
}
|
||||
@ -383,7 +382,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "Unauthorized to delete user").SetInternal(err)
|
||||
}
|
||||
|
||||
userID, err := strconv.Atoi(c.Param("id"))
|
||||
userID, err := util.ConvertStringToInt32(c.Param("id"))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
|
||||
}
|
||||
|
@ -67,13 +67,13 @@ var (
|
||||
)
|
||||
|
||||
type UserSetting struct {
|
||||
UserID int `json:"userId"`
|
||||
UserID int32 `json:"userId"`
|
||||
Key UserSettingKey `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type UpsertUserSettingRequest struct {
|
||||
UserID int `json:"-"`
|
||||
UserID int32 `json:"-"`
|
||||
Key UserSettingKey `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
@ -122,7 +122,7 @@ func (upsert UpsertUserSettingRequest) Validate() error {
|
||||
func (s *APIV1Service) registerUserSettingRoutes(g *echo.Group) {
|
||||
g.POST("/user/setting", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int)
|
||||
userID, ok := c.Get(auth.UserIDContextKey).(int32)
|
||||
if !ok {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing auth session")
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/usememos/memos/api/auth"
|
||||
"github.com/usememos/memos/common/util"
|
||||
"github.com/usememos/memos/store"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -76,7 +77,7 @@ func (in *GRPCAuthInterceptor) AuthenticationInterceptor(ctx context.Context, re
|
||||
return handler(childCtx, request)
|
||||
}
|
||||
|
||||
func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessTokenStr string) (int, error) {
|
||||
func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessTokenStr string) (int32, error) {
|
||||
if accessTokenStr == "" {
|
||||
return 0, status.Errorf(codes.Unauthenticated, "access token not found")
|
||||
}
|
||||
@ -103,7 +104,7 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessTokenStr
|
||||
)
|
||||
}
|
||||
|
||||
userID, err := strconv.Atoi(claims.Subject)
|
||||
userID, err := util.ConvertStringToInt32(claims.Subject)
|
||||
if err != nil {
|
||||
return 0, status.Errorf(codes.Unauthenticated, "malformed ID %q in the access token", claims.Subject)
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ func NewTagService(store *store.Store) *TagService {
|
||||
|
||||
func (s *TagService) ListTags(ctx context.Context, request *apiv2pb.ListTagsRequest) (*apiv2pb.ListTagsResponse, error) {
|
||||
tags, err := s.Store.ListTags(ctx, &store.FindTag{
|
||||
CreatorID: int(request.CreatorId),
|
||||
CreatorID: request.CreatorId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list tags: %v", err)
|
||||
|
@ -37,9 +37,8 @@ func (s *UserService) GetUser(ctx context.Context, request *apiv2pb.GetUserReque
|
||||
// Data desensitization.
|
||||
userMessage.OpenId = ""
|
||||
|
||||
userUID := int(userMessage.Id)
|
||||
userSettings, err := s.Store.ListUserSettings(ctx, &store.FindUserSetting{
|
||||
UserID: &userUID,
|
||||
UserID: &userMessage.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list user settings: %v", err)
|
||||
|
@ -4,11 +4,21 @@ import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"net/mail"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ConvertStringToInt32 converts a string to int32.
|
||||
func ConvertStringToInt32(src string) (int32, error) {
|
||||
i, err := strconv.Atoi(src)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int32(i), nil
|
||||
}
|
||||
|
||||
// HasPrefixes returns true if the string s has any of the given prefixes.
|
||||
func HasPrefixes(src string, prefixes ...string) bool {
|
||||
for _, prefix := range prefixes {
|
||||
|
@ -37,7 +37,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
|
||||
return fmt.Errorf("fail to SendReplyMessage: %s", err)
|
||||
}
|
||||
|
||||
var creatorID int
|
||||
var creatorID int32
|
||||
userSettingList, err := t.store.ListUserSettings(ctx, &store.FindUserSetting{
|
||||
Key: apiv1.UserSettingTelegramUserIDKey.String(),
|
||||
})
|
||||
@ -121,7 +121,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
|
||||
}
|
||||
|
||||
func (t *telegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram.Bot, callbackQuery telegram.CallbackQuery) error {
|
||||
var memoID int
|
||||
var memoID int32
|
||||
var visibility store.Visibility
|
||||
n, err := fmt.Sscanf(callbackQuery.Data, "%s %d", &visibility, &memoID)
|
||||
if err != nil || n != 2 {
|
||||
@ -146,7 +146,7 @@ func (t *telegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram
|
||||
return bot.AnswerCallbackQuery(ctx, callbackQuery.ID, fmt.Sprintf("Success change Memo %d to %s", memoID, visibility))
|
||||
}
|
||||
|
||||
func generateKeyboardForMemoID(id int) [][]telegram.InlineKeyboardButton {
|
||||
func generateKeyboardForMemoID(id int32) [][]telegram.InlineKeyboardButton {
|
||||
allVisibility := []store.Visibility{
|
||||
store.Public,
|
||||
store.Protected,
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
ID int
|
||||
ID int32
|
||||
|
||||
// Standard fields
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
CreatedTs int64
|
||||
|
||||
// Domain specific fields
|
||||
|
@ -4,6 +4,6 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func getUserSettingCacheKey(userID int, key string) string {
|
||||
func getUserSettingCacheKey(userID int32, key string) string {
|
||||
return fmt.Sprintf("%d-%s", userID, key)
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ type FieldMapping struct {
|
||||
}
|
||||
|
||||
type IdentityProvider struct {
|
||||
ID int
|
||||
ID int32
|
||||
Name string
|
||||
Type IdentityProviderType
|
||||
IdentifierFilter string
|
||||
@ -46,11 +46,11 @@ type IdentityProvider struct {
|
||||
}
|
||||
|
||||
type FindIdentityProvider struct {
|
||||
ID *int
|
||||
ID *int32
|
||||
}
|
||||
|
||||
type UpdateIdentityProvider struct {
|
||||
ID int
|
||||
ID int32
|
||||
Type IdentityProviderType
|
||||
Name *string
|
||||
IdentifierFilter *string
|
||||
@ -58,7 +58,7 @@ type UpdateIdentityProvider struct {
|
||||
}
|
||||
|
||||
type DeleteIdentityProvider struct {
|
||||
ID int
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateIdentityProvider(ctx context.Context, create *IdentityProvider) (*IdentityProvider, error) {
|
||||
|
@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/usememos/memos/common/util"
|
||||
)
|
||||
|
||||
// Visibility is the type of a visibility.
|
||||
@ -34,11 +35,11 @@ func (v Visibility) String() string {
|
||||
}
|
||||
|
||||
type Memo struct {
|
||||
ID int
|
||||
ID int32
|
||||
|
||||
// Standard fields
|
||||
RowStatus RowStatus
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
CreatedTs int64
|
||||
UpdatedTs int64
|
||||
|
||||
@ -48,16 +49,16 @@ type Memo struct {
|
||||
|
||||
// Composed fields
|
||||
Pinned bool
|
||||
ResourceIDList []int
|
||||
ResourceIDList []int32
|
||||
RelationList []*MemoRelation
|
||||
}
|
||||
|
||||
type FindMemo struct {
|
||||
ID *int
|
||||
ID *int32
|
||||
|
||||
// Standard fields
|
||||
RowStatus *RowStatus
|
||||
CreatorID *int
|
||||
CreatorID *int32
|
||||
|
||||
// Domain specific fields
|
||||
Pinned *bool
|
||||
@ -71,7 +72,7 @@ type FindMemo struct {
|
||||
}
|
||||
|
||||
type UpdateMemo struct {
|
||||
ID int
|
||||
ID int32
|
||||
CreatedTs *int64
|
||||
UpdatedTs *int64
|
||||
RowStatus *RowStatus
|
||||
@ -80,7 +81,7 @@ type UpdateMemo struct {
|
||||
}
|
||||
|
||||
type DeleteMemo struct {
|
||||
ID int
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
|
||||
@ -220,9 +221,9 @@ func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
|
||||
|
||||
if memoResourceIDList.Valid {
|
||||
idStringList := strings.Split(memoResourceIDList.String, ",")
|
||||
memo.ResourceIDList = make([]int, 0, len(idStringList))
|
||||
memo.ResourceIDList = make([]int32, 0, len(idStringList))
|
||||
for _, idString := range idStringList {
|
||||
id, err := strconv.Atoi(idString)
|
||||
id, err := util.ConvertStringToInt32(idString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -237,7 +238,7 @@ func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
|
||||
if len(relatedMemoTypeList) != 2 {
|
||||
return nil, fmt.Errorf("invalid relation format")
|
||||
}
|
||||
relatedMemoID, err := strconv.Atoi(relatedMemoTypeList[0])
|
||||
relatedMemoID, err := util.ConvertStringToInt32(relatedMemoTypeList[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -318,7 +319,7 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) FindMemosVisibilityList(ctx context.Context, memoIDs []int) ([]Visibility, error) {
|
||||
func (s *Store) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error) {
|
||||
args := make([]any, 0, len(memoIDs))
|
||||
list := make([]string, 0, len(memoIDs))
|
||||
for _, memoID := range memoIDs {
|
||||
|
@ -8,19 +8,19 @@ import (
|
||||
)
|
||||
|
||||
type MemoOrganizer struct {
|
||||
MemoID int
|
||||
UserID int
|
||||
MemoID int32
|
||||
UserID int32
|
||||
Pinned bool
|
||||
}
|
||||
|
||||
type FindMemoOrganizer struct {
|
||||
MemoID int
|
||||
UserID int
|
||||
MemoID int32
|
||||
UserID int32
|
||||
}
|
||||
|
||||
type DeleteMemoOrganizer struct {
|
||||
MemoID *int
|
||||
UserID *int
|
||||
MemoID *int32
|
||||
UserID *int32
|
||||
}
|
||||
|
||||
func (s *Store) UpsertMemoOrganizer(ctx context.Context, upsert *MemoOrganizer) (*MemoOrganizer, error) {
|
||||
|
@ -14,20 +14,20 @@ const (
|
||||
)
|
||||
|
||||
type MemoRelation struct {
|
||||
MemoID int
|
||||
RelatedMemoID int
|
||||
MemoID int32
|
||||
RelatedMemoID int32
|
||||
Type MemoRelationType
|
||||
}
|
||||
|
||||
type FindMemoRelation struct {
|
||||
MemoID *int
|
||||
RelatedMemoID *int
|
||||
MemoID *int32
|
||||
RelatedMemoID *int32
|
||||
Type *MemoRelationType
|
||||
}
|
||||
|
||||
type DeleteMemoRelation struct {
|
||||
MemoID *int
|
||||
RelatedMemoID *int
|
||||
MemoID *int32
|
||||
RelatedMemoID *int32
|
||||
Type *MemoRelationType
|
||||
}
|
||||
|
||||
|
@ -7,27 +7,27 @@ import (
|
||||
)
|
||||
|
||||
type MemoResource struct {
|
||||
MemoID int
|
||||
ResourceID int
|
||||
MemoID int32
|
||||
ResourceID int32
|
||||
CreatedTs int64
|
||||
UpdatedTs int64
|
||||
}
|
||||
|
||||
type UpsertMemoResource struct {
|
||||
MemoID int
|
||||
ResourceID int
|
||||
MemoID int32
|
||||
ResourceID int32
|
||||
CreatedTs int64
|
||||
UpdatedTs *int64
|
||||
}
|
||||
|
||||
type FindMemoResource struct {
|
||||
MemoID *int
|
||||
ResourceID *int
|
||||
MemoID *int32
|
||||
ResourceID *int32
|
||||
}
|
||||
|
||||
type DeleteMemoResource struct {
|
||||
MemoID *int
|
||||
ResourceID *int
|
||||
MemoID *int32
|
||||
ResourceID *int32
|
||||
}
|
||||
|
||||
func (s *Store) UpsertMemoResource(ctx context.Context, upsert *UpsertMemoResource) (*MemoResource, error) {
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
type Resource struct {
|
||||
ID int
|
||||
ID int32
|
||||
|
||||
// Standard fields
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
CreatedTs int64
|
||||
UpdatedTs int64
|
||||
|
||||
@ -27,16 +27,16 @@ type Resource struct {
|
||||
|
||||
type FindResource struct {
|
||||
GetBlob bool
|
||||
ID *int
|
||||
CreatorID *int
|
||||
ID *int32
|
||||
CreatorID *int32
|
||||
Filename *string
|
||||
MemoID *int
|
||||
MemoID *int32
|
||||
Limit *int
|
||||
Offset *int
|
||||
}
|
||||
|
||||
type UpdateResource struct {
|
||||
ID int
|
||||
ID int32
|
||||
UpdatedTs *int64
|
||||
Filename *string
|
||||
InternalPath *string
|
||||
@ -44,7 +44,7 @@ type UpdateResource struct {
|
||||
}
|
||||
|
||||
type DeleteResource struct {
|
||||
ID int
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateResource(ctx context.Context, create *Resource) (*Resource, error) {
|
||||
|
@ -6,24 +6,24 @@ import (
|
||||
)
|
||||
|
||||
type Storage struct {
|
||||
ID int
|
||||
ID int32
|
||||
Name string
|
||||
Type string
|
||||
Config string
|
||||
}
|
||||
|
||||
type FindStorage struct {
|
||||
ID *int
|
||||
ID *int32
|
||||
}
|
||||
|
||||
type UpdateStorage struct {
|
||||
ID int
|
||||
ID int32
|
||||
Name *string
|
||||
Config *string
|
||||
}
|
||||
|
||||
type DeleteStorage struct {
|
||||
ID int
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateStorage(ctx context.Context, create *Storage) (*Storage, error) {
|
||||
|
@ -8,16 +8,16 @@ import (
|
||||
|
||||
type Tag struct {
|
||||
Name string
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
}
|
||||
|
||||
type FindTag struct {
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
}
|
||||
|
||||
type DeleteTag struct {
|
||||
Name string
|
||||
CreatorID int
|
||||
CreatorID int32
|
||||
}
|
||||
|
||||
func (s *Store) UpsertTag(ctx context.Context, upsert *Tag) (*Tag, error) {
|
||||
|
@ -30,7 +30,7 @@ func (e Role) String() string {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int
|
||||
ID int32
|
||||
|
||||
// Standard fields
|
||||
RowStatus RowStatus
|
||||
@ -48,7 +48,7 @@ type User struct {
|
||||
}
|
||||
|
||||
type UpdateUser struct {
|
||||
ID int
|
||||
ID int32
|
||||
|
||||
UpdatedTs *int64
|
||||
RowStatus *RowStatus
|
||||
@ -63,7 +63,7 @@ type UpdateUser struct {
|
||||
}
|
||||
|
||||
type FindUser struct {
|
||||
ID *int
|
||||
ID *int32
|
||||
RowStatus *RowStatus
|
||||
Username *string
|
||||
Role *Role
|
||||
@ -73,7 +73,7 @@ type FindUser struct {
|
||||
}
|
||||
|
||||
type DeleteUser struct {
|
||||
ID int
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateUser(ctx context.Context, create *User) (*User, error) {
|
||||
|
@ -7,13 +7,13 @@ import (
|
||||
)
|
||||
|
||||
type UserSetting struct {
|
||||
UserID int
|
||||
UserID int32
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
type FindUserSetting struct {
|
||||
UserID *int
|
||||
UserID *int32
|
||||
Key string
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func TestMemoRelationServer(t *testing.T) {
|
||||
require.Len(t, memo2.RelationList, 1)
|
||||
}
|
||||
|
||||
func (s *TestingServer) postMemoRelationUpsert(memoID int, memoRelationUpsert *apiv1.UpsertMemoRelationRequest) (*apiv1.MemoRelation, error) {
|
||||
func (s *TestingServer) postMemoRelationUpsert(memoID int32, memoRelationUpsert *apiv1.UpsertMemoRelationRequest) (*apiv1.MemoRelation, error) {
|
||||
rawData, err := json.Marshal(&memoRelationUpsert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal memo relation upsert")
|
||||
@ -85,7 +85,7 @@ func (s *TestingServer) postMemoRelationUpsert(memoID int, memoRelationUpsert *a
|
||||
return memoRelation, nil
|
||||
}
|
||||
|
||||
func (s *TestingServer) deleteMemoRelation(memoID int, relatedMemoID int, relationType apiv1.MemoRelationType) error {
|
||||
func (s *TestingServer) deleteMemoRelation(memoID int32, relatedMemoID int32, relationType apiv1.MemoRelationType) error {
|
||||
_, err := s.delete(fmt.Sprintf("/api/v1/memo/%d/relation/%d/type/%s", memoID, relatedMemoID, relationType), nil)
|
||||
return err
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func TestMemoServer(t *testing.T) {
|
||||
require.Len(t, memoList, 0)
|
||||
}
|
||||
|
||||
func (s *TestingServer) getMemo(memoID int) (*apiv1.Memo, error) {
|
||||
func (s *TestingServer) getMemo(memoID int32) (*apiv1.Memo, error) {
|
||||
body, err := s.get(fmt.Sprintf("/api/v1/memo/%d", memoID), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -145,12 +145,12 @@ func (s *TestingServer) patchMemo(memoPatch *apiv1.PatchMemoRequest) (*apiv1.Mem
|
||||
return memo, nil
|
||||
}
|
||||
|
||||
func (s *TestingServer) deleteMemo(memoID int) error {
|
||||
func (s *TestingServer) deleteMemo(memoID int32) error {
|
||||
_, err := s.delete(fmt.Sprintf("/api/v1/memo/%d", memoID), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TestingServer) postMemoOrganizer(memoID int, memosOrganizer *apiv1.UpsertMemoOrganizerRequest) (*apiv1.Memo, error) {
|
||||
func (s *TestingServer) postMemoOrganizer(memoID int32, memosOrganizer *apiv1.UpsertMemoOrganizerRequest) (*apiv1.Memo, error) {
|
||||
rawData, err := json.Marshal(&memosOrganizer)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal memos organizer")
|
||||
|
@ -29,15 +29,15 @@ func TestResourceStore(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, correctFilename, res.Filename)
|
||||
require.Equal(t, 1, res.ID)
|
||||
require.Equal(t, int32(1), res.ID)
|
||||
notFoundResource, err := ts.GetResource(ctx, &store.FindResource{
|
||||
Filename: &incorrectFilename,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, notFoundResource)
|
||||
|
||||
correctCreatorID := 101
|
||||
incorrectCreatorID := 102
|
||||
var correctCreatorID int32 = 101
|
||||
var incorrectCreatorID int32 = 102
|
||||
_, err = ts.GetResource(ctx, &store.FindResource{
|
||||
CreatorID: &correctCreatorID,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user