[feature/backend] add categories param in posts

This commit is contained in:
CDN 2025-02-22 02:42:55 +08:00
parent 958e3c2886
commit be8bf22017
Signed by: CDN
GPG key ID: 0C656827F9F80080
21 changed files with 448 additions and 281 deletions

View file

@ -6578,8 +6578,9 @@ type PostMutation struct {
contributors map[int]struct{}
removedcontributors map[int]struct{}
clearedcontributors bool
category *int
clearedcategory bool
categories map[int]struct{}
removedcategories map[int]struct{}
clearedcategories bool
done bool
oldValue func(context.Context) (*Post, error)
predicates []predicate.Post
@ -6935,43 +6936,58 @@ func (m *PostMutation) ResetContributors() {
m.removedcontributors = nil
}
// SetCategoryID sets the "category" edge to the Category entity by id.
func (m *PostMutation) SetCategoryID(id int) {
m.category = &id
// AddCategoryIDs adds the "categories" edge to the Category entity by ids.
func (m *PostMutation) AddCategoryIDs(ids ...int) {
if m.categories == nil {
m.categories = make(map[int]struct{})
}
for i := range ids {
m.categories[ids[i]] = struct{}{}
}
}
// ClearCategory clears the "category" edge to the Category entity.
func (m *PostMutation) ClearCategory() {
m.clearedcategory = true
// ClearCategories clears the "categories" edge to the Category entity.
func (m *PostMutation) ClearCategories() {
m.clearedcategories = true
}
// CategoryCleared reports if the "category" edge to the Category entity was cleared.
func (m *PostMutation) CategoryCleared() bool {
return m.clearedcategory
// CategoriesCleared reports if the "categories" edge to the Category entity was cleared.
func (m *PostMutation) CategoriesCleared() bool {
return m.clearedcategories
}
// CategoryID returns the "category" edge ID in the mutation.
func (m *PostMutation) CategoryID() (id int, exists bool) {
if m.category != nil {
return *m.category, true
// RemoveCategoryIDs removes the "categories" edge to the Category entity by IDs.
func (m *PostMutation) RemoveCategoryIDs(ids ...int) {
if m.removedcategories == nil {
m.removedcategories = make(map[int]struct{})
}
for i := range ids {
delete(m.categories, ids[i])
m.removedcategories[ids[i]] = struct{}{}
}
}
// RemovedCategories returns the removed IDs of the "categories" edge to the Category entity.
func (m *PostMutation) RemovedCategoriesIDs() (ids []int) {
for id := range m.removedcategories {
ids = append(ids, id)
}
return
}
// CategoryIDs returns the "category" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CategoryID instead. It exists only for internal usage by the builders.
func (m *PostMutation) CategoryIDs() (ids []int) {
if id := m.category; id != nil {
ids = append(ids, *id)
// CategoriesIDs returns the "categories" edge IDs in the mutation.
func (m *PostMutation) CategoriesIDs() (ids []int) {
for id := range m.categories {
ids = append(ids, id)
}
return
}
// ResetCategory resets all changes to the "category" edge.
func (m *PostMutation) ResetCategory() {
m.category = nil
m.clearedcategory = false
// ResetCategories resets all changes to the "categories" edge.
func (m *PostMutation) ResetCategories() {
m.categories = nil
m.clearedcategories = false
m.removedcategories = nil
}
// Where appends a list predicates to the PostMutation builder.
@ -7165,8 +7181,8 @@ func (m *PostMutation) AddedEdges() []string {
if m.contributors != nil {
edges = append(edges, post.EdgeContributors)
}
if m.category != nil {
edges = append(edges, post.EdgeCategory)
if m.categories != nil {
edges = append(edges, post.EdgeCategories)
}
return edges
}
@ -7187,10 +7203,12 @@ func (m *PostMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case post.EdgeCategory:
if id := m.category; id != nil {
return []ent.Value{*id}
case post.EdgeCategories:
ids := make([]ent.Value, 0, len(m.categories))
for id := range m.categories {
ids = append(ids, id)
}
return ids
}
return nil
}
@ -7204,6 +7222,9 @@ func (m *PostMutation) RemovedEdges() []string {
if m.removedcontributors != nil {
edges = append(edges, post.EdgeContributors)
}
if m.removedcategories != nil {
edges = append(edges, post.EdgeCategories)
}
return edges
}
@ -7223,6 +7244,12 @@ func (m *PostMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case post.EdgeCategories:
ids := make([]ent.Value, 0, len(m.removedcategories))
for id := range m.removedcategories {
ids = append(ids, id)
}
return ids
}
return nil
}
@ -7236,8 +7263,8 @@ func (m *PostMutation) ClearedEdges() []string {
if m.clearedcontributors {
edges = append(edges, post.EdgeContributors)
}
if m.clearedcategory {
edges = append(edges, post.EdgeCategory)
if m.clearedcategories {
edges = append(edges, post.EdgeCategories)
}
return edges
}
@ -7250,8 +7277,8 @@ func (m *PostMutation) EdgeCleared(name string) bool {
return m.clearedcontents
case post.EdgeContributors:
return m.clearedcontributors
case post.EdgeCategory:
return m.clearedcategory
case post.EdgeCategories:
return m.clearedcategories
}
return false
}
@ -7260,9 +7287,6 @@ func (m *PostMutation) EdgeCleared(name string) bool {
// if that edge is not defined in the schema.
func (m *PostMutation) ClearEdge(name string) error {
switch name {
case post.EdgeCategory:
m.ClearCategory()
return nil
}
return fmt.Errorf("unknown Post unique edge %s", name)
}
@ -7277,8 +7301,8 @@ func (m *PostMutation) ResetEdge(name string) error {
case post.EdgeContributors:
m.ResetContributors()
return nil
case post.EdgeCategory:
m.ResetCategory()
case post.EdgeCategories:
m.ResetCategories()
return nil
}
return fmt.Errorf("unknown Post edge %s", name)