[feature/backend] add categories param in posts
This commit is contained in:
parent
958e3c2886
commit
be8bf22017
21 changed files with 448 additions and 281 deletions
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
"tss-rocks-be/ent/category"
|
||||
"tss-rocks-be/ent/post"
|
||||
|
||||
"entgo.io/ent"
|
||||
|
@ -28,9 +27,8 @@ type Post struct {
|
|||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the PostQuery when eager-loading is set.
|
||||
Edges PostEdges `json:"edges"`
|
||||
category_posts *int
|
||||
selectValues sql.SelectValues
|
||||
Edges PostEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// PostEdges holds the relations/edges for other nodes in the graph.
|
||||
|
@ -39,8 +37,8 @@ type PostEdges struct {
|
|||
Contents []*PostContent `json:"contents,omitempty"`
|
||||
// Contributors holds the value of the contributors edge.
|
||||
Contributors []*PostContributor `json:"contributors,omitempty"`
|
||||
// Category holds the value of the category edge.
|
||||
Category *Category `json:"category,omitempty"`
|
||||
// Categories holds the value of the categories edge.
|
||||
Categories []*Category `json:"categories,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [3]bool
|
||||
|
@ -64,15 +62,13 @@ func (e PostEdges) ContributorsOrErr() ([]*PostContributor, error) {
|
|||
return nil, &NotLoadedError{edge: "contributors"}
|
||||
}
|
||||
|
||||
// CategoryOrErr returns the Category value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e PostEdges) CategoryOrErr() (*Category, error) {
|
||||
if e.Category != nil {
|
||||
return e.Category, nil
|
||||
} else if e.loadedTypes[2] {
|
||||
return nil, &NotFoundError{label: category.Label}
|
||||
// CategoriesOrErr returns the Categories value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e PostEdges) CategoriesOrErr() ([]*Category, error) {
|
||||
if e.loadedTypes[2] {
|
||||
return e.Categories, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "category"}
|
||||
return nil, &NotLoadedError{edge: "categories"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
|
@ -86,8 +82,6 @@ func (*Post) scanValues(columns []string) ([]any, error) {
|
|||
values[i] = new(sql.NullString)
|
||||
case post.FieldCreatedAt, post.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case post.ForeignKeys[0]: // category_posts
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
|
@ -133,13 +127,6 @@ func (po *Post) assignValues(columns []string, values []any) error {
|
|||
} else if value.Valid {
|
||||
po.UpdatedAt = value.Time
|
||||
}
|
||||
case post.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field category_posts", value)
|
||||
} else if value.Valid {
|
||||
po.category_posts = new(int)
|
||||
*po.category_posts = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
po.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
|
@ -163,9 +150,9 @@ func (po *Post) QueryContributors() *PostContributorQuery {
|
|||
return NewPostClient(po.config).QueryContributors(po)
|
||||
}
|
||||
|
||||
// QueryCategory queries the "category" edge of the Post entity.
|
||||
func (po *Post) QueryCategory() *CategoryQuery {
|
||||
return NewPostClient(po.config).QueryCategory(po)
|
||||
// QueryCategories queries the "categories" edge of the Post entity.
|
||||
func (po *Post) QueryCategories() *CategoryQuery {
|
||||
return NewPostClient(po.config).QueryCategories(po)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Post.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue