feat: update handlers to normalize tags and contributors
Update CreateMediaItem handler: - Normalize tags for display using NormalizeTags() - Normalize contributors for display using NormalizeContributors() - Generate tags_search using NormalizeTagsSearch() - Generate contributors_search using NormalizeContributorsSearch() - Pass search fields to database Update UpdateMediaItem handler: - Same normalization logic as CreateMediaItem - Regenerate search fields on updates Update HandleBulkUpdate handler: - Add tag normalization with punctuation preference - Regenerate search fields when tags/contributors updated All handlers now populate both display and search fields, ensuring consistent normalization throughout the application. Relates to Tags & Contributors Migration Phase 6
This commit is contained in:
@@ -473,6 +473,7 @@ func (h *MediaHandler) HandleBulkUpdate(c echo.Context) error {
|
||||
Genre: existingBook.Genre,
|
||||
Language: existingBook.Language,
|
||||
Tags: existingBook.Tags,
|
||||
TagsSearch: existingBook.TagsSearch,
|
||||
Description: existingBook.Description,
|
||||
Publisher: existingBook.Publisher,
|
||||
CopyrightYear: existingBook.CopyrightYear,
|
||||
@@ -482,6 +483,7 @@ func (h *MediaHandler) HandleBulkUpdate(c echo.Context) error {
|
||||
Asin: existingBook.Asin,
|
||||
DatePublished: existingBook.DatePublished,
|
||||
Contributors: existingBook.Contributors,
|
||||
ContributorsSearch: existingBook.ContributorsSearch,
|
||||
Edition: existingBook.Edition,
|
||||
PageCount: existingBook.PageCount,
|
||||
GoodreadsID: existingBook.GoodreadsID,
|
||||
@@ -502,7 +504,10 @@ func (h *MediaHandler) HandleBulkUpdate(c echo.Context) error {
|
||||
updateParams.Language = pgtype.Text{String: *update.Updates.Language, Valid: true}
|
||||
}
|
||||
if len(update.Updates.Tags) > 0 {
|
||||
updateParams.Tags = update.Updates.Tags
|
||||
normalizedTags := utils.NormalizeTags(update.Updates.Tags)
|
||||
updateParams.Tags = normalizedTags
|
||||
tagsSearch := utils.NormalizeTagsSearch(update.Updates.Tags)
|
||||
updateParams.TagsSearch = tagsSearch
|
||||
}
|
||||
|
||||
_, err = h.db.UpdateMediaItem(c.Request().Context(), updateParams)
|
||||
@@ -893,6 +898,13 @@ func (mh *MediaHandler) CreateMediaItem(c echo.Context) error {
|
||||
req.Tags = utils.NormalizeTags(req.Tags)
|
||||
}
|
||||
|
||||
if len(req.Contributors) > 0 {
|
||||
req.Contributors = utils.NormalizeContributors(req.Contributors)
|
||||
}
|
||||
|
||||
tagsSearch := utils.NormalizeTagsSearch(req.Tags)
|
||||
contributorsSearch := utils.NormalizeContributorsSearch(req.Contributors)
|
||||
|
||||
_, err := mh.db.GetLibrary(c.Request().Context(), pgtype.UUID{Bytes: req.LibraryID, Valid: true})
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
@@ -914,10 +926,12 @@ func (mh *MediaHandler) CreateMediaItem(c echo.Context) error {
|
||||
Series: pgtype.Text{String: req.Series, Valid: req.Series != ""},
|
||||
SeriesNumber: pgtype.Int4{Int32: req.SeriesNumber, Valid: req.SeriesNumber > 0},
|
||||
Tags: req.Tags,
|
||||
TagsSearch: tagsSearch,
|
||||
Asin: pgtype.Text{String: req.ASIN, Valid: req.ASIN != ""},
|
||||
DatePublished: pgtype.Date{Time: parseDate(req.DatePublished), Valid: req.DatePublished != ""},
|
||||
Publisher: pgtype.Text{String: req.Publisher, Valid: req.Publisher != ""},
|
||||
Contributors: req.Contributors,
|
||||
ContributorsSearch: contributorsSearch,
|
||||
AddedByAdminID: user.ID,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -954,6 +968,17 @@ func (mh *MediaHandler) UpdateMediaItem(c echo.Context) error {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
}
|
||||
|
||||
if len(req.Tags) > 0 {
|
||||
req.Tags = utils.NormalizeTags(req.Tags)
|
||||
}
|
||||
|
||||
if len(req.Contributors) > 0 {
|
||||
req.Contributors = utils.NormalizeContributors(req.Contributors)
|
||||
}
|
||||
|
||||
tagsSearch := utils.NormalizeTagsSearch(req.Tags)
|
||||
contributorsSearch := utils.NormalizeContributorsSearch(req.Contributors)
|
||||
|
||||
item, err := mh.db.UpdateMediaItem(c.Request().Context(), database.UpdateMediaItemParams{
|
||||
ID: pgtype.UUID{Bytes: mediaUUID, Valid: true},
|
||||
Title: req.Title,
|
||||
@@ -964,10 +989,12 @@ func (mh *MediaHandler) UpdateMediaItem(c echo.Context) error {
|
||||
Series: pgtype.Text{String: req.Series, Valid: req.Series != ""},
|
||||
SeriesNumber: pgtype.Int4{Int32: req.SeriesNumber, Valid: req.SeriesNumber > 0},
|
||||
Tags: req.Tags,
|
||||
TagsSearch: tagsSearch,
|
||||
Asin: pgtype.Text{String: req.ASIN, Valid: req.ASIN != ""},
|
||||
DatePublished: pgtype.Date{Time: parseDate(req.DatePublished), Valid: req.DatePublished != ""},
|
||||
Publisher: pgtype.Text{String: req.Publisher, Valid: req.Publisher != ""},
|
||||
Contributors: req.Contributors,
|
||||
ContributorsSearch: contributorsSearch,
|
||||
})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user