mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: delete tag (#1062)
This commit is contained in:
@ -15,6 +15,6 @@ type TagFind struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TagDelete struct {
|
type TagDelete struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
CreatorID int
|
CreatorID int
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
@ -127,29 +126,27 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
g.DELETE("/tag/:tagName", func(c echo.Context) error {
|
g.POST("/tag/delete", func(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
userID, ok := c.Get(getUserIDContextKey()).(int)
|
userID, ok := c.Get(getUserIDContextKey()).(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
return echo.NewHTTPError(http.StatusUnauthorized, "Missing user in session")
|
||||||
}
|
}
|
||||||
|
|
||||||
tagName, err := url.QueryUnescape(c.Param("tagName"))
|
tagDelete := &api.TagDelete{}
|
||||||
if err != nil {
|
if err := json.NewDecoder(c.Request().Body).Decode(tagDelete); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid tag name").SetInternal(err)
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post tag request").SetInternal(err)
|
||||||
} else if tagName == "" {
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Tag name cannot be empty")
|
if tagDelete.Name == "" {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "Tag name shouldn't be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
tagDelete := &api.TagDelete{
|
tagDelete.CreatorID = userID
|
||||||
Name: tagName,
|
|
||||||
CreatorID: userID,
|
|
||||||
}
|
|
||||||
if err := s.Store.DeleteTag(ctx, tagDelete); err != nil {
|
if err := s.Store.DeleteTag(ctx, tagDelete); err != nil {
|
||||||
if common.ErrorCode(err) == common.NotFound {
|
if common.ErrorCode(err) == common.NotFound {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Tag name not found: %s", tagName))
|
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Tag name not found: %s", tagDelete.Name))
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete tag name: %v", tagName)).SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete tag name: %v", tagDelete.Name)).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, true)
|
return c.JSON(http.StatusOK, true)
|
||||||
|
@ -202,7 +202,9 @@ export function upsertTag(tagName: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deleteTag(tagName: string) {
|
export function deleteTag(tagName: string) {
|
||||||
return axios.delete<ResponseObject<string>>(`/api/tag/${encodeURIComponent(tagName)}`);
|
return axios.post<ResponseObject<boolean>>(`/api/tag/delete`, {
|
||||||
|
name: tagName,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRepoStarCount() {
|
export async function getRepoStarCount() {
|
||||||
|
Reference in New Issue
Block a user