mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Tag Favoriting (#4728)
* Add missing key unbind --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
type Tag struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Favorite bool `json:"favorite,omitempty"`
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
Parents []string `json:"parents,omitempty"`
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
type Tag struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Favorite bool `json:"favorite"`
|
||||
Description string `json:"description"`
|
||||
IgnoreAutoTag bool `json:"ignore_auto_tag"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
@@ -24,6 +25,7 @@ func NewTag() Tag {
|
||||
type TagPartial struct {
|
||||
Name OptionalString
|
||||
Description OptionalString
|
||||
Favorite OptionalBool
|
||||
IgnoreAutoTag OptionalBool
|
||||
CreatedAt OptionalTime
|
||||
UpdatedAt OptionalTime
|
||||
|
||||
@@ -8,6 +8,8 @@ type TagFilterType struct {
|
||||
Name *StringCriterionInput `json:"name"`
|
||||
// Filter by tag aliases
|
||||
Aliases *StringCriterionInput `json:"aliases"`
|
||||
// Filter by tag favorites
|
||||
Favorite *bool `json:"favorite"`
|
||||
// Filter by tag description
|
||||
Description *StringCriterionInput `json:"description"`
|
||||
// Filter to only include tags missing this property
|
||||
|
||||
@@ -1034,6 +1034,7 @@ type TagQueryInput struct {
|
||||
// Filter to search name - assumes like query unless quoted
|
||||
Name *string `json:"name,omitempty"`
|
||||
// Filter to category ID
|
||||
IsFavorite *bool `json:"is_favorite,omitempty"`
|
||||
CategoryID *string `json:"category_id,omitempty"`
|
||||
Page int `json:"page"`
|
||||
PerPage int `json:"per_page"`
|
||||
|
||||
@@ -30,7 +30,7 @@ const (
|
||||
dbConnTimeout = 30
|
||||
)
|
||||
|
||||
var appSchemaVersion uint = 56
|
||||
var appSchemaVersion uint = 57
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var migrationsBox embed.FS
|
||||
|
||||
1
pkg/sqlite/migrations/57_tag_favorite.up.sql
Normal file
1
pkg/sqlite/migrations/57_tag_favorite.up.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE `tags` ADD COLUMN `favorite` boolean not null default '0';
|
||||
@@ -1480,7 +1480,10 @@ func createPerformers(ctx context.Context, n int, o int) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getTagBoolValue(index int) bool {
|
||||
index = index % 2
|
||||
return index == 1
|
||||
}
|
||||
func getTagStringValue(index int, field string) string {
|
||||
return "tag_" + strconv.FormatInt(int64(index), 10) + "_" + field
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ const (
|
||||
type tagRow struct {
|
||||
ID int `db:"id" goqu:"skipinsert"`
|
||||
Name null.String `db:"name"` // TODO: make schema non-nullable
|
||||
Favorite bool `db:"favorite"`
|
||||
Description zero.String `db:"description"`
|
||||
IgnoreAutoTag bool `db:"ignore_auto_tag"`
|
||||
CreatedAt Timestamp `db:"created_at"`
|
||||
@@ -41,6 +42,7 @@ type tagRow struct {
|
||||
func (r *tagRow) fromTag(o models.Tag) {
|
||||
r.ID = o.ID
|
||||
r.Name = null.StringFrom(o.Name)
|
||||
r.Favorite = o.Favorite
|
||||
r.Description = zero.StringFrom(o.Description)
|
||||
r.IgnoreAutoTag = o.IgnoreAutoTag
|
||||
r.CreatedAt = Timestamp{Timestamp: o.CreatedAt}
|
||||
@@ -51,6 +53,7 @@ func (r *tagRow) resolve() *models.Tag {
|
||||
ret := &models.Tag{
|
||||
ID: r.ID,
|
||||
Name: r.Name.String,
|
||||
Favorite: r.Favorite,
|
||||
Description: r.Description.String,
|
||||
IgnoreAutoTag: r.IgnoreAutoTag,
|
||||
CreatedAt: r.CreatedAt.Timestamp,
|
||||
@@ -81,6 +84,7 @@ type tagRowRecord struct {
|
||||
func (r *tagRowRecord) fromPartial(o models.TagPartial) {
|
||||
r.setString("name", o.Name)
|
||||
r.setNullString("description", o.Description)
|
||||
r.setBool("favorite", o.Favorite)
|
||||
r.setBool("ignore_auto_tag", o.IgnoreAutoTag)
|
||||
r.setTimestamp("created_at", o.CreatedAt)
|
||||
r.setTimestamp("updated_at", o.UpdatedAt)
|
||||
@@ -498,6 +502,7 @@ func (qb *TagStore) makeFilter(ctx context.Context, tagFilter *models.TagFilterT
|
||||
query.handleCriterion(ctx, stringCriterionHandler(tagFilter.Name, tagTable+".name"))
|
||||
query.handleCriterion(ctx, tagAliasCriterionHandler(qb, tagFilter.Aliases))
|
||||
|
||||
query.handleCriterion(ctx, boolCriterionHandler(tagFilter.Favorite, tagTable+".favorite", nil))
|
||||
query.handleCriterion(ctx, stringCriterionHandler(tagFilter.Description, tagTable+".description"))
|
||||
query.handleCriterion(ctx, boolCriterionHandler(tagFilter.IgnoreAutoTag, tagTable+".ignore_auto_tag", nil))
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ func ToJSON(ctx context.Context, reader FinderAliasImageGetter, tag *models.Tag)
|
||||
newTagJSON := jsonschema.Tag{
|
||||
Name: tag.Name,
|
||||
Description: tag.Description,
|
||||
Favorite: tag.Favorite,
|
||||
IgnoreAutoTag: tag.IgnoreAutoTag,
|
||||
CreatedAt: json.JSONTime{Time: tag.CreatedAt},
|
||||
UpdatedAt: json.JSONTime{Time: tag.UpdatedAt},
|
||||
|
||||
@@ -37,6 +37,7 @@ func createTag(id int) models.Tag {
|
||||
return models.Tag{
|
||||
ID: id,
|
||||
Name: tagName,
|
||||
Favorite: true,
|
||||
Description: description,
|
||||
IgnoreAutoTag: autoTagIgnored,
|
||||
CreatedAt: createTime,
|
||||
@@ -47,6 +48,7 @@ func createTag(id int) models.Tag {
|
||||
func createJSONTag(aliases []string, image string, parents []string) *jsonschema.Tag {
|
||||
return &jsonschema.Tag{
|
||||
Name: tagName,
|
||||
Favorite: true,
|
||||
Description: description,
|
||||
Aliases: aliases,
|
||||
IgnoreAutoTag: autoTagIgnored,
|
||||
|
||||
@@ -39,6 +39,7 @@ func (i *Importer) PreImport(ctx context.Context) error {
|
||||
i.tag = models.Tag{
|
||||
Name: i.Input.Name,
|
||||
Description: i.Input.Description,
|
||||
Favorite: i.Input.Favorite,
|
||||
IgnoreAutoTag: i.Input.IgnoreAutoTag,
|
||||
CreatedAt: i.Input.CreatedAt.GetTime(),
|
||||
UpdatedAt: i.Input.UpdatedAt.GetTime(),
|
||||
|
||||
Reference in New Issue
Block a user