mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: tweak variable names
This commit is contained in:
@@ -435,34 +435,34 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
|
|||||||
// - creatorUsername is listed at ./web/src/helpers/api.ts:82, but it's not present here
|
// - creatorUsername is listed at ./web/src/helpers/api.ts:82, but it's not present here
|
||||||
func (s *APIV1Service) GetAllMemos(c echo.Context) error {
|
func (s *APIV1Service) GetAllMemos(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
findMemoMessage := &store.FindMemo{}
|
memoFind := &store.FindMemo{}
|
||||||
_, ok := c.Get(userIDContextKey).(int32)
|
_, ok := c.Get(userIDContextKey).(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public}
|
memoFind.VisibilityList = []store.Visibility{store.Public}
|
||||||
} else {
|
} else {
|
||||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public, store.Protected}
|
memoFind.VisibilityList = []store.Visibility{store.Public, store.Protected}
|
||||||
}
|
}
|
||||||
|
|
||||||
if limit, err := strconv.Atoi(c.QueryParam("limit")); err == nil {
|
if limit, err := strconv.Atoi(c.QueryParam("limit")); err == nil {
|
||||||
findMemoMessage.Limit = &limit
|
memoFind.Limit = &limit
|
||||||
}
|
}
|
||||||
if offset, err := strconv.Atoi(c.QueryParam("offset")); err == nil {
|
if offset, err := strconv.Atoi(c.QueryParam("offset")); err == nil {
|
||||||
findMemoMessage.Offset = &offset
|
memoFind.Offset = &offset
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only fetch normal status memos.
|
// Only fetch normal status memos.
|
||||||
normalStatus := store.Normal
|
normalStatus := store.Normal
|
||||||
findMemoMessage.RowStatus = &normalStatus
|
memoFind.RowStatus = &normalStatus
|
||||||
|
|
||||||
memoDisplayWithUpdatedTs, err := s.getMemoDisplayWithUpdatedTsSettingValue(ctx)
|
memoDisplayWithUpdatedTs, err := s.getMemoDisplayWithUpdatedTsSettingValue(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get memo display with updated ts setting value").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get memo display with updated ts setting value").SetInternal(err)
|
||||||
}
|
}
|
||||||
if memoDisplayWithUpdatedTs {
|
if memoDisplayWithUpdatedTs {
|
||||||
findMemoMessage.OrderByUpdatedTs = true
|
memoFind.OrderByUpdatedTs = true
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := s.Store.ListMemos(ctx, findMemoMessage)
|
list, err := s.Store.ListMemos(ctx, memoFind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch all memo list").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch all memo list").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
@@ -313,10 +313,9 @@ func (s *APIV1Service) DeleteUser(c echo.Context) error {
|
|||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
userDelete := &store.DeleteUser{
|
if err := s.Store.DeleteUser(ctx, &store.DeleteUser{
|
||||||
ID: userID,
|
ID: userID,
|
||||||
}
|
}); err != nil {
|
||||||
if err := s.Store.DeleteUser(ctx, userDelete); err != nil {
|
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete user").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete user").SetInternal(err)
|
||||||
}
|
}
|
||||||
return c.JSON(http.StatusOK, true)
|
return c.JSON(http.StatusOK, true)
|
||||||
|
@@ -64,12 +64,12 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v := find.VisibilityList; len(v) != 0 {
|
if v := find.VisibilityList; len(v) != 0 {
|
||||||
list := []string{}
|
placeholder := []string{}
|
||||||
for _, visibility := range v {
|
for _, visibility := range v {
|
||||||
list = append(list, "?")
|
placeholder = append(placeholder, "?")
|
||||||
args = append(args, visibility)
|
args = append(args, visibility.String())
|
||||||
}
|
}
|
||||||
where = append(where, fmt.Sprintf("`memo`.`visibility` in (%s)", strings.Join(list, ",")))
|
where = append(where, fmt.Sprintf("`memo`.`visibility` in (%s)", strings.Join(placeholder, ",")))
|
||||||
}
|
}
|
||||||
orders := []string{}
|
orders := []string{}
|
||||||
if find.OrderByPinned {
|
if find.OrderByPinned {
|
||||||
|
@@ -51,12 +51,12 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v := find.VisibilityList; len(v) != 0 {
|
if v := find.VisibilityList; len(v) != 0 {
|
||||||
list := []string{}
|
placeholder := []string{}
|
||||||
for _, visibility := range v {
|
for _, visibility := range v {
|
||||||
list = append(list, fmt.Sprintf("$%d", len(args)+1))
|
placeholder = append(placeholder, "?")
|
||||||
args = append(args, visibility)
|
args = append(args, visibility.String())
|
||||||
}
|
}
|
||||||
where = append(where, fmt.Sprintf("memo.visibility in (%s)", strings.Join(list, ",")))
|
where = append(where, fmt.Sprintf("memo.visibility in (%s)", strings.Join(placeholder, ",")))
|
||||||
}
|
}
|
||||||
if v := find.Pinned; v != nil {
|
if v := find.Pinned; v != nil {
|
||||||
where = append(where, "memo_organizer.pinned = 1")
|
where = append(where, "memo_organizer.pinned = 1")
|
||||||
|
Reference in New Issue
Block a user