diff --git a/ent/client.go b/ent/client.go index d8f8762..582cebc 100644 --- a/ent/client.go +++ b/ent/client.go @@ -12,6 +12,7 @@ import ( "api/ent/card" "api/ent/group" + "api/ent/ma" "api/ent/ue" "api/ent/user" @@ -30,6 +31,8 @@ type Client struct { Card *CardClient // Group is the client for interacting with the Group builders. Group *GroupClient + // Ma is the client for interacting with the Ma builders. + Ma *MaClient // Ue is the client for interacting with the Ue builders. Ue *UeClient // User is the client for interacting with the User builders. @@ -49,6 +52,7 @@ func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) c.Card = NewCardClient(c.config) c.Group = NewGroupClient(c.config) + c.Ma = NewMaClient(c.config) c.Ue = NewUeClient(c.config) c.User = NewUserClient(c.config) } @@ -135,6 +139,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { config: cfg, Card: NewCardClient(cfg), Group: NewGroupClient(cfg), + Ma: NewMaClient(cfg), Ue: NewUeClient(cfg), User: NewUserClient(cfg), }, nil @@ -158,6 +163,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) config: cfg, Card: NewCardClient(cfg), Group: NewGroupClient(cfg), + Ma: NewMaClient(cfg), Ue: NewUeClient(cfg), User: NewUserClient(cfg), }, nil @@ -190,6 +196,7 @@ func (c *Client) Close() error { func (c *Client) Use(hooks ...Hook) { c.Card.Use(hooks...) c.Group.Use(hooks...) + c.Ma.Use(hooks...) c.Ue.Use(hooks...) c.User.Use(hooks...) } @@ -199,6 +206,7 @@ func (c *Client) Use(hooks ...Hook) { func (c *Client) Intercept(interceptors ...Interceptor) { c.Card.Intercept(interceptors...) c.Group.Intercept(interceptors...) + c.Ma.Intercept(interceptors...) c.Ue.Intercept(interceptors...) c.User.Intercept(interceptors...) } @@ -210,6 +218,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.Card.mutate(ctx, m) case *GroupMutation: return c.Group.mutate(ctx, m) + case *MaMutation: + return c.Ma.mutate(ctx, m) case *UeMutation: return c.Ue.mutate(ctx, m) case *UserMutation: @@ -487,6 +497,140 @@ func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, erro } } +// MaClient is a client for the Ma schema. +type MaClient struct { + config +} + +// NewMaClient returns a client for the Ma from the given config. +func NewMaClient(c config) *MaClient { + return &MaClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `ma.Hooks(f(g(h())))`. +func (c *MaClient) Use(hooks ...Hook) { + c.hooks.Ma = append(c.hooks.Ma, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `ma.Intercept(f(g(h())))`. +func (c *MaClient) Intercept(interceptors ...Interceptor) { + c.inters.Ma = append(c.inters.Ma, interceptors...) +} + +// Create returns a builder for creating a Ma entity. +func (c *MaClient) Create() *MaCreate { + mutation := newMaMutation(c.config, OpCreate) + return &MaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Ma entities. +func (c *MaClient) CreateBulk(builders ...*MaCreate) *MaCreateBulk { + return &MaCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Ma. +func (c *MaClient) Update() *MaUpdate { + mutation := newMaMutation(c.config, OpUpdate) + return &MaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *MaClient) UpdateOne(m *Ma) *MaUpdateOne { + mutation := newMaMutation(c.config, OpUpdateOne, withMa(m)) + return &MaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *MaClient) UpdateOneID(id int) *MaUpdateOne { + mutation := newMaMutation(c.config, OpUpdateOne, withMaID(id)) + return &MaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Ma. +func (c *MaClient) Delete() *MaDelete { + mutation := newMaMutation(c.config, OpDelete) + return &MaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *MaClient) DeleteOne(m *Ma) *MaDeleteOne { + return c.DeleteOneID(m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *MaClient) DeleteOneID(id int) *MaDeleteOne { + builder := c.Delete().Where(ma.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &MaDeleteOne{builder} +} + +// Query returns a query builder for Ma. +func (c *MaClient) Query() *MaQuery { + return &MaQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeMa}, + inters: c.Interceptors(), + } +} + +// Get returns a Ma entity by its id. +func (c *MaClient) Get(ctx context.Context, id int) (*Ma, error) { + return c.Query().Where(ma.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *MaClient) GetX(ctx context.Context, id int) *Ma { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryOwner queries the owner edge of a Ma. +func (c *MaClient) QueryOwner(m *Ma) *UserQuery { + query := (&UserClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := m.ID + step := sqlgraph.NewStep( + sqlgraph.From(ma.Table, ma.FieldID, id), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ma.OwnerTable, ma.OwnerColumn), + ) + fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *MaClient) Hooks() []Hook { + return c.hooks.Ma +} + +// Interceptors returns the client interceptors. +func (c *MaClient) Interceptors() []Interceptor { + return c.inters.Ma +} + +func (c *MaClient) mutate(ctx context.Context, m *MaMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Ma mutation op: %q", m.Op()) + } +} + // UeClient is a client for the Ue schema. type UeClient struct { config @@ -746,6 +890,22 @@ func (c *UserClient) QueryUe(u *User) *UeQuery { return query } +// QueryMa queries the ma edge of a User. +func (c *UserClient) QueryMa(u *User) *MaQuery { + query := (&MaClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := u.ID + step := sqlgraph.NewStep( + sqlgraph.From(user.Table, user.FieldID, id), + sqlgraph.To(ma.Table, ma.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.MaTable, user.MaColumn), + ) + fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *UserClient) Hooks() []Hook { return c.hooks.User @@ -774,9 +934,9 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) // hooks and interceptors per client, for fast access. type ( hooks struct { - Card, Group, Ue, User []ent.Hook + Card, Group, Ma, Ue, User []ent.Hook } inters struct { - Card, Group, Ue, User []ent.Interceptor + Card, Group, Ma, Ue, User []ent.Interceptor } ) diff --git a/ent/ent.go b/ent/ent.go index 388e8c8..f91e530 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -5,6 +5,7 @@ package ent import ( "api/ent/card" "api/ent/group" + "api/ent/ma" "api/ent/ue" "api/ent/user" "context" @@ -78,6 +79,7 @@ func checkColumn(table, column string) error { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ card.Table: card.ValidColumn, group.Table: group.ValidColumn, + ma.Table: ma.ValidColumn, ue.Table: ue.ValidColumn, user.Table: user.ValidColumn, }) diff --git a/ent/hook/hook.go b/ent/hook/hook.go index 269aa33..c4e9057 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -32,6 +32,18 @@ func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m) } +// The MaFunc type is an adapter to allow the use of ordinary +// function as Ma mutator. +type MaFunc func(context.Context, *ent.MaMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f MaFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.MaMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaMutation", m) +} + // The UeFunc type is an adapter to allow the use of ordinary // function as Ue mutator. type UeFunc func(context.Context, *ent.UeMutation) (ent.Value, error) diff --git a/ent/ma.go b/ent/ma.go new file mode 100644 index 0000000..8d5e30d --- /dev/null +++ b/ent/ma.go @@ -0,0 +1,290 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "api/ent/ma" + "api/ent/user" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// Ma is the model entity for the Ma schema. +type Ma struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // Password holds the value of the "password" field. + Password string `json:"-"` + // Token holds the value of the "token" field. + Token string `json:"-"` + // Limit holds the value of the "limit" field. + Limit bool `json:"limit,omitempty"` + // Count holds the value of the "count" field. + Count int `json:"count,omitempty"` + // Handle holds the value of the "handle" field. + Handle string `json:"handle,omitempty"` + // Text holds the value of the "text" field. + Text string `json:"text,omitempty"` + // Did holds the value of the "did" field. + Did string `json:"did,omitempty"` + // Avatar holds the value of the "avatar" field. + Avatar string `json:"avatar,omitempty"` + // Cid holds the value of the "cid" field. + Cid string `json:"cid,omitempty"` + // URI holds the value of the "uri" field. + URI string `json:"uri,omitempty"` + // Rkey holds the value of the "rkey" field. + Rkey string `json:"rkey,omitempty"` + // BskyURL holds the value of the "bsky_url" field. + BskyURL string `json:"bsky_url,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the MaQuery when eager-loading is set. + Edges MaEdges `json:"edges"` + user_ma *int + selectValues sql.SelectValues +} + +// MaEdges holds the relations/edges for other nodes in the graph. +type MaEdges struct { + // Owner holds the value of the owner edge. + Owner *User `json:"owner,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// OwnerOrErr returns the Owner value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e MaEdges) OwnerOrErr() (*User, error) { + if e.loadedTypes[0] { + if e.Owner == nil { + // Edge was loaded but was not found. + return nil, &NotFoundError{label: user.Label} + } + return e.Owner, nil + } + return nil, &NotLoadedError{edge: "owner"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Ma) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case ma.FieldLimit: + values[i] = new(sql.NullBool) + case ma.FieldID, ma.FieldCount: + values[i] = new(sql.NullInt64) + case ma.FieldPassword, ma.FieldToken, ma.FieldHandle, ma.FieldText, ma.FieldDid, ma.FieldAvatar, ma.FieldCid, ma.FieldURI, ma.FieldRkey, ma.FieldBskyURL: + values[i] = new(sql.NullString) + case ma.FieldUpdatedAt, ma.FieldCreatedAt: + values[i] = new(sql.NullTime) + case ma.ForeignKeys[0]: // user_ma + values[i] = new(sql.NullInt64) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Ma fields. +func (m *Ma) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case ma.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + m.ID = int(value.Int64) + case ma.FieldPassword: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value.Valid { + m.Password = value.String + } + case ma.FieldToken: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field token", values[i]) + } else if value.Valid { + m.Token = value.String + } + case ma.FieldLimit: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field limit", values[i]) + } else if value.Valid { + m.Limit = value.Bool + } + case ma.FieldCount: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field count", values[i]) + } else if value.Valid { + m.Count = int(value.Int64) + } + case ma.FieldHandle: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field handle", values[i]) + } else if value.Valid { + m.Handle = value.String + } + case ma.FieldText: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field text", values[i]) + } else if value.Valid { + m.Text = value.String + } + case ma.FieldDid: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field did", values[i]) + } else if value.Valid { + m.Did = value.String + } + case ma.FieldAvatar: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field avatar", values[i]) + } else if value.Valid { + m.Avatar = value.String + } + case ma.FieldCid: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field cid", values[i]) + } else if value.Valid { + m.Cid = value.String + } + case ma.FieldURI: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field uri", values[i]) + } else if value.Valid { + m.URI = value.String + } + case ma.FieldRkey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field rkey", values[i]) + } else if value.Valid { + m.Rkey = value.String + } + case ma.FieldBskyURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field bsky_url", values[i]) + } else if value.Valid { + m.BskyURL = value.String + } + case ma.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + m.UpdatedAt = value.Time + } + case ma.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + m.CreatedAt = value.Time + } + case ma.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field user_ma", value) + } else if value.Valid { + m.user_ma = new(int) + *m.user_ma = int(value.Int64) + } + default: + m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Ma. +// This includes values selected through modifiers, order, etc. +func (m *Ma) Value(name string) (ent.Value, error) { + return m.selectValues.Get(name) +} + +// QueryOwner queries the "owner" edge of the Ma entity. +func (m *Ma) QueryOwner() *UserQuery { + return NewMaClient(m.config).QueryOwner(m) +} + +// Update returns a builder for updating this Ma. +// Note that you need to call Ma.Unwrap() before calling this method if this Ma +// was returned from a transaction, and the transaction was committed or rolled back. +func (m *Ma) Update() *MaUpdateOne { + return NewMaClient(m.config).UpdateOne(m) +} + +// Unwrap unwraps the Ma entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (m *Ma) Unwrap() *Ma { + _tx, ok := m.config.driver.(*txDriver) + if !ok { + panic("ent: Ma is not a transactional entity") + } + m.config.driver = _tx.drv + return m +} + +// String implements the fmt.Stringer. +func (m *Ma) String() string { + var builder strings.Builder + builder.WriteString("Ma(") + builder.WriteString(fmt.Sprintf("id=%v, ", m.ID)) + builder.WriteString("password=") + builder.WriteString(", ") + builder.WriteString("token=") + builder.WriteString(", ") + builder.WriteString("limit=") + builder.WriteString(fmt.Sprintf("%v", m.Limit)) + builder.WriteString(", ") + builder.WriteString("count=") + builder.WriteString(fmt.Sprintf("%v", m.Count)) + builder.WriteString(", ") + builder.WriteString("handle=") + builder.WriteString(m.Handle) + builder.WriteString(", ") + builder.WriteString("text=") + builder.WriteString(m.Text) + builder.WriteString(", ") + builder.WriteString("did=") + builder.WriteString(m.Did) + builder.WriteString(", ") + builder.WriteString("avatar=") + builder.WriteString(m.Avatar) + builder.WriteString(", ") + builder.WriteString("cid=") + builder.WriteString(m.Cid) + builder.WriteString(", ") + builder.WriteString("uri=") + builder.WriteString(m.URI) + builder.WriteString(", ") + builder.WriteString("rkey=") + builder.WriteString(m.Rkey) + builder.WriteString(", ") + builder.WriteString("bsky_url=") + builder.WriteString(m.BskyURL) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(m.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// Mas is a parsable slice of Ma. +type Mas []*Ma diff --git a/ent/ma/ma.go b/ent/ma/ma.go new file mode 100644 index 0000000..45f2dff --- /dev/null +++ b/ent/ma/ma.go @@ -0,0 +1,197 @@ +// Code generated by ent, DO NOT EDIT. + +package ma + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the ma type in the database. + Label = "ma" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldPassword holds the string denoting the password field in the database. + FieldPassword = "password" + // FieldToken holds the string denoting the token field in the database. + FieldToken = "token" + // FieldLimit holds the string denoting the limit field in the database. + FieldLimit = "limit" + // FieldCount holds the string denoting the count field in the database. + FieldCount = "count" + // FieldHandle holds the string denoting the handle field in the database. + FieldHandle = "handle" + // FieldText holds the string denoting the text field in the database. + FieldText = "text" + // FieldDid holds the string denoting the did field in the database. + FieldDid = "did" + // FieldAvatar holds the string denoting the avatar field in the database. + FieldAvatar = "avatar" + // FieldCid holds the string denoting the cid field in the database. + FieldCid = "cid" + // FieldURI holds the string denoting the uri field in the database. + FieldURI = "uri" + // FieldRkey holds the string denoting the rkey field in the database. + FieldRkey = "rkey" + // FieldBskyURL holds the string denoting the bsky_url field in the database. + FieldBskyURL = "bsky_url" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // EdgeOwner holds the string denoting the owner edge name in mutations. + EdgeOwner = "owner" + // Table holds the table name of the ma in the database. + Table = "mas" + // OwnerTable is the table that holds the owner relation/edge. + OwnerTable = "mas" + // OwnerInverseTable is the table name for the User entity. + // It exists in this package in order to avoid circular dependency with the "user" package. + OwnerInverseTable = "users" + // OwnerColumn is the table column denoting the owner relation/edge. + OwnerColumn = "user_ma" +) + +// Columns holds all SQL columns for ma fields. +var Columns = []string{ + FieldID, + FieldPassword, + FieldToken, + FieldLimit, + FieldCount, + FieldHandle, + FieldText, + FieldDid, + FieldAvatar, + FieldCid, + FieldURI, + FieldRkey, + FieldBskyURL, + FieldUpdatedAt, + FieldCreatedAt, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "mas" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "user_ma", +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + for i := range ForeignKeys { + if column == ForeignKeys[i] { + return true + } + } + return false +} + +var ( + // PasswordValidator is a validator for the "password" field. It is called by the builders before save. + PasswordValidator func(string) error + // DefaultLimit holds the default value on creation for the "limit" field. + DefaultLimit bool + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the Ma queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByPassword orders the results by the password field. +func ByPassword(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPassword, opts...).ToFunc() +} + +// ByToken orders the results by the token field. +func ByToken(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldToken, opts...).ToFunc() +} + +// ByLimit orders the results by the limit field. +func ByLimit(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLimit, opts...).ToFunc() +} + +// ByCount orders the results by the count field. +func ByCount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCount, opts...).ToFunc() +} + +// ByHandle orders the results by the handle field. +func ByHandle(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldHandle, opts...).ToFunc() +} + +// ByText orders the results by the text field. +func ByText(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldText, opts...).ToFunc() +} + +// ByDid orders the results by the did field. +func ByDid(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDid, opts...).ToFunc() +} + +// ByAvatar orders the results by the avatar field. +func ByAvatar(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAvatar, opts...).ToFunc() +} + +// ByCid orders the results by the cid field. +func ByCid(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCid, opts...).ToFunc() +} + +// ByURI orders the results by the uri field. +func ByURI(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldURI, opts...).ToFunc() +} + +// ByRkey orders the results by the rkey field. +func ByRkey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRkey, opts...).ToFunc() +} + +// ByBskyURL orders the results by the bsky_url field. +func ByBskyURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBskyURL, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByOwnerField orders the results by owner field. +func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...)) + } +} +func newOwnerStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(OwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn), + ) +} diff --git a/ent/ma/where.go b/ent/ma/where.go new file mode 100644 index 0000000..be4f021 --- /dev/null +++ b/ent/ma/where.go @@ -0,0 +1,1091 @@ +// Code generated by ent, DO NOT EDIT. + +package ma + +import ( + "api/ent/predicate" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldID, id)) +} + +// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. +func Password(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldPassword, v)) +} + +// Token applies equality check predicate on the "token" field. It's identical to TokenEQ. +func Token(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldToken, v)) +} + +// Limit applies equality check predicate on the "limit" field. It's identical to LimitEQ. +func Limit(v bool) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldLimit, v)) +} + +// Count applies equality check predicate on the "count" field. It's identical to CountEQ. +func Count(v int) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldCount, v)) +} + +// Handle applies equality check predicate on the "handle" field. It's identical to HandleEQ. +func Handle(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldHandle, v)) +} + +// Text applies equality check predicate on the "text" field. It's identical to TextEQ. +func Text(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldText, v)) +} + +// Did applies equality check predicate on the "did" field. It's identical to DidEQ. +func Did(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldDid, v)) +} + +// Avatar applies equality check predicate on the "avatar" field. It's identical to AvatarEQ. +func Avatar(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldAvatar, v)) +} + +// Cid applies equality check predicate on the "cid" field. It's identical to CidEQ. +func Cid(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldCid, v)) +} + +// URI applies equality check predicate on the "uri" field. It's identical to URIEQ. +func URI(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldURI, v)) +} + +// Rkey applies equality check predicate on the "rkey" field. It's identical to RkeyEQ. +func Rkey(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldRkey, v)) +} + +// BskyURL applies equality check predicate on the "bsky_url" field. It's identical to BskyURLEQ. +func BskyURL(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldBskyURL, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldCreatedAt, v)) +} + +// PasswordEQ applies the EQ predicate on the "password" field. +func PasswordEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldPassword, v)) +} + +// PasswordNEQ applies the NEQ predicate on the "password" field. +func PasswordNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldPassword, v)) +} + +// PasswordIn applies the In predicate on the "password" field. +func PasswordIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldPassword, vs...)) +} + +// PasswordNotIn applies the NotIn predicate on the "password" field. +func PasswordNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldPassword, vs...)) +} + +// PasswordGT applies the GT predicate on the "password" field. +func PasswordGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldPassword, v)) +} + +// PasswordGTE applies the GTE predicate on the "password" field. +func PasswordGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldPassword, v)) +} + +// PasswordLT applies the LT predicate on the "password" field. +func PasswordLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldPassword, v)) +} + +// PasswordLTE applies the LTE predicate on the "password" field. +func PasswordLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldPassword, v)) +} + +// PasswordContains applies the Contains predicate on the "password" field. +func PasswordContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldPassword, v)) +} + +// PasswordHasPrefix applies the HasPrefix predicate on the "password" field. +func PasswordHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldPassword, v)) +} + +// PasswordHasSuffix applies the HasSuffix predicate on the "password" field. +func PasswordHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldPassword, v)) +} + +// PasswordEqualFold applies the EqualFold predicate on the "password" field. +func PasswordEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldPassword, v)) +} + +// PasswordContainsFold applies the ContainsFold predicate on the "password" field. +func PasswordContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldPassword, v)) +} + +// TokenEQ applies the EQ predicate on the "token" field. +func TokenEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldToken, v)) +} + +// TokenNEQ applies the NEQ predicate on the "token" field. +func TokenNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldToken, v)) +} + +// TokenIn applies the In predicate on the "token" field. +func TokenIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldToken, vs...)) +} + +// TokenNotIn applies the NotIn predicate on the "token" field. +func TokenNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldToken, vs...)) +} + +// TokenGT applies the GT predicate on the "token" field. +func TokenGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldToken, v)) +} + +// TokenGTE applies the GTE predicate on the "token" field. +func TokenGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldToken, v)) +} + +// TokenLT applies the LT predicate on the "token" field. +func TokenLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldToken, v)) +} + +// TokenLTE applies the LTE predicate on the "token" field. +func TokenLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldToken, v)) +} + +// TokenContains applies the Contains predicate on the "token" field. +func TokenContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldToken, v)) +} + +// TokenHasPrefix applies the HasPrefix predicate on the "token" field. +func TokenHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldToken, v)) +} + +// TokenHasSuffix applies the HasSuffix predicate on the "token" field. +func TokenHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldToken, v)) +} + +// TokenIsNil applies the IsNil predicate on the "token" field. +func TokenIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldToken)) +} + +// TokenNotNil applies the NotNil predicate on the "token" field. +func TokenNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldToken)) +} + +// TokenEqualFold applies the EqualFold predicate on the "token" field. +func TokenEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldToken, v)) +} + +// TokenContainsFold applies the ContainsFold predicate on the "token" field. +func TokenContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldToken, v)) +} + +// LimitEQ applies the EQ predicate on the "limit" field. +func LimitEQ(v bool) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldLimit, v)) +} + +// LimitNEQ applies the NEQ predicate on the "limit" field. +func LimitNEQ(v bool) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldLimit, v)) +} + +// LimitIsNil applies the IsNil predicate on the "limit" field. +func LimitIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldLimit)) +} + +// LimitNotNil applies the NotNil predicate on the "limit" field. +func LimitNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldLimit)) +} + +// CountEQ applies the EQ predicate on the "count" field. +func CountEQ(v int) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldCount, v)) +} + +// CountNEQ applies the NEQ predicate on the "count" field. +func CountNEQ(v int) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldCount, v)) +} + +// CountIn applies the In predicate on the "count" field. +func CountIn(vs ...int) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldCount, vs...)) +} + +// CountNotIn applies the NotIn predicate on the "count" field. +func CountNotIn(vs ...int) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldCount, vs...)) +} + +// CountGT applies the GT predicate on the "count" field. +func CountGT(v int) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldCount, v)) +} + +// CountGTE applies the GTE predicate on the "count" field. +func CountGTE(v int) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldCount, v)) +} + +// CountLT applies the LT predicate on the "count" field. +func CountLT(v int) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldCount, v)) +} + +// CountLTE applies the LTE predicate on the "count" field. +func CountLTE(v int) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldCount, v)) +} + +// CountIsNil applies the IsNil predicate on the "count" field. +func CountIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldCount)) +} + +// CountNotNil applies the NotNil predicate on the "count" field. +func CountNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldCount)) +} + +// HandleEQ applies the EQ predicate on the "handle" field. +func HandleEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldHandle, v)) +} + +// HandleNEQ applies the NEQ predicate on the "handle" field. +func HandleNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldHandle, v)) +} + +// HandleIn applies the In predicate on the "handle" field. +func HandleIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldHandle, vs...)) +} + +// HandleNotIn applies the NotIn predicate on the "handle" field. +func HandleNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldHandle, vs...)) +} + +// HandleGT applies the GT predicate on the "handle" field. +func HandleGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldHandle, v)) +} + +// HandleGTE applies the GTE predicate on the "handle" field. +func HandleGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldHandle, v)) +} + +// HandleLT applies the LT predicate on the "handle" field. +func HandleLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldHandle, v)) +} + +// HandleLTE applies the LTE predicate on the "handle" field. +func HandleLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldHandle, v)) +} + +// HandleContains applies the Contains predicate on the "handle" field. +func HandleContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldHandle, v)) +} + +// HandleHasPrefix applies the HasPrefix predicate on the "handle" field. +func HandleHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldHandle, v)) +} + +// HandleHasSuffix applies the HasSuffix predicate on the "handle" field. +func HandleHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldHandle, v)) +} + +// HandleIsNil applies the IsNil predicate on the "handle" field. +func HandleIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldHandle)) +} + +// HandleNotNil applies the NotNil predicate on the "handle" field. +func HandleNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldHandle)) +} + +// HandleEqualFold applies the EqualFold predicate on the "handle" field. +func HandleEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldHandle, v)) +} + +// HandleContainsFold applies the ContainsFold predicate on the "handle" field. +func HandleContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldHandle, v)) +} + +// TextEQ applies the EQ predicate on the "text" field. +func TextEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldText, v)) +} + +// TextNEQ applies the NEQ predicate on the "text" field. +func TextNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldText, v)) +} + +// TextIn applies the In predicate on the "text" field. +func TextIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldText, vs...)) +} + +// TextNotIn applies the NotIn predicate on the "text" field. +func TextNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldText, vs...)) +} + +// TextGT applies the GT predicate on the "text" field. +func TextGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldText, v)) +} + +// TextGTE applies the GTE predicate on the "text" field. +func TextGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldText, v)) +} + +// TextLT applies the LT predicate on the "text" field. +func TextLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldText, v)) +} + +// TextLTE applies the LTE predicate on the "text" field. +func TextLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldText, v)) +} + +// TextContains applies the Contains predicate on the "text" field. +func TextContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldText, v)) +} + +// TextHasPrefix applies the HasPrefix predicate on the "text" field. +func TextHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldText, v)) +} + +// TextHasSuffix applies the HasSuffix predicate on the "text" field. +func TextHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldText, v)) +} + +// TextIsNil applies the IsNil predicate on the "text" field. +func TextIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldText)) +} + +// TextNotNil applies the NotNil predicate on the "text" field. +func TextNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldText)) +} + +// TextEqualFold applies the EqualFold predicate on the "text" field. +func TextEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldText, v)) +} + +// TextContainsFold applies the ContainsFold predicate on the "text" field. +func TextContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldText, v)) +} + +// DidEQ applies the EQ predicate on the "did" field. +func DidEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldDid, v)) +} + +// DidNEQ applies the NEQ predicate on the "did" field. +func DidNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldDid, v)) +} + +// DidIn applies the In predicate on the "did" field. +func DidIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldDid, vs...)) +} + +// DidNotIn applies the NotIn predicate on the "did" field. +func DidNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldDid, vs...)) +} + +// DidGT applies the GT predicate on the "did" field. +func DidGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldDid, v)) +} + +// DidGTE applies the GTE predicate on the "did" field. +func DidGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldDid, v)) +} + +// DidLT applies the LT predicate on the "did" field. +func DidLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldDid, v)) +} + +// DidLTE applies the LTE predicate on the "did" field. +func DidLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldDid, v)) +} + +// DidContains applies the Contains predicate on the "did" field. +func DidContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldDid, v)) +} + +// DidHasPrefix applies the HasPrefix predicate on the "did" field. +func DidHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldDid, v)) +} + +// DidHasSuffix applies the HasSuffix predicate on the "did" field. +func DidHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldDid, v)) +} + +// DidIsNil applies the IsNil predicate on the "did" field. +func DidIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldDid)) +} + +// DidNotNil applies the NotNil predicate on the "did" field. +func DidNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldDid)) +} + +// DidEqualFold applies the EqualFold predicate on the "did" field. +func DidEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldDid, v)) +} + +// DidContainsFold applies the ContainsFold predicate on the "did" field. +func DidContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldDid, v)) +} + +// AvatarEQ applies the EQ predicate on the "avatar" field. +func AvatarEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldAvatar, v)) +} + +// AvatarNEQ applies the NEQ predicate on the "avatar" field. +func AvatarNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldAvatar, v)) +} + +// AvatarIn applies the In predicate on the "avatar" field. +func AvatarIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldAvatar, vs...)) +} + +// AvatarNotIn applies the NotIn predicate on the "avatar" field. +func AvatarNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldAvatar, vs...)) +} + +// AvatarGT applies the GT predicate on the "avatar" field. +func AvatarGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldAvatar, v)) +} + +// AvatarGTE applies the GTE predicate on the "avatar" field. +func AvatarGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldAvatar, v)) +} + +// AvatarLT applies the LT predicate on the "avatar" field. +func AvatarLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldAvatar, v)) +} + +// AvatarLTE applies the LTE predicate on the "avatar" field. +func AvatarLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldAvatar, v)) +} + +// AvatarContains applies the Contains predicate on the "avatar" field. +func AvatarContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldAvatar, v)) +} + +// AvatarHasPrefix applies the HasPrefix predicate on the "avatar" field. +func AvatarHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldAvatar, v)) +} + +// AvatarHasSuffix applies the HasSuffix predicate on the "avatar" field. +func AvatarHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldAvatar, v)) +} + +// AvatarIsNil applies the IsNil predicate on the "avatar" field. +func AvatarIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldAvatar)) +} + +// AvatarNotNil applies the NotNil predicate on the "avatar" field. +func AvatarNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldAvatar)) +} + +// AvatarEqualFold applies the EqualFold predicate on the "avatar" field. +func AvatarEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldAvatar, v)) +} + +// AvatarContainsFold applies the ContainsFold predicate on the "avatar" field. +func AvatarContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldAvatar, v)) +} + +// CidEQ applies the EQ predicate on the "cid" field. +func CidEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldCid, v)) +} + +// CidNEQ applies the NEQ predicate on the "cid" field. +func CidNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldCid, v)) +} + +// CidIn applies the In predicate on the "cid" field. +func CidIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldCid, vs...)) +} + +// CidNotIn applies the NotIn predicate on the "cid" field. +func CidNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldCid, vs...)) +} + +// CidGT applies the GT predicate on the "cid" field. +func CidGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldCid, v)) +} + +// CidGTE applies the GTE predicate on the "cid" field. +func CidGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldCid, v)) +} + +// CidLT applies the LT predicate on the "cid" field. +func CidLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldCid, v)) +} + +// CidLTE applies the LTE predicate on the "cid" field. +func CidLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldCid, v)) +} + +// CidContains applies the Contains predicate on the "cid" field. +func CidContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldCid, v)) +} + +// CidHasPrefix applies the HasPrefix predicate on the "cid" field. +func CidHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldCid, v)) +} + +// CidHasSuffix applies the HasSuffix predicate on the "cid" field. +func CidHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldCid, v)) +} + +// CidIsNil applies the IsNil predicate on the "cid" field. +func CidIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldCid)) +} + +// CidNotNil applies the NotNil predicate on the "cid" field. +func CidNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldCid)) +} + +// CidEqualFold applies the EqualFold predicate on the "cid" field. +func CidEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldCid, v)) +} + +// CidContainsFold applies the ContainsFold predicate on the "cid" field. +func CidContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldCid, v)) +} + +// URIEQ applies the EQ predicate on the "uri" field. +func URIEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldURI, v)) +} + +// URINEQ applies the NEQ predicate on the "uri" field. +func URINEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldURI, v)) +} + +// URIIn applies the In predicate on the "uri" field. +func URIIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldURI, vs...)) +} + +// URINotIn applies the NotIn predicate on the "uri" field. +func URINotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldURI, vs...)) +} + +// URIGT applies the GT predicate on the "uri" field. +func URIGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldURI, v)) +} + +// URIGTE applies the GTE predicate on the "uri" field. +func URIGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldURI, v)) +} + +// URILT applies the LT predicate on the "uri" field. +func URILT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldURI, v)) +} + +// URILTE applies the LTE predicate on the "uri" field. +func URILTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldURI, v)) +} + +// URIContains applies the Contains predicate on the "uri" field. +func URIContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldURI, v)) +} + +// URIHasPrefix applies the HasPrefix predicate on the "uri" field. +func URIHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldURI, v)) +} + +// URIHasSuffix applies the HasSuffix predicate on the "uri" field. +func URIHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldURI, v)) +} + +// URIIsNil applies the IsNil predicate on the "uri" field. +func URIIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldURI)) +} + +// URINotNil applies the NotNil predicate on the "uri" field. +func URINotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldURI)) +} + +// URIEqualFold applies the EqualFold predicate on the "uri" field. +func URIEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldURI, v)) +} + +// URIContainsFold applies the ContainsFold predicate on the "uri" field. +func URIContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldURI, v)) +} + +// RkeyEQ applies the EQ predicate on the "rkey" field. +func RkeyEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldRkey, v)) +} + +// RkeyNEQ applies the NEQ predicate on the "rkey" field. +func RkeyNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldRkey, v)) +} + +// RkeyIn applies the In predicate on the "rkey" field. +func RkeyIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldRkey, vs...)) +} + +// RkeyNotIn applies the NotIn predicate on the "rkey" field. +func RkeyNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldRkey, vs...)) +} + +// RkeyGT applies the GT predicate on the "rkey" field. +func RkeyGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldRkey, v)) +} + +// RkeyGTE applies the GTE predicate on the "rkey" field. +func RkeyGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldRkey, v)) +} + +// RkeyLT applies the LT predicate on the "rkey" field. +func RkeyLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldRkey, v)) +} + +// RkeyLTE applies the LTE predicate on the "rkey" field. +func RkeyLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldRkey, v)) +} + +// RkeyContains applies the Contains predicate on the "rkey" field. +func RkeyContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldRkey, v)) +} + +// RkeyHasPrefix applies the HasPrefix predicate on the "rkey" field. +func RkeyHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldRkey, v)) +} + +// RkeyHasSuffix applies the HasSuffix predicate on the "rkey" field. +func RkeyHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldRkey, v)) +} + +// RkeyIsNil applies the IsNil predicate on the "rkey" field. +func RkeyIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldRkey)) +} + +// RkeyNotNil applies the NotNil predicate on the "rkey" field. +func RkeyNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldRkey)) +} + +// RkeyEqualFold applies the EqualFold predicate on the "rkey" field. +func RkeyEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldRkey, v)) +} + +// RkeyContainsFold applies the ContainsFold predicate on the "rkey" field. +func RkeyContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldRkey, v)) +} + +// BskyURLEQ applies the EQ predicate on the "bsky_url" field. +func BskyURLEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldBskyURL, v)) +} + +// BskyURLNEQ applies the NEQ predicate on the "bsky_url" field. +func BskyURLNEQ(v string) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldBskyURL, v)) +} + +// BskyURLIn applies the In predicate on the "bsky_url" field. +func BskyURLIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldBskyURL, vs...)) +} + +// BskyURLNotIn applies the NotIn predicate on the "bsky_url" field. +func BskyURLNotIn(vs ...string) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldBskyURL, vs...)) +} + +// BskyURLGT applies the GT predicate on the "bsky_url" field. +func BskyURLGT(v string) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldBskyURL, v)) +} + +// BskyURLGTE applies the GTE predicate on the "bsky_url" field. +func BskyURLGTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldBskyURL, v)) +} + +// BskyURLLT applies the LT predicate on the "bsky_url" field. +func BskyURLLT(v string) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldBskyURL, v)) +} + +// BskyURLLTE applies the LTE predicate on the "bsky_url" field. +func BskyURLLTE(v string) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldBskyURL, v)) +} + +// BskyURLContains applies the Contains predicate on the "bsky_url" field. +func BskyURLContains(v string) predicate.Ma { + return predicate.Ma(sql.FieldContains(FieldBskyURL, v)) +} + +// BskyURLHasPrefix applies the HasPrefix predicate on the "bsky_url" field. +func BskyURLHasPrefix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasPrefix(FieldBskyURL, v)) +} + +// BskyURLHasSuffix applies the HasSuffix predicate on the "bsky_url" field. +func BskyURLHasSuffix(v string) predicate.Ma { + return predicate.Ma(sql.FieldHasSuffix(FieldBskyURL, v)) +} + +// BskyURLIsNil applies the IsNil predicate on the "bsky_url" field. +func BskyURLIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldBskyURL)) +} + +// BskyURLNotNil applies the NotNil predicate on the "bsky_url" field. +func BskyURLNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldBskyURL)) +} + +// BskyURLEqualFold applies the EqualFold predicate on the "bsky_url" field. +func BskyURLEqualFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldEqualFold(FieldBskyURL, v)) +} + +// BskyURLContainsFold applies the ContainsFold predicate on the "bsky_url" field. +func BskyURLContainsFold(v string) predicate.Ma { + return predicate.Ma(sql.FieldContainsFold(FieldBskyURL, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field. +func UpdatedAtIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldUpdatedAt)) +} + +// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field. +func UpdatedAtNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldUpdatedAt)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Ma { + return predicate.Ma(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Ma { + return predicate.Ma(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Ma { + return predicate.Ma(sql.FieldLTE(FieldCreatedAt, v)) +} + +// CreatedAtIsNil applies the IsNil predicate on the "created_at" field. +func CreatedAtIsNil() predicate.Ma { + return predicate.Ma(sql.FieldIsNull(FieldCreatedAt)) +} + +// CreatedAtNotNil applies the NotNil predicate on the "created_at" field. +func CreatedAtNotNil() predicate.Ma { + return predicate.Ma(sql.FieldNotNull(FieldCreatedAt)) +} + +// HasOwner applies the HasEdge predicate on the "owner" edge. +func HasOwner() predicate.Ma { + return predicate.Ma(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates). +func HasOwnerWith(preds ...predicate.User) predicate.Ma { + return predicate.Ma(func(s *sql.Selector) { + step := newOwnerStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Ma) predicate.Ma { + return predicate.Ma(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Ma) predicate.Ma { + return predicate.Ma(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Ma) predicate.Ma { + return predicate.Ma(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/ma_create.go b/ent/ma_create.go new file mode 100644 index 0000000..cbdf14a --- /dev/null +++ b/ent/ma_create.go @@ -0,0 +1,465 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "api/ent/ma" + "api/ent/user" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MaCreate is the builder for creating a Ma entity. +type MaCreate struct { + config + mutation *MaMutation + hooks []Hook +} + +// SetPassword sets the "password" field. +func (mc *MaCreate) SetPassword(s string) *MaCreate { + mc.mutation.SetPassword(s) + return mc +} + +// SetToken sets the "token" field. +func (mc *MaCreate) SetToken(s string) *MaCreate { + mc.mutation.SetToken(s) + return mc +} + +// SetNillableToken sets the "token" field if the given value is not nil. +func (mc *MaCreate) SetNillableToken(s *string) *MaCreate { + if s != nil { + mc.SetToken(*s) + } + return mc +} + +// SetLimit sets the "limit" field. +func (mc *MaCreate) SetLimit(b bool) *MaCreate { + mc.mutation.SetLimit(b) + return mc +} + +// SetNillableLimit sets the "limit" field if the given value is not nil. +func (mc *MaCreate) SetNillableLimit(b *bool) *MaCreate { + if b != nil { + mc.SetLimit(*b) + } + return mc +} + +// SetCount sets the "count" field. +func (mc *MaCreate) SetCount(i int) *MaCreate { + mc.mutation.SetCount(i) + return mc +} + +// SetNillableCount sets the "count" field if the given value is not nil. +func (mc *MaCreate) SetNillableCount(i *int) *MaCreate { + if i != nil { + mc.SetCount(*i) + } + return mc +} + +// SetHandle sets the "handle" field. +func (mc *MaCreate) SetHandle(s string) *MaCreate { + mc.mutation.SetHandle(s) + return mc +} + +// SetNillableHandle sets the "handle" field if the given value is not nil. +func (mc *MaCreate) SetNillableHandle(s *string) *MaCreate { + if s != nil { + mc.SetHandle(*s) + } + return mc +} + +// SetText sets the "text" field. +func (mc *MaCreate) SetText(s string) *MaCreate { + mc.mutation.SetText(s) + return mc +} + +// SetNillableText sets the "text" field if the given value is not nil. +func (mc *MaCreate) SetNillableText(s *string) *MaCreate { + if s != nil { + mc.SetText(*s) + } + return mc +} + +// SetDid sets the "did" field. +func (mc *MaCreate) SetDid(s string) *MaCreate { + mc.mutation.SetDid(s) + return mc +} + +// SetNillableDid sets the "did" field if the given value is not nil. +func (mc *MaCreate) SetNillableDid(s *string) *MaCreate { + if s != nil { + mc.SetDid(*s) + } + return mc +} + +// SetAvatar sets the "avatar" field. +func (mc *MaCreate) SetAvatar(s string) *MaCreate { + mc.mutation.SetAvatar(s) + return mc +} + +// SetNillableAvatar sets the "avatar" field if the given value is not nil. +func (mc *MaCreate) SetNillableAvatar(s *string) *MaCreate { + if s != nil { + mc.SetAvatar(*s) + } + return mc +} + +// SetCid sets the "cid" field. +func (mc *MaCreate) SetCid(s string) *MaCreate { + mc.mutation.SetCid(s) + return mc +} + +// SetNillableCid sets the "cid" field if the given value is not nil. +func (mc *MaCreate) SetNillableCid(s *string) *MaCreate { + if s != nil { + mc.SetCid(*s) + } + return mc +} + +// SetURI sets the "uri" field. +func (mc *MaCreate) SetURI(s string) *MaCreate { + mc.mutation.SetURI(s) + return mc +} + +// SetNillableURI sets the "uri" field if the given value is not nil. +func (mc *MaCreate) SetNillableURI(s *string) *MaCreate { + if s != nil { + mc.SetURI(*s) + } + return mc +} + +// SetRkey sets the "rkey" field. +func (mc *MaCreate) SetRkey(s string) *MaCreate { + mc.mutation.SetRkey(s) + return mc +} + +// SetNillableRkey sets the "rkey" field if the given value is not nil. +func (mc *MaCreate) SetNillableRkey(s *string) *MaCreate { + if s != nil { + mc.SetRkey(*s) + } + return mc +} + +// SetBskyURL sets the "bsky_url" field. +func (mc *MaCreate) SetBskyURL(s string) *MaCreate { + mc.mutation.SetBskyURL(s) + return mc +} + +// SetNillableBskyURL sets the "bsky_url" field if the given value is not nil. +func (mc *MaCreate) SetNillableBskyURL(s *string) *MaCreate { + if s != nil { + mc.SetBskyURL(*s) + } + return mc +} + +// SetUpdatedAt sets the "updated_at" field. +func (mc *MaCreate) SetUpdatedAt(t time.Time) *MaCreate { + mc.mutation.SetUpdatedAt(t) + return mc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (mc *MaCreate) SetNillableUpdatedAt(t *time.Time) *MaCreate { + if t != nil { + mc.SetUpdatedAt(*t) + } + return mc +} + +// SetCreatedAt sets the "created_at" field. +func (mc *MaCreate) SetCreatedAt(t time.Time) *MaCreate { + mc.mutation.SetCreatedAt(t) + return mc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (mc *MaCreate) SetNillableCreatedAt(t *time.Time) *MaCreate { + if t != nil { + mc.SetCreatedAt(*t) + } + return mc +} + +// SetOwnerID sets the "owner" edge to the User entity by ID. +func (mc *MaCreate) SetOwnerID(id int) *MaCreate { + mc.mutation.SetOwnerID(id) + return mc +} + +// SetOwner sets the "owner" edge to the User entity. +func (mc *MaCreate) SetOwner(u *User) *MaCreate { + return mc.SetOwnerID(u.ID) +} + +// Mutation returns the MaMutation object of the builder. +func (mc *MaCreate) Mutation() *MaMutation { + return mc.mutation +} + +// Save creates the Ma in the database. +func (mc *MaCreate) Save(ctx context.Context) (*Ma, error) { + mc.defaults() + return withHooks[*Ma, MaMutation](ctx, mc.sqlSave, mc.mutation, mc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (mc *MaCreate) SaveX(ctx context.Context) *Ma { + v, err := mc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mc *MaCreate) Exec(ctx context.Context) error { + _, err := mc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mc *MaCreate) ExecX(ctx context.Context) { + if err := mc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (mc *MaCreate) defaults() { + if _, ok := mc.mutation.Limit(); !ok { + v := ma.DefaultLimit + mc.mutation.SetLimit(v) + } + if _, ok := mc.mutation.CreatedAt(); !ok { + v := ma.DefaultCreatedAt() + mc.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mc *MaCreate) check() error { + if _, ok := mc.mutation.Password(); !ok { + return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Ma.password"`)} + } + if v, ok := mc.mutation.Password(); ok { + if err := ma.PasswordValidator(v); err != nil { + return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Ma.password": %w`, err)} + } + } + if _, ok := mc.mutation.OwnerID(); !ok { + return &ValidationError{Name: "owner", err: errors.New(`ent: missing required edge "Ma.owner"`)} + } + return nil +} + +func (mc *MaCreate) sqlSave(ctx context.Context) (*Ma, error) { + if err := mc.check(); err != nil { + return nil, err + } + _node, _spec := mc.createSpec() + if err := sqlgraph.CreateNode(ctx, mc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + mc.mutation.id = &_node.ID + mc.mutation.done = true + return _node, nil +} + +func (mc *MaCreate) createSpec() (*Ma, *sqlgraph.CreateSpec) { + var ( + _node = &Ma{config: mc.config} + _spec = sqlgraph.NewCreateSpec(ma.Table, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt)) + ) + if value, ok := mc.mutation.Password(); ok { + _spec.SetField(ma.FieldPassword, field.TypeString, value) + _node.Password = value + } + if value, ok := mc.mutation.Token(); ok { + _spec.SetField(ma.FieldToken, field.TypeString, value) + _node.Token = value + } + if value, ok := mc.mutation.Limit(); ok { + _spec.SetField(ma.FieldLimit, field.TypeBool, value) + _node.Limit = value + } + if value, ok := mc.mutation.Count(); ok { + _spec.SetField(ma.FieldCount, field.TypeInt, value) + _node.Count = value + } + if value, ok := mc.mutation.Handle(); ok { + _spec.SetField(ma.FieldHandle, field.TypeString, value) + _node.Handle = value + } + if value, ok := mc.mutation.Text(); ok { + _spec.SetField(ma.FieldText, field.TypeString, value) + _node.Text = value + } + if value, ok := mc.mutation.Did(); ok { + _spec.SetField(ma.FieldDid, field.TypeString, value) + _node.Did = value + } + if value, ok := mc.mutation.Avatar(); ok { + _spec.SetField(ma.FieldAvatar, field.TypeString, value) + _node.Avatar = value + } + if value, ok := mc.mutation.Cid(); ok { + _spec.SetField(ma.FieldCid, field.TypeString, value) + _node.Cid = value + } + if value, ok := mc.mutation.URI(); ok { + _spec.SetField(ma.FieldURI, field.TypeString, value) + _node.URI = value + } + if value, ok := mc.mutation.Rkey(); ok { + _spec.SetField(ma.FieldRkey, field.TypeString, value) + _node.Rkey = value + } + if value, ok := mc.mutation.BskyURL(); ok { + _spec.SetField(ma.FieldBskyURL, field.TypeString, value) + _node.BskyURL = value + } + if value, ok := mc.mutation.UpdatedAt(); ok { + _spec.SetField(ma.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := mc.mutation.CreatedAt(); ok { + _spec.SetField(ma.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if nodes := mc.mutation.OwnerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: ma.OwnerTable, + Columns: []string{ma.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.user_ma = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// MaCreateBulk is the builder for creating many Ma entities in bulk. +type MaCreateBulk struct { + config + builders []*MaCreate +} + +// Save creates the Ma entities in the database. +func (mcb *MaCreateBulk) Save(ctx context.Context) ([]*Ma, error) { + specs := make([]*sqlgraph.CreateSpec, len(mcb.builders)) + nodes := make([]*Ma, len(mcb.builders)) + mutators := make([]Mutator, len(mcb.builders)) + for i := range mcb.builders { + func(i int, root context.Context) { + builder := mcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MaMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, mcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, mcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, mcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (mcb *MaCreateBulk) SaveX(ctx context.Context) []*Ma { + v, err := mcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mcb *MaCreateBulk) Exec(ctx context.Context) error { + _, err := mcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mcb *MaCreateBulk) ExecX(ctx context.Context) { + if err := mcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/ma_delete.go b/ent/ma_delete.go new file mode 100644 index 0000000..ca8322e --- /dev/null +++ b/ent/ma_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "api/ent/ma" + "api/ent/predicate" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MaDelete is the builder for deleting a Ma entity. +type MaDelete struct { + config + hooks []Hook + mutation *MaMutation +} + +// Where appends a list predicates to the MaDelete builder. +func (md *MaDelete) Where(ps ...predicate.Ma) *MaDelete { + md.mutation.Where(ps...) + return md +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (md *MaDelete) Exec(ctx context.Context) (int, error) { + return withHooks[int, MaMutation](ctx, md.sqlExec, md.mutation, md.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (md *MaDelete) ExecX(ctx context.Context) int { + n, err := md.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (md *MaDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(ma.Table, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt)) + if ps := md.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, md.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + md.mutation.done = true + return affected, err +} + +// MaDeleteOne is the builder for deleting a single Ma entity. +type MaDeleteOne struct { + md *MaDelete +} + +// Where appends a list predicates to the MaDelete builder. +func (mdo *MaDeleteOne) Where(ps ...predicate.Ma) *MaDeleteOne { + mdo.md.mutation.Where(ps...) + return mdo +} + +// Exec executes the deletion query. +func (mdo *MaDeleteOne) Exec(ctx context.Context) error { + n, err := mdo.md.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{ma.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (mdo *MaDeleteOne) ExecX(ctx context.Context) { + if err := mdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/ma_query.go b/ent/ma_query.go new file mode 100644 index 0000000..380be18 --- /dev/null +++ b/ent/ma_query.go @@ -0,0 +1,613 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "api/ent/ma" + "api/ent/predicate" + "api/ent/user" + "context" + "fmt" + "math" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MaQuery is the builder for querying Ma entities. +type MaQuery struct { + config + ctx *QueryContext + order []ma.OrderOption + inters []Interceptor + predicates []predicate.Ma + withOwner *UserQuery + withFKs bool + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the MaQuery builder. +func (mq *MaQuery) Where(ps ...predicate.Ma) *MaQuery { + mq.predicates = append(mq.predicates, ps...) + return mq +} + +// Limit the number of records to be returned by this query. +func (mq *MaQuery) Limit(limit int) *MaQuery { + mq.ctx.Limit = &limit + return mq +} + +// Offset to start from. +func (mq *MaQuery) Offset(offset int) *MaQuery { + mq.ctx.Offset = &offset + return mq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (mq *MaQuery) Unique(unique bool) *MaQuery { + mq.ctx.Unique = &unique + return mq +} + +// Order specifies how the records should be ordered. +func (mq *MaQuery) Order(o ...ma.OrderOption) *MaQuery { + mq.order = append(mq.order, o...) + return mq +} + +// QueryOwner chains the current query on the "owner" edge. +func (mq *MaQuery) QueryOwner() *UserQuery { + query := (&UserClient{config: mq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := mq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(ma.Table, ma.FieldID, selector), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ma.OwnerTable, ma.OwnerColumn), + ) + fromU = sqlgraph.SetNeighbors(mq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Ma entity from the query. +// Returns a *NotFoundError when no Ma was found. +func (mq *MaQuery) First(ctx context.Context) (*Ma, error) { + nodes, err := mq.Limit(1).All(setContextOp(ctx, mq.ctx, "First")) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{ma.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (mq *MaQuery) FirstX(ctx context.Context) *Ma { + node, err := mq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Ma ID from the query. +// Returns a *NotFoundError when no Ma ID was found. +func (mq *MaQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = mq.Limit(1).IDs(setContextOp(ctx, mq.ctx, "FirstID")); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{ma.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (mq *MaQuery) FirstIDX(ctx context.Context) int { + id, err := mq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Ma entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Ma entity is found. +// Returns a *NotFoundError when no Ma entities are found. +func (mq *MaQuery) Only(ctx context.Context) (*Ma, error) { + nodes, err := mq.Limit(2).All(setContextOp(ctx, mq.ctx, "Only")) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{ma.Label} + default: + return nil, &NotSingularError{ma.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (mq *MaQuery) OnlyX(ctx context.Context) *Ma { + node, err := mq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Ma ID in the query. +// Returns a *NotSingularError when more than one Ma ID is found. +// Returns a *NotFoundError when no entities are found. +func (mq *MaQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = mq.Limit(2).IDs(setContextOp(ctx, mq.ctx, "OnlyID")); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{ma.Label} + default: + err = &NotSingularError{ma.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (mq *MaQuery) OnlyIDX(ctx context.Context) int { + id, err := mq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Mas. +func (mq *MaQuery) All(ctx context.Context) ([]*Ma, error) { + ctx = setContextOp(ctx, mq.ctx, "All") + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Ma, *MaQuery]() + return withInterceptors[[]*Ma](ctx, mq, qr, mq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (mq *MaQuery) AllX(ctx context.Context) []*Ma { + nodes, err := mq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Ma IDs. +func (mq *MaQuery) IDs(ctx context.Context) (ids []int, err error) { + if mq.ctx.Unique == nil && mq.path != nil { + mq.Unique(true) + } + ctx = setContextOp(ctx, mq.ctx, "IDs") + if err = mq.Select(ma.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (mq *MaQuery) IDsX(ctx context.Context) []int { + ids, err := mq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (mq *MaQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, mq.ctx, "Count") + if err := mq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, mq, querierCount[*MaQuery](), mq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (mq *MaQuery) CountX(ctx context.Context) int { + count, err := mq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (mq *MaQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, mq.ctx, "Exist") + switch _, err := mq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (mq *MaQuery) ExistX(ctx context.Context) bool { + exist, err := mq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the MaQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (mq *MaQuery) Clone() *MaQuery { + if mq == nil { + return nil + } + return &MaQuery{ + config: mq.config, + ctx: mq.ctx.Clone(), + order: append([]ma.OrderOption{}, mq.order...), + inters: append([]Interceptor{}, mq.inters...), + predicates: append([]predicate.Ma{}, mq.predicates...), + withOwner: mq.withOwner.Clone(), + // clone intermediate query. + sql: mq.sql.Clone(), + path: mq.path, + } +} + +// WithOwner tells the query-builder to eager-load the nodes that are connected to +// the "owner" edge. The optional arguments are used to configure the query builder of the edge. +func (mq *MaQuery) WithOwner(opts ...func(*UserQuery)) *MaQuery { + query := (&UserClient{config: mq.config}).Query() + for _, opt := range opts { + opt(query) + } + mq.withOwner = query + return mq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Password string `json:"password,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Ma.Query(). +// GroupBy(ma.FieldPassword). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (mq *MaQuery) GroupBy(field string, fields ...string) *MaGroupBy { + mq.ctx.Fields = append([]string{field}, fields...) + grbuild := &MaGroupBy{build: mq} + grbuild.flds = &mq.ctx.Fields + grbuild.label = ma.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Password string `json:"password,omitempty"` +// } +// +// client.Ma.Query(). +// Select(ma.FieldPassword). +// Scan(ctx, &v) +func (mq *MaQuery) Select(fields ...string) *MaSelect { + mq.ctx.Fields = append(mq.ctx.Fields, fields...) + sbuild := &MaSelect{MaQuery: mq} + sbuild.label = ma.Label + sbuild.flds, sbuild.scan = &mq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a MaSelect configured with the given aggregations. +func (mq *MaQuery) Aggregate(fns ...AggregateFunc) *MaSelect { + return mq.Select().Aggregate(fns...) +} + +func (mq *MaQuery) prepareQuery(ctx context.Context) error { + for _, inter := range mq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, mq); err != nil { + return err + } + } + } + for _, f := range mq.ctx.Fields { + if !ma.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if mq.path != nil { + prev, err := mq.path(ctx) + if err != nil { + return err + } + mq.sql = prev + } + return nil +} + +func (mq *MaQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Ma, error) { + var ( + nodes = []*Ma{} + withFKs = mq.withFKs + _spec = mq.querySpec() + loadedTypes = [1]bool{ + mq.withOwner != nil, + } + ) + if mq.withOwner != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, ma.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Ma).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Ma{config: mq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := mq.withOwner; query != nil { + if err := mq.loadOwner(ctx, query, nodes, nil, + func(n *Ma, e *User) { n.Edges.Owner = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (mq *MaQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Ma, init func(*Ma), assign func(*Ma, *User)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Ma) + for i := range nodes { + if nodes[i].user_ma == nil { + continue + } + fk := *nodes[i].user_ma + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(user.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "user_ma" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (mq *MaQuery) sqlCount(ctx context.Context) (int, error) { + _spec := mq.querySpec() + _spec.Node.Columns = mq.ctx.Fields + if len(mq.ctx.Fields) > 0 { + _spec.Unique = mq.ctx.Unique != nil && *mq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, mq.driver, _spec) +} + +func (mq *MaQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(ma.Table, ma.Columns, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt)) + _spec.From = mq.sql + if unique := mq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if mq.path != nil { + _spec.Unique = true + } + if fields := mq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, ma.FieldID) + for i := range fields { + if fields[i] != ma.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := mq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := mq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := mq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := mq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (mq *MaQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(mq.driver.Dialect()) + t1 := builder.Table(ma.Table) + columns := mq.ctx.Fields + if len(columns) == 0 { + columns = ma.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if mq.sql != nil { + selector = mq.sql + selector.Select(selector.Columns(columns...)...) + } + if mq.ctx.Unique != nil && *mq.ctx.Unique { + selector.Distinct() + } + for _, p := range mq.predicates { + p(selector) + } + for _, p := range mq.order { + p(selector) + } + if offset := mq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := mq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// MaGroupBy is the group-by builder for Ma entities. +type MaGroupBy struct { + selector + build *MaQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (mgb *MaGroupBy) Aggregate(fns ...AggregateFunc) *MaGroupBy { + mgb.fns = append(mgb.fns, fns...) + return mgb +} + +// Scan applies the selector query and scans the result into the given value. +func (mgb *MaGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, mgb.build.ctx, "GroupBy") + if err := mgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*MaQuery, *MaGroupBy](ctx, mgb.build, mgb, mgb.build.inters, v) +} + +func (mgb *MaGroupBy) sqlScan(ctx context.Context, root *MaQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(mgb.fns)) + for _, fn := range mgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*mgb.flds)+len(mgb.fns)) + for _, f := range *mgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*mgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := mgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// MaSelect is the builder for selecting fields of Ma entities. +type MaSelect struct { + *MaQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ms *MaSelect) Aggregate(fns ...AggregateFunc) *MaSelect { + ms.fns = append(ms.fns, fns...) + return ms +} + +// Scan applies the selector query and scans the result into the given value. +func (ms *MaSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ms.ctx, "Select") + if err := ms.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*MaQuery, *MaSelect](ctx, ms.MaQuery, ms, ms.inters, v) +} + +func (ms *MaSelect) sqlScan(ctx context.Context, root *MaQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ms.fns)) + for _, fn := range ms.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ms.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ms.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/ma_update.go b/ent/ma_update.go new file mode 100644 index 0000000..f9f51de --- /dev/null +++ b/ent/ma_update.go @@ -0,0 +1,941 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "api/ent/ma" + "api/ent/predicate" + "api/ent/user" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MaUpdate is the builder for updating Ma entities. +type MaUpdate struct { + config + hooks []Hook + mutation *MaMutation +} + +// Where appends a list predicates to the MaUpdate builder. +func (mu *MaUpdate) Where(ps ...predicate.Ma) *MaUpdate { + mu.mutation.Where(ps...) + return mu +} + +// SetToken sets the "token" field. +func (mu *MaUpdate) SetToken(s string) *MaUpdate { + mu.mutation.SetToken(s) + return mu +} + +// SetNillableToken sets the "token" field if the given value is not nil. +func (mu *MaUpdate) SetNillableToken(s *string) *MaUpdate { + if s != nil { + mu.SetToken(*s) + } + return mu +} + +// ClearToken clears the value of the "token" field. +func (mu *MaUpdate) ClearToken() *MaUpdate { + mu.mutation.ClearToken() + return mu +} + +// SetLimit sets the "limit" field. +func (mu *MaUpdate) SetLimit(b bool) *MaUpdate { + mu.mutation.SetLimit(b) + return mu +} + +// SetNillableLimit sets the "limit" field if the given value is not nil. +func (mu *MaUpdate) SetNillableLimit(b *bool) *MaUpdate { + if b != nil { + mu.SetLimit(*b) + } + return mu +} + +// ClearLimit clears the value of the "limit" field. +func (mu *MaUpdate) ClearLimit() *MaUpdate { + mu.mutation.ClearLimit() + return mu +} + +// SetCount sets the "count" field. +func (mu *MaUpdate) SetCount(i int) *MaUpdate { + mu.mutation.ResetCount() + mu.mutation.SetCount(i) + return mu +} + +// SetNillableCount sets the "count" field if the given value is not nil. +func (mu *MaUpdate) SetNillableCount(i *int) *MaUpdate { + if i != nil { + mu.SetCount(*i) + } + return mu +} + +// AddCount adds i to the "count" field. +func (mu *MaUpdate) AddCount(i int) *MaUpdate { + mu.mutation.AddCount(i) + return mu +} + +// ClearCount clears the value of the "count" field. +func (mu *MaUpdate) ClearCount() *MaUpdate { + mu.mutation.ClearCount() + return mu +} + +// SetHandle sets the "handle" field. +func (mu *MaUpdate) SetHandle(s string) *MaUpdate { + mu.mutation.SetHandle(s) + return mu +} + +// SetNillableHandle sets the "handle" field if the given value is not nil. +func (mu *MaUpdate) SetNillableHandle(s *string) *MaUpdate { + if s != nil { + mu.SetHandle(*s) + } + return mu +} + +// ClearHandle clears the value of the "handle" field. +func (mu *MaUpdate) ClearHandle() *MaUpdate { + mu.mutation.ClearHandle() + return mu +} + +// SetText sets the "text" field. +func (mu *MaUpdate) SetText(s string) *MaUpdate { + mu.mutation.SetText(s) + return mu +} + +// SetNillableText sets the "text" field if the given value is not nil. +func (mu *MaUpdate) SetNillableText(s *string) *MaUpdate { + if s != nil { + mu.SetText(*s) + } + return mu +} + +// ClearText clears the value of the "text" field. +func (mu *MaUpdate) ClearText() *MaUpdate { + mu.mutation.ClearText() + return mu +} + +// SetDid sets the "did" field. +func (mu *MaUpdate) SetDid(s string) *MaUpdate { + mu.mutation.SetDid(s) + return mu +} + +// SetNillableDid sets the "did" field if the given value is not nil. +func (mu *MaUpdate) SetNillableDid(s *string) *MaUpdate { + if s != nil { + mu.SetDid(*s) + } + return mu +} + +// ClearDid clears the value of the "did" field. +func (mu *MaUpdate) ClearDid() *MaUpdate { + mu.mutation.ClearDid() + return mu +} + +// SetAvatar sets the "avatar" field. +func (mu *MaUpdate) SetAvatar(s string) *MaUpdate { + mu.mutation.SetAvatar(s) + return mu +} + +// SetNillableAvatar sets the "avatar" field if the given value is not nil. +func (mu *MaUpdate) SetNillableAvatar(s *string) *MaUpdate { + if s != nil { + mu.SetAvatar(*s) + } + return mu +} + +// ClearAvatar clears the value of the "avatar" field. +func (mu *MaUpdate) ClearAvatar() *MaUpdate { + mu.mutation.ClearAvatar() + return mu +} + +// SetCid sets the "cid" field. +func (mu *MaUpdate) SetCid(s string) *MaUpdate { + mu.mutation.SetCid(s) + return mu +} + +// SetNillableCid sets the "cid" field if the given value is not nil. +func (mu *MaUpdate) SetNillableCid(s *string) *MaUpdate { + if s != nil { + mu.SetCid(*s) + } + return mu +} + +// ClearCid clears the value of the "cid" field. +func (mu *MaUpdate) ClearCid() *MaUpdate { + mu.mutation.ClearCid() + return mu +} + +// SetURI sets the "uri" field. +func (mu *MaUpdate) SetURI(s string) *MaUpdate { + mu.mutation.SetURI(s) + return mu +} + +// SetNillableURI sets the "uri" field if the given value is not nil. +func (mu *MaUpdate) SetNillableURI(s *string) *MaUpdate { + if s != nil { + mu.SetURI(*s) + } + return mu +} + +// ClearURI clears the value of the "uri" field. +func (mu *MaUpdate) ClearURI() *MaUpdate { + mu.mutation.ClearURI() + return mu +} + +// SetRkey sets the "rkey" field. +func (mu *MaUpdate) SetRkey(s string) *MaUpdate { + mu.mutation.SetRkey(s) + return mu +} + +// SetNillableRkey sets the "rkey" field if the given value is not nil. +func (mu *MaUpdate) SetNillableRkey(s *string) *MaUpdate { + if s != nil { + mu.SetRkey(*s) + } + return mu +} + +// ClearRkey clears the value of the "rkey" field. +func (mu *MaUpdate) ClearRkey() *MaUpdate { + mu.mutation.ClearRkey() + return mu +} + +// SetBskyURL sets the "bsky_url" field. +func (mu *MaUpdate) SetBskyURL(s string) *MaUpdate { + mu.mutation.SetBskyURL(s) + return mu +} + +// SetNillableBskyURL sets the "bsky_url" field if the given value is not nil. +func (mu *MaUpdate) SetNillableBskyURL(s *string) *MaUpdate { + if s != nil { + mu.SetBskyURL(*s) + } + return mu +} + +// ClearBskyURL clears the value of the "bsky_url" field. +func (mu *MaUpdate) ClearBskyURL() *MaUpdate { + mu.mutation.ClearBskyURL() + return mu +} + +// SetUpdatedAt sets the "updated_at" field. +func (mu *MaUpdate) SetUpdatedAt(t time.Time) *MaUpdate { + mu.mutation.SetUpdatedAt(t) + return mu +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (mu *MaUpdate) SetNillableUpdatedAt(t *time.Time) *MaUpdate { + if t != nil { + mu.SetUpdatedAt(*t) + } + return mu +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (mu *MaUpdate) ClearUpdatedAt() *MaUpdate { + mu.mutation.ClearUpdatedAt() + return mu +} + +// SetOwnerID sets the "owner" edge to the User entity by ID. +func (mu *MaUpdate) SetOwnerID(id int) *MaUpdate { + mu.mutation.SetOwnerID(id) + return mu +} + +// SetOwner sets the "owner" edge to the User entity. +func (mu *MaUpdate) SetOwner(u *User) *MaUpdate { + return mu.SetOwnerID(u.ID) +} + +// Mutation returns the MaMutation object of the builder. +func (mu *MaUpdate) Mutation() *MaMutation { + return mu.mutation +} + +// ClearOwner clears the "owner" edge to the User entity. +func (mu *MaUpdate) ClearOwner() *MaUpdate { + mu.mutation.ClearOwner() + return mu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (mu *MaUpdate) Save(ctx context.Context) (int, error) { + return withHooks[int, MaMutation](ctx, mu.sqlSave, mu.mutation, mu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (mu *MaUpdate) SaveX(ctx context.Context) int { + affected, err := mu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (mu *MaUpdate) Exec(ctx context.Context) error { + _, err := mu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mu *MaUpdate) ExecX(ctx context.Context) { + if err := mu.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mu *MaUpdate) check() error { + if _, ok := mu.mutation.OwnerID(); mu.mutation.OwnerCleared() && !ok { + return errors.New(`ent: clearing a required unique edge "Ma.owner"`) + } + return nil +} + +func (mu *MaUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := mu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(ma.Table, ma.Columns, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt)) + if ps := mu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := mu.mutation.Token(); ok { + _spec.SetField(ma.FieldToken, field.TypeString, value) + } + if mu.mutation.TokenCleared() { + _spec.ClearField(ma.FieldToken, field.TypeString) + } + if value, ok := mu.mutation.Limit(); ok { + _spec.SetField(ma.FieldLimit, field.TypeBool, value) + } + if mu.mutation.LimitCleared() { + _spec.ClearField(ma.FieldLimit, field.TypeBool) + } + if value, ok := mu.mutation.Count(); ok { + _spec.SetField(ma.FieldCount, field.TypeInt, value) + } + if value, ok := mu.mutation.AddedCount(); ok { + _spec.AddField(ma.FieldCount, field.TypeInt, value) + } + if mu.mutation.CountCleared() { + _spec.ClearField(ma.FieldCount, field.TypeInt) + } + if value, ok := mu.mutation.Handle(); ok { + _spec.SetField(ma.FieldHandle, field.TypeString, value) + } + if mu.mutation.HandleCleared() { + _spec.ClearField(ma.FieldHandle, field.TypeString) + } + if value, ok := mu.mutation.Text(); ok { + _spec.SetField(ma.FieldText, field.TypeString, value) + } + if mu.mutation.TextCleared() { + _spec.ClearField(ma.FieldText, field.TypeString) + } + if value, ok := mu.mutation.Did(); ok { + _spec.SetField(ma.FieldDid, field.TypeString, value) + } + if mu.mutation.DidCleared() { + _spec.ClearField(ma.FieldDid, field.TypeString) + } + if value, ok := mu.mutation.Avatar(); ok { + _spec.SetField(ma.FieldAvatar, field.TypeString, value) + } + if mu.mutation.AvatarCleared() { + _spec.ClearField(ma.FieldAvatar, field.TypeString) + } + if value, ok := mu.mutation.Cid(); ok { + _spec.SetField(ma.FieldCid, field.TypeString, value) + } + if mu.mutation.CidCleared() { + _spec.ClearField(ma.FieldCid, field.TypeString) + } + if value, ok := mu.mutation.URI(); ok { + _spec.SetField(ma.FieldURI, field.TypeString, value) + } + if mu.mutation.URICleared() { + _spec.ClearField(ma.FieldURI, field.TypeString) + } + if value, ok := mu.mutation.Rkey(); ok { + _spec.SetField(ma.FieldRkey, field.TypeString, value) + } + if mu.mutation.RkeyCleared() { + _spec.ClearField(ma.FieldRkey, field.TypeString) + } + if value, ok := mu.mutation.BskyURL(); ok { + _spec.SetField(ma.FieldBskyURL, field.TypeString, value) + } + if mu.mutation.BskyURLCleared() { + _spec.ClearField(ma.FieldBskyURL, field.TypeString) + } + if value, ok := mu.mutation.UpdatedAt(); ok { + _spec.SetField(ma.FieldUpdatedAt, field.TypeTime, value) + } + if mu.mutation.UpdatedAtCleared() { + _spec.ClearField(ma.FieldUpdatedAt, field.TypeTime) + } + if mu.mutation.CreatedAtCleared() { + _spec.ClearField(ma.FieldCreatedAt, field.TypeTime) + } + if mu.mutation.OwnerCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: ma.OwnerTable, + Columns: []string{ma.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mu.mutation.OwnerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: ma.OwnerTable, + Columns: []string{ma.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{ma.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + mu.mutation.done = true + return n, nil +} + +// MaUpdateOne is the builder for updating a single Ma entity. +type MaUpdateOne struct { + config + fields []string + hooks []Hook + mutation *MaMutation +} + +// SetToken sets the "token" field. +func (muo *MaUpdateOne) SetToken(s string) *MaUpdateOne { + muo.mutation.SetToken(s) + return muo +} + +// SetNillableToken sets the "token" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableToken(s *string) *MaUpdateOne { + if s != nil { + muo.SetToken(*s) + } + return muo +} + +// ClearToken clears the value of the "token" field. +func (muo *MaUpdateOne) ClearToken() *MaUpdateOne { + muo.mutation.ClearToken() + return muo +} + +// SetLimit sets the "limit" field. +func (muo *MaUpdateOne) SetLimit(b bool) *MaUpdateOne { + muo.mutation.SetLimit(b) + return muo +} + +// SetNillableLimit sets the "limit" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableLimit(b *bool) *MaUpdateOne { + if b != nil { + muo.SetLimit(*b) + } + return muo +} + +// ClearLimit clears the value of the "limit" field. +func (muo *MaUpdateOne) ClearLimit() *MaUpdateOne { + muo.mutation.ClearLimit() + return muo +} + +// SetCount sets the "count" field. +func (muo *MaUpdateOne) SetCount(i int) *MaUpdateOne { + muo.mutation.ResetCount() + muo.mutation.SetCount(i) + return muo +} + +// SetNillableCount sets the "count" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableCount(i *int) *MaUpdateOne { + if i != nil { + muo.SetCount(*i) + } + return muo +} + +// AddCount adds i to the "count" field. +func (muo *MaUpdateOne) AddCount(i int) *MaUpdateOne { + muo.mutation.AddCount(i) + return muo +} + +// ClearCount clears the value of the "count" field. +func (muo *MaUpdateOne) ClearCount() *MaUpdateOne { + muo.mutation.ClearCount() + return muo +} + +// SetHandle sets the "handle" field. +func (muo *MaUpdateOne) SetHandle(s string) *MaUpdateOne { + muo.mutation.SetHandle(s) + return muo +} + +// SetNillableHandle sets the "handle" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableHandle(s *string) *MaUpdateOne { + if s != nil { + muo.SetHandle(*s) + } + return muo +} + +// ClearHandle clears the value of the "handle" field. +func (muo *MaUpdateOne) ClearHandle() *MaUpdateOne { + muo.mutation.ClearHandle() + return muo +} + +// SetText sets the "text" field. +func (muo *MaUpdateOne) SetText(s string) *MaUpdateOne { + muo.mutation.SetText(s) + return muo +} + +// SetNillableText sets the "text" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableText(s *string) *MaUpdateOne { + if s != nil { + muo.SetText(*s) + } + return muo +} + +// ClearText clears the value of the "text" field. +func (muo *MaUpdateOne) ClearText() *MaUpdateOne { + muo.mutation.ClearText() + return muo +} + +// SetDid sets the "did" field. +func (muo *MaUpdateOne) SetDid(s string) *MaUpdateOne { + muo.mutation.SetDid(s) + return muo +} + +// SetNillableDid sets the "did" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableDid(s *string) *MaUpdateOne { + if s != nil { + muo.SetDid(*s) + } + return muo +} + +// ClearDid clears the value of the "did" field. +func (muo *MaUpdateOne) ClearDid() *MaUpdateOne { + muo.mutation.ClearDid() + return muo +} + +// SetAvatar sets the "avatar" field. +func (muo *MaUpdateOne) SetAvatar(s string) *MaUpdateOne { + muo.mutation.SetAvatar(s) + return muo +} + +// SetNillableAvatar sets the "avatar" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableAvatar(s *string) *MaUpdateOne { + if s != nil { + muo.SetAvatar(*s) + } + return muo +} + +// ClearAvatar clears the value of the "avatar" field. +func (muo *MaUpdateOne) ClearAvatar() *MaUpdateOne { + muo.mutation.ClearAvatar() + return muo +} + +// SetCid sets the "cid" field. +func (muo *MaUpdateOne) SetCid(s string) *MaUpdateOne { + muo.mutation.SetCid(s) + return muo +} + +// SetNillableCid sets the "cid" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableCid(s *string) *MaUpdateOne { + if s != nil { + muo.SetCid(*s) + } + return muo +} + +// ClearCid clears the value of the "cid" field. +func (muo *MaUpdateOne) ClearCid() *MaUpdateOne { + muo.mutation.ClearCid() + return muo +} + +// SetURI sets the "uri" field. +func (muo *MaUpdateOne) SetURI(s string) *MaUpdateOne { + muo.mutation.SetURI(s) + return muo +} + +// SetNillableURI sets the "uri" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableURI(s *string) *MaUpdateOne { + if s != nil { + muo.SetURI(*s) + } + return muo +} + +// ClearURI clears the value of the "uri" field. +func (muo *MaUpdateOne) ClearURI() *MaUpdateOne { + muo.mutation.ClearURI() + return muo +} + +// SetRkey sets the "rkey" field. +func (muo *MaUpdateOne) SetRkey(s string) *MaUpdateOne { + muo.mutation.SetRkey(s) + return muo +} + +// SetNillableRkey sets the "rkey" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableRkey(s *string) *MaUpdateOne { + if s != nil { + muo.SetRkey(*s) + } + return muo +} + +// ClearRkey clears the value of the "rkey" field. +func (muo *MaUpdateOne) ClearRkey() *MaUpdateOne { + muo.mutation.ClearRkey() + return muo +} + +// SetBskyURL sets the "bsky_url" field. +func (muo *MaUpdateOne) SetBskyURL(s string) *MaUpdateOne { + muo.mutation.SetBskyURL(s) + return muo +} + +// SetNillableBskyURL sets the "bsky_url" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableBskyURL(s *string) *MaUpdateOne { + if s != nil { + muo.SetBskyURL(*s) + } + return muo +} + +// ClearBskyURL clears the value of the "bsky_url" field. +func (muo *MaUpdateOne) ClearBskyURL() *MaUpdateOne { + muo.mutation.ClearBskyURL() + return muo +} + +// SetUpdatedAt sets the "updated_at" field. +func (muo *MaUpdateOne) SetUpdatedAt(t time.Time) *MaUpdateOne { + muo.mutation.SetUpdatedAt(t) + return muo +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (muo *MaUpdateOne) SetNillableUpdatedAt(t *time.Time) *MaUpdateOne { + if t != nil { + muo.SetUpdatedAt(*t) + } + return muo +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (muo *MaUpdateOne) ClearUpdatedAt() *MaUpdateOne { + muo.mutation.ClearUpdatedAt() + return muo +} + +// SetOwnerID sets the "owner" edge to the User entity by ID. +func (muo *MaUpdateOne) SetOwnerID(id int) *MaUpdateOne { + muo.mutation.SetOwnerID(id) + return muo +} + +// SetOwner sets the "owner" edge to the User entity. +func (muo *MaUpdateOne) SetOwner(u *User) *MaUpdateOne { + return muo.SetOwnerID(u.ID) +} + +// Mutation returns the MaMutation object of the builder. +func (muo *MaUpdateOne) Mutation() *MaMutation { + return muo.mutation +} + +// ClearOwner clears the "owner" edge to the User entity. +func (muo *MaUpdateOne) ClearOwner() *MaUpdateOne { + muo.mutation.ClearOwner() + return muo +} + +// Where appends a list predicates to the MaUpdate builder. +func (muo *MaUpdateOne) Where(ps ...predicate.Ma) *MaUpdateOne { + muo.mutation.Where(ps...) + return muo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (muo *MaUpdateOne) Select(field string, fields ...string) *MaUpdateOne { + muo.fields = append([]string{field}, fields...) + return muo +} + +// Save executes the query and returns the updated Ma entity. +func (muo *MaUpdateOne) Save(ctx context.Context) (*Ma, error) { + return withHooks[*Ma, MaMutation](ctx, muo.sqlSave, muo.mutation, muo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (muo *MaUpdateOne) SaveX(ctx context.Context) *Ma { + node, err := muo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (muo *MaUpdateOne) Exec(ctx context.Context) error { + _, err := muo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (muo *MaUpdateOne) ExecX(ctx context.Context) { + if err := muo.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (muo *MaUpdateOne) check() error { + if _, ok := muo.mutation.OwnerID(); muo.mutation.OwnerCleared() && !ok { + return errors.New(`ent: clearing a required unique edge "Ma.owner"`) + } + return nil +} + +func (muo *MaUpdateOne) sqlSave(ctx context.Context) (_node *Ma, err error) { + if err := muo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(ma.Table, ma.Columns, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt)) + id, ok := muo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Ma.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := muo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, ma.FieldID) + for _, f := range fields { + if !ma.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != ma.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := muo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := muo.mutation.Token(); ok { + _spec.SetField(ma.FieldToken, field.TypeString, value) + } + if muo.mutation.TokenCleared() { + _spec.ClearField(ma.FieldToken, field.TypeString) + } + if value, ok := muo.mutation.Limit(); ok { + _spec.SetField(ma.FieldLimit, field.TypeBool, value) + } + if muo.mutation.LimitCleared() { + _spec.ClearField(ma.FieldLimit, field.TypeBool) + } + if value, ok := muo.mutation.Count(); ok { + _spec.SetField(ma.FieldCount, field.TypeInt, value) + } + if value, ok := muo.mutation.AddedCount(); ok { + _spec.AddField(ma.FieldCount, field.TypeInt, value) + } + if muo.mutation.CountCleared() { + _spec.ClearField(ma.FieldCount, field.TypeInt) + } + if value, ok := muo.mutation.Handle(); ok { + _spec.SetField(ma.FieldHandle, field.TypeString, value) + } + if muo.mutation.HandleCleared() { + _spec.ClearField(ma.FieldHandle, field.TypeString) + } + if value, ok := muo.mutation.Text(); ok { + _spec.SetField(ma.FieldText, field.TypeString, value) + } + if muo.mutation.TextCleared() { + _spec.ClearField(ma.FieldText, field.TypeString) + } + if value, ok := muo.mutation.Did(); ok { + _spec.SetField(ma.FieldDid, field.TypeString, value) + } + if muo.mutation.DidCleared() { + _spec.ClearField(ma.FieldDid, field.TypeString) + } + if value, ok := muo.mutation.Avatar(); ok { + _spec.SetField(ma.FieldAvatar, field.TypeString, value) + } + if muo.mutation.AvatarCleared() { + _spec.ClearField(ma.FieldAvatar, field.TypeString) + } + if value, ok := muo.mutation.Cid(); ok { + _spec.SetField(ma.FieldCid, field.TypeString, value) + } + if muo.mutation.CidCleared() { + _spec.ClearField(ma.FieldCid, field.TypeString) + } + if value, ok := muo.mutation.URI(); ok { + _spec.SetField(ma.FieldURI, field.TypeString, value) + } + if muo.mutation.URICleared() { + _spec.ClearField(ma.FieldURI, field.TypeString) + } + if value, ok := muo.mutation.Rkey(); ok { + _spec.SetField(ma.FieldRkey, field.TypeString, value) + } + if muo.mutation.RkeyCleared() { + _spec.ClearField(ma.FieldRkey, field.TypeString) + } + if value, ok := muo.mutation.BskyURL(); ok { + _spec.SetField(ma.FieldBskyURL, field.TypeString, value) + } + if muo.mutation.BskyURLCleared() { + _spec.ClearField(ma.FieldBskyURL, field.TypeString) + } + if value, ok := muo.mutation.UpdatedAt(); ok { + _spec.SetField(ma.FieldUpdatedAt, field.TypeTime, value) + } + if muo.mutation.UpdatedAtCleared() { + _spec.ClearField(ma.FieldUpdatedAt, field.TypeTime) + } + if muo.mutation.CreatedAtCleared() { + _spec.ClearField(ma.FieldCreatedAt, field.TypeTime) + } + if muo.mutation.OwnerCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: ma.OwnerTable, + Columns: []string{ma.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := muo.mutation.OwnerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: ma.OwnerTable, + Columns: []string{ma.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Ma{config: muo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{ma.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + muo.mutation.done = true + return _node, nil +} diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 66398cb..5f46470 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -56,6 +56,39 @@ var ( }, }, } + // MasColumns holds the columns for the "mas" table. + MasColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "password", Type: field.TypeString}, + {Name: "token", Type: field.TypeString, Nullable: true}, + {Name: "limit", Type: field.TypeBool, Nullable: true, Default: false}, + {Name: "count", Type: field.TypeInt, Nullable: true}, + {Name: "handle", Type: field.TypeString, Nullable: true}, + {Name: "text", Type: field.TypeString, Nullable: true}, + {Name: "did", Type: field.TypeString, Nullable: true}, + {Name: "avatar", Type: field.TypeString, Nullable: true}, + {Name: "cid", Type: field.TypeString, Nullable: true}, + {Name: "uri", Type: field.TypeString, Nullable: true}, + {Name: "rkey", Type: field.TypeString, Nullable: true}, + {Name: "bsky_url", Type: field.TypeString, Nullable: true}, + {Name: "updated_at", Type: field.TypeTime, Nullable: true}, + {Name: "created_at", Type: field.TypeTime, Nullable: true}, + {Name: "user_ma", Type: field.TypeInt}, + } + // MasTable holds the schema information for the "mas" table. + MasTable = &schema.Table{ + Name: "mas", + Columns: MasColumns, + PrimaryKey: []*schema.Column{MasColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "mas_users_ma", + Columns: []*schema.Column{MasColumns[15]}, + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } // UesColumns holds the columns for the "ues" table. UesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -129,7 +162,7 @@ var ( {Name: "ten_post", Type: field.TypeString, Nullable: true}, {Name: "ten_get", Type: field.TypeString, Nullable: true}, {Name: "ten_at", Type: field.TypeTime, Nullable: true}, - {Name: "next", Type: field.TypeString, Nullable: true, Default: "20240327"}, + {Name: "next", Type: field.TypeString, Nullable: true, Default: "20240401"}, {Name: "room", Type: field.TypeInt, Nullable: true}, {Name: "model", Type: field.TypeBool, Nullable: true}, {Name: "model_at", Type: field.TypeTime, Nullable: true}, @@ -174,6 +207,7 @@ var ( Tables = []*schema.Table{ CardsTable, GroupsTable, + MasTable, UesTable, UsersTable, } @@ -181,6 +215,7 @@ var ( func init() { CardsTable.ForeignKeys[0].RefTable = UsersTable + MasTable.ForeignKeys[0].RefTable = UsersTable UesTable.ForeignKeys[0].RefTable = UsersTable UsersTable.ForeignKeys[0].RefTable = GroupsTable } diff --git a/ent/mutation.go b/ent/mutation.go index 1ca3cf5..5579bb8 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -5,6 +5,7 @@ package ent import ( "api/ent/card" "api/ent/group" + "api/ent/ma" "api/ent/predicate" "api/ent/ue" "api/ent/user" @@ -29,6 +30,7 @@ const ( // Node types. TypeCard = "Card" TypeGroup = "Group" + TypeMa = "Ma" TypeUe = "Ue" TypeUser = "User" ) @@ -1664,6 +1666,1388 @@ func (m *GroupMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Group edge %s", name) } +// MaMutation represents an operation that mutates the Ma nodes in the graph. +type MaMutation struct { + config + op Op + typ string + id *int + password *string + token *string + _limit *bool + count *int + addcount *int + handle *string + text *string + did *string + avatar *string + cid *string + uri *string + rkey *string + bsky_url *string + updated_at *time.Time + created_at *time.Time + clearedFields map[string]struct{} + owner *int + clearedowner bool + done bool + oldValue func(context.Context) (*Ma, error) + predicates []predicate.Ma +} + +var _ ent.Mutation = (*MaMutation)(nil) + +// maOption allows management of the mutation configuration using functional options. +type maOption func(*MaMutation) + +// newMaMutation creates new mutation for the Ma entity. +func newMaMutation(c config, op Op, opts ...maOption) *MaMutation { + m := &MaMutation{ + config: c, + op: op, + typ: TypeMa, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withMaID sets the ID field of the mutation. +func withMaID(id int) maOption { + return func(m *MaMutation) { + var ( + err error + once sync.Once + value *Ma + ) + m.oldValue = func(ctx context.Context) (*Ma, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Ma.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withMa sets the old Ma of the mutation. +func withMa(node *Ma) maOption { + return func(m *MaMutation) { + m.oldValue = func(context.Context) (*Ma, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m MaMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m MaMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *MaMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *MaMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Ma.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetPassword sets the "password" field. +func (m *MaMutation) SetPassword(s string) { + m.password = &s +} + +// Password returns the value of the "password" field in the mutation. +func (m *MaMutation) Password() (r string, exists bool) { + v := m.password + if v == nil { + return + } + return *v, true +} + +// OldPassword returns the old "password" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldPassword(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPassword is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPassword requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPassword: %w", err) + } + return oldValue.Password, nil +} + +// ResetPassword resets all changes to the "password" field. +func (m *MaMutation) ResetPassword() { + m.password = nil +} + +// SetToken sets the "token" field. +func (m *MaMutation) SetToken(s string) { + m.token = &s +} + +// Token returns the value of the "token" field in the mutation. +func (m *MaMutation) Token() (r string, exists bool) { + v := m.token + if v == nil { + return + } + return *v, true +} + +// OldToken returns the old "token" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldToken(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldToken is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldToken requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldToken: %w", err) + } + return oldValue.Token, nil +} + +// ClearToken clears the value of the "token" field. +func (m *MaMutation) ClearToken() { + m.token = nil + m.clearedFields[ma.FieldToken] = struct{}{} +} + +// TokenCleared returns if the "token" field was cleared in this mutation. +func (m *MaMutation) TokenCleared() bool { + _, ok := m.clearedFields[ma.FieldToken] + return ok +} + +// ResetToken resets all changes to the "token" field. +func (m *MaMutation) ResetToken() { + m.token = nil + delete(m.clearedFields, ma.FieldToken) +} + +// SetLimit sets the "limit" field. +func (m *MaMutation) SetLimit(b bool) { + m._limit = &b +} + +// Limit returns the value of the "limit" field in the mutation. +func (m *MaMutation) Limit() (r bool, exists bool) { + v := m._limit + if v == nil { + return + } + return *v, true +} + +// OldLimit returns the old "limit" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldLimit(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLimit is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLimit requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLimit: %w", err) + } + return oldValue.Limit, nil +} + +// ClearLimit clears the value of the "limit" field. +func (m *MaMutation) ClearLimit() { + m._limit = nil + m.clearedFields[ma.FieldLimit] = struct{}{} +} + +// LimitCleared returns if the "limit" field was cleared in this mutation. +func (m *MaMutation) LimitCleared() bool { + _, ok := m.clearedFields[ma.FieldLimit] + return ok +} + +// ResetLimit resets all changes to the "limit" field. +func (m *MaMutation) ResetLimit() { + m._limit = nil + delete(m.clearedFields, ma.FieldLimit) +} + +// SetCount sets the "count" field. +func (m *MaMutation) SetCount(i int) { + m.count = &i + m.addcount = nil +} + +// Count returns the value of the "count" field in the mutation. +func (m *MaMutation) Count() (r int, exists bool) { + v := m.count + if v == nil { + return + } + return *v, true +} + +// OldCount returns the old "count" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldCount(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCount: %w", err) + } + return oldValue.Count, nil +} + +// AddCount adds i to the "count" field. +func (m *MaMutation) AddCount(i int) { + if m.addcount != nil { + *m.addcount += i + } else { + m.addcount = &i + } +} + +// AddedCount returns the value that was added to the "count" field in this mutation. +func (m *MaMutation) AddedCount() (r int, exists bool) { + v := m.addcount + if v == nil { + return + } + return *v, true +} + +// ClearCount clears the value of the "count" field. +func (m *MaMutation) ClearCount() { + m.count = nil + m.addcount = nil + m.clearedFields[ma.FieldCount] = struct{}{} +} + +// CountCleared returns if the "count" field was cleared in this mutation. +func (m *MaMutation) CountCleared() bool { + _, ok := m.clearedFields[ma.FieldCount] + return ok +} + +// ResetCount resets all changes to the "count" field. +func (m *MaMutation) ResetCount() { + m.count = nil + m.addcount = nil + delete(m.clearedFields, ma.FieldCount) +} + +// SetHandle sets the "handle" field. +func (m *MaMutation) SetHandle(s string) { + m.handle = &s +} + +// Handle returns the value of the "handle" field in the mutation. +func (m *MaMutation) Handle() (r string, exists bool) { + v := m.handle + if v == nil { + return + } + return *v, true +} + +// OldHandle returns the old "handle" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldHandle(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldHandle is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldHandle requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHandle: %w", err) + } + return oldValue.Handle, nil +} + +// ClearHandle clears the value of the "handle" field. +func (m *MaMutation) ClearHandle() { + m.handle = nil + m.clearedFields[ma.FieldHandle] = struct{}{} +} + +// HandleCleared returns if the "handle" field was cleared in this mutation. +func (m *MaMutation) HandleCleared() bool { + _, ok := m.clearedFields[ma.FieldHandle] + return ok +} + +// ResetHandle resets all changes to the "handle" field. +func (m *MaMutation) ResetHandle() { + m.handle = nil + delete(m.clearedFields, ma.FieldHandle) +} + +// SetText sets the "text" field. +func (m *MaMutation) SetText(s string) { + m.text = &s +} + +// Text returns the value of the "text" field in the mutation. +func (m *MaMutation) Text() (r string, exists bool) { + v := m.text + if v == nil { + return + } + return *v, true +} + +// OldText returns the old "text" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldText(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldText is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldText requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldText: %w", err) + } + return oldValue.Text, nil +} + +// ClearText clears the value of the "text" field. +func (m *MaMutation) ClearText() { + m.text = nil + m.clearedFields[ma.FieldText] = struct{}{} +} + +// TextCleared returns if the "text" field was cleared in this mutation. +func (m *MaMutation) TextCleared() bool { + _, ok := m.clearedFields[ma.FieldText] + return ok +} + +// ResetText resets all changes to the "text" field. +func (m *MaMutation) ResetText() { + m.text = nil + delete(m.clearedFields, ma.FieldText) +} + +// SetDid sets the "did" field. +func (m *MaMutation) SetDid(s string) { + m.did = &s +} + +// Did returns the value of the "did" field in the mutation. +func (m *MaMutation) Did() (r string, exists bool) { + v := m.did + if v == nil { + return + } + return *v, true +} + +// OldDid returns the old "did" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldDid(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDid is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDid requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDid: %w", err) + } + return oldValue.Did, nil +} + +// ClearDid clears the value of the "did" field. +func (m *MaMutation) ClearDid() { + m.did = nil + m.clearedFields[ma.FieldDid] = struct{}{} +} + +// DidCleared returns if the "did" field was cleared in this mutation. +func (m *MaMutation) DidCleared() bool { + _, ok := m.clearedFields[ma.FieldDid] + return ok +} + +// ResetDid resets all changes to the "did" field. +func (m *MaMutation) ResetDid() { + m.did = nil + delete(m.clearedFields, ma.FieldDid) +} + +// SetAvatar sets the "avatar" field. +func (m *MaMutation) SetAvatar(s string) { + m.avatar = &s +} + +// Avatar returns the value of the "avatar" field in the mutation. +func (m *MaMutation) Avatar() (r string, exists bool) { + v := m.avatar + if v == nil { + return + } + return *v, true +} + +// OldAvatar returns the old "avatar" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldAvatar(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAvatar is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAvatar requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAvatar: %w", err) + } + return oldValue.Avatar, nil +} + +// ClearAvatar clears the value of the "avatar" field. +func (m *MaMutation) ClearAvatar() { + m.avatar = nil + m.clearedFields[ma.FieldAvatar] = struct{}{} +} + +// AvatarCleared returns if the "avatar" field was cleared in this mutation. +func (m *MaMutation) AvatarCleared() bool { + _, ok := m.clearedFields[ma.FieldAvatar] + return ok +} + +// ResetAvatar resets all changes to the "avatar" field. +func (m *MaMutation) ResetAvatar() { + m.avatar = nil + delete(m.clearedFields, ma.FieldAvatar) +} + +// SetCid sets the "cid" field. +func (m *MaMutation) SetCid(s string) { + m.cid = &s +} + +// Cid returns the value of the "cid" field in the mutation. +func (m *MaMutation) Cid() (r string, exists bool) { + v := m.cid + if v == nil { + return + } + return *v, true +} + +// OldCid returns the old "cid" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldCid(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCid is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCid requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCid: %w", err) + } + return oldValue.Cid, nil +} + +// ClearCid clears the value of the "cid" field. +func (m *MaMutation) ClearCid() { + m.cid = nil + m.clearedFields[ma.FieldCid] = struct{}{} +} + +// CidCleared returns if the "cid" field was cleared in this mutation. +func (m *MaMutation) CidCleared() bool { + _, ok := m.clearedFields[ma.FieldCid] + return ok +} + +// ResetCid resets all changes to the "cid" field. +func (m *MaMutation) ResetCid() { + m.cid = nil + delete(m.clearedFields, ma.FieldCid) +} + +// SetURI sets the "uri" field. +func (m *MaMutation) SetURI(s string) { + m.uri = &s +} + +// URI returns the value of the "uri" field in the mutation. +func (m *MaMutation) URI() (r string, exists bool) { + v := m.uri + if v == nil { + return + } + return *v, true +} + +// OldURI returns the old "uri" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldURI(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldURI is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldURI requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldURI: %w", err) + } + return oldValue.URI, nil +} + +// ClearURI clears the value of the "uri" field. +func (m *MaMutation) ClearURI() { + m.uri = nil + m.clearedFields[ma.FieldURI] = struct{}{} +} + +// URICleared returns if the "uri" field was cleared in this mutation. +func (m *MaMutation) URICleared() bool { + _, ok := m.clearedFields[ma.FieldURI] + return ok +} + +// ResetURI resets all changes to the "uri" field. +func (m *MaMutation) ResetURI() { + m.uri = nil + delete(m.clearedFields, ma.FieldURI) +} + +// SetRkey sets the "rkey" field. +func (m *MaMutation) SetRkey(s string) { + m.rkey = &s +} + +// Rkey returns the value of the "rkey" field in the mutation. +func (m *MaMutation) Rkey() (r string, exists bool) { + v := m.rkey + if v == nil { + return + } + return *v, true +} + +// OldRkey returns the old "rkey" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldRkey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRkey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRkey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRkey: %w", err) + } + return oldValue.Rkey, nil +} + +// ClearRkey clears the value of the "rkey" field. +func (m *MaMutation) ClearRkey() { + m.rkey = nil + m.clearedFields[ma.FieldRkey] = struct{}{} +} + +// RkeyCleared returns if the "rkey" field was cleared in this mutation. +func (m *MaMutation) RkeyCleared() bool { + _, ok := m.clearedFields[ma.FieldRkey] + return ok +} + +// ResetRkey resets all changes to the "rkey" field. +func (m *MaMutation) ResetRkey() { + m.rkey = nil + delete(m.clearedFields, ma.FieldRkey) +} + +// SetBskyURL sets the "bsky_url" field. +func (m *MaMutation) SetBskyURL(s string) { + m.bsky_url = &s +} + +// BskyURL returns the value of the "bsky_url" field in the mutation. +func (m *MaMutation) BskyURL() (r string, exists bool) { + v := m.bsky_url + if v == nil { + return + } + return *v, true +} + +// OldBskyURL returns the old "bsky_url" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldBskyURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBskyURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBskyURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBskyURL: %w", err) + } + return oldValue.BskyURL, nil +} + +// ClearBskyURL clears the value of the "bsky_url" field. +func (m *MaMutation) ClearBskyURL() { + m.bsky_url = nil + m.clearedFields[ma.FieldBskyURL] = struct{}{} +} + +// BskyURLCleared returns if the "bsky_url" field was cleared in this mutation. +func (m *MaMutation) BskyURLCleared() bool { + _, ok := m.clearedFields[ma.FieldBskyURL] + return ok +} + +// ResetBskyURL resets all changes to the "bsky_url" field. +func (m *MaMutation) ResetBskyURL() { + m.bsky_url = nil + delete(m.clearedFields, ma.FieldBskyURL) +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *MaMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *MaMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ClearUpdatedAt clears the value of the "updated_at" field. +func (m *MaMutation) ClearUpdatedAt() { + m.updated_at = nil + m.clearedFields[ma.FieldUpdatedAt] = struct{}{} +} + +// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. +func (m *MaMutation) UpdatedAtCleared() bool { + _, ok := m.clearedFields[ma.FieldUpdatedAt] + return ok +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *MaMutation) ResetUpdatedAt() { + m.updated_at = nil + delete(m.clearedFields, ma.FieldUpdatedAt) +} + +// SetCreatedAt sets the "created_at" field. +func (m *MaMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *MaMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Ma entity. +// If the Ma object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MaMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ClearCreatedAt clears the value of the "created_at" field. +func (m *MaMutation) ClearCreatedAt() { + m.created_at = nil + m.clearedFields[ma.FieldCreatedAt] = struct{}{} +} + +// CreatedAtCleared returns if the "created_at" field was cleared in this mutation. +func (m *MaMutation) CreatedAtCleared() bool { + _, ok := m.clearedFields[ma.FieldCreatedAt] + return ok +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *MaMutation) ResetCreatedAt() { + m.created_at = nil + delete(m.clearedFields, ma.FieldCreatedAt) +} + +// SetOwnerID sets the "owner" edge to the User entity by id. +func (m *MaMutation) SetOwnerID(id int) { + m.owner = &id +} + +// ClearOwner clears the "owner" edge to the User entity. +func (m *MaMutation) ClearOwner() { + m.clearedowner = true +} + +// OwnerCleared reports if the "owner" edge to the User entity was cleared. +func (m *MaMutation) OwnerCleared() bool { + return m.clearedowner +} + +// OwnerID returns the "owner" edge ID in the mutation. +func (m *MaMutation) OwnerID() (id int, exists bool) { + if m.owner != nil { + return *m.owner, true + } + return +} + +// OwnerIDs returns the "owner" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// OwnerID instead. It exists only for internal usage by the builders. +func (m *MaMutation) OwnerIDs() (ids []int) { + if id := m.owner; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetOwner resets all changes to the "owner" edge. +func (m *MaMutation) ResetOwner() { + m.owner = nil + m.clearedowner = false +} + +// Where appends a list predicates to the MaMutation builder. +func (m *MaMutation) Where(ps ...predicate.Ma) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the MaMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *MaMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Ma, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *MaMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *MaMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Ma). +func (m *MaMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *MaMutation) Fields() []string { + fields := make([]string, 0, 14) + if m.password != nil { + fields = append(fields, ma.FieldPassword) + } + if m.token != nil { + fields = append(fields, ma.FieldToken) + } + if m._limit != nil { + fields = append(fields, ma.FieldLimit) + } + if m.count != nil { + fields = append(fields, ma.FieldCount) + } + if m.handle != nil { + fields = append(fields, ma.FieldHandle) + } + if m.text != nil { + fields = append(fields, ma.FieldText) + } + if m.did != nil { + fields = append(fields, ma.FieldDid) + } + if m.avatar != nil { + fields = append(fields, ma.FieldAvatar) + } + if m.cid != nil { + fields = append(fields, ma.FieldCid) + } + if m.uri != nil { + fields = append(fields, ma.FieldURI) + } + if m.rkey != nil { + fields = append(fields, ma.FieldRkey) + } + if m.bsky_url != nil { + fields = append(fields, ma.FieldBskyURL) + } + if m.updated_at != nil { + fields = append(fields, ma.FieldUpdatedAt) + } + if m.created_at != nil { + fields = append(fields, ma.FieldCreatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *MaMutation) Field(name string) (ent.Value, bool) { + switch name { + case ma.FieldPassword: + return m.Password() + case ma.FieldToken: + return m.Token() + case ma.FieldLimit: + return m.Limit() + case ma.FieldCount: + return m.Count() + case ma.FieldHandle: + return m.Handle() + case ma.FieldText: + return m.Text() + case ma.FieldDid: + return m.Did() + case ma.FieldAvatar: + return m.Avatar() + case ma.FieldCid: + return m.Cid() + case ma.FieldURI: + return m.URI() + case ma.FieldRkey: + return m.Rkey() + case ma.FieldBskyURL: + return m.BskyURL() + case ma.FieldUpdatedAt: + return m.UpdatedAt() + case ma.FieldCreatedAt: + return m.CreatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *MaMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case ma.FieldPassword: + return m.OldPassword(ctx) + case ma.FieldToken: + return m.OldToken(ctx) + case ma.FieldLimit: + return m.OldLimit(ctx) + case ma.FieldCount: + return m.OldCount(ctx) + case ma.FieldHandle: + return m.OldHandle(ctx) + case ma.FieldText: + return m.OldText(ctx) + case ma.FieldDid: + return m.OldDid(ctx) + case ma.FieldAvatar: + return m.OldAvatar(ctx) + case ma.FieldCid: + return m.OldCid(ctx) + case ma.FieldURI: + return m.OldURI(ctx) + case ma.FieldRkey: + return m.OldRkey(ctx) + case ma.FieldBskyURL: + return m.OldBskyURL(ctx) + case ma.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case ma.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown Ma field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MaMutation) SetField(name string, value ent.Value) error { + switch name { + case ma.FieldPassword: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPassword(v) + return nil + case ma.FieldToken: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetToken(v) + return nil + case ma.FieldLimit: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLimit(v) + return nil + case ma.FieldCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCount(v) + return nil + case ma.FieldHandle: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHandle(v) + return nil + case ma.FieldText: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetText(v) + return nil + case ma.FieldDid: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDid(v) + return nil + case ma.FieldAvatar: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAvatar(v) + return nil + case ma.FieldCid: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCid(v) + return nil + case ma.FieldURI: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetURI(v) + return nil + case ma.FieldRkey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRkey(v) + return nil + case ma.FieldBskyURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBskyURL(v) + return nil + case ma.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case ma.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown Ma field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *MaMutation) AddedFields() []string { + var fields []string + if m.addcount != nil { + fields = append(fields, ma.FieldCount) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *MaMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case ma.FieldCount: + return m.AddedCount() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MaMutation) AddField(name string, value ent.Value) error { + switch name { + case ma.FieldCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCount(v) + return nil + } + return fmt.Errorf("unknown Ma numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *MaMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(ma.FieldToken) { + fields = append(fields, ma.FieldToken) + } + if m.FieldCleared(ma.FieldLimit) { + fields = append(fields, ma.FieldLimit) + } + if m.FieldCleared(ma.FieldCount) { + fields = append(fields, ma.FieldCount) + } + if m.FieldCleared(ma.FieldHandle) { + fields = append(fields, ma.FieldHandle) + } + if m.FieldCleared(ma.FieldText) { + fields = append(fields, ma.FieldText) + } + if m.FieldCleared(ma.FieldDid) { + fields = append(fields, ma.FieldDid) + } + if m.FieldCleared(ma.FieldAvatar) { + fields = append(fields, ma.FieldAvatar) + } + if m.FieldCleared(ma.FieldCid) { + fields = append(fields, ma.FieldCid) + } + if m.FieldCleared(ma.FieldURI) { + fields = append(fields, ma.FieldURI) + } + if m.FieldCleared(ma.FieldRkey) { + fields = append(fields, ma.FieldRkey) + } + if m.FieldCleared(ma.FieldBskyURL) { + fields = append(fields, ma.FieldBskyURL) + } + if m.FieldCleared(ma.FieldUpdatedAt) { + fields = append(fields, ma.FieldUpdatedAt) + } + if m.FieldCleared(ma.FieldCreatedAt) { + fields = append(fields, ma.FieldCreatedAt) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *MaMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *MaMutation) ClearField(name string) error { + switch name { + case ma.FieldToken: + m.ClearToken() + return nil + case ma.FieldLimit: + m.ClearLimit() + return nil + case ma.FieldCount: + m.ClearCount() + return nil + case ma.FieldHandle: + m.ClearHandle() + return nil + case ma.FieldText: + m.ClearText() + return nil + case ma.FieldDid: + m.ClearDid() + return nil + case ma.FieldAvatar: + m.ClearAvatar() + return nil + case ma.FieldCid: + m.ClearCid() + return nil + case ma.FieldURI: + m.ClearURI() + return nil + case ma.FieldRkey: + m.ClearRkey() + return nil + case ma.FieldBskyURL: + m.ClearBskyURL() + return nil + case ma.FieldUpdatedAt: + m.ClearUpdatedAt() + return nil + case ma.FieldCreatedAt: + m.ClearCreatedAt() + return nil + } + return fmt.Errorf("unknown Ma nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *MaMutation) ResetField(name string) error { + switch name { + case ma.FieldPassword: + m.ResetPassword() + return nil + case ma.FieldToken: + m.ResetToken() + return nil + case ma.FieldLimit: + m.ResetLimit() + return nil + case ma.FieldCount: + m.ResetCount() + return nil + case ma.FieldHandle: + m.ResetHandle() + return nil + case ma.FieldText: + m.ResetText() + return nil + case ma.FieldDid: + m.ResetDid() + return nil + case ma.FieldAvatar: + m.ResetAvatar() + return nil + case ma.FieldCid: + m.ResetCid() + return nil + case ma.FieldURI: + m.ResetURI() + return nil + case ma.FieldRkey: + m.ResetRkey() + return nil + case ma.FieldBskyURL: + m.ResetBskyURL() + return nil + case ma.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case ma.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown Ma field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *MaMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.owner != nil { + edges = append(edges, ma.EdgeOwner) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *MaMutation) AddedIDs(name string) []ent.Value { + switch name { + case ma.EdgeOwner: + if id := m.owner; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *MaMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *MaMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *MaMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedowner { + edges = append(edges, ma.EdgeOwner) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *MaMutation) EdgeCleared(name string) bool { + switch name { + case ma.EdgeOwner: + return m.clearedowner + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *MaMutation) ClearEdge(name string) error { + switch name { + case ma.EdgeOwner: + m.ClearOwner() + return nil + } + return fmt.Errorf("unknown Ma unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *MaMutation) ResetEdge(name string) error { + switch name { + case ma.EdgeOwner: + m.ResetOwner() + return nil + } + return fmt.Errorf("unknown Ma edge %s", name) +} + // UeMutation represents an operation that mutates the Ue nodes in the graph. type UeMutation struct { config @@ -3830,6 +5214,9 @@ type UserMutation struct { ue map[int]struct{} removedue map[int]struct{} clearedue bool + ma map[int]struct{} + removedma map[int]struct{} + clearedma bool done bool oldValue func(context.Context) (*User, error) predicates []predicate.User @@ -6801,6 +8188,60 @@ func (m *UserMutation) ResetUe() { m.removedue = nil } +// AddMaIDs adds the "ma" edge to the Ma entity by ids. +func (m *UserMutation) AddMaIDs(ids ...int) { + if m.ma == nil { + m.ma = make(map[int]struct{}) + } + for i := range ids { + m.ma[ids[i]] = struct{}{} + } +} + +// ClearMa clears the "ma" edge to the Ma entity. +func (m *UserMutation) ClearMa() { + m.clearedma = true +} + +// MaCleared reports if the "ma" edge to the Ma entity was cleared. +func (m *UserMutation) MaCleared() bool { + return m.clearedma +} + +// RemoveMaIDs removes the "ma" edge to the Ma entity by IDs. +func (m *UserMutation) RemoveMaIDs(ids ...int) { + if m.removedma == nil { + m.removedma = make(map[int]struct{}) + } + for i := range ids { + delete(m.ma, ids[i]) + m.removedma[ids[i]] = struct{}{} + } +} + +// RemovedMa returns the removed IDs of the "ma" edge to the Ma entity. +func (m *UserMutation) RemovedMaIDs() (ids []int) { + for id := range m.removedma { + ids = append(ids, id) + } + return +} + +// MaIDs returns the "ma" edge IDs in the mutation. +func (m *UserMutation) MaIDs() (ids []int) { + for id := range m.ma { + ids = append(ids, id) + } + return +} + +// ResetMa resets all changes to the "ma" edge. +func (m *UserMutation) ResetMa() { + m.ma = nil + m.clearedma = false + m.removedma = nil +} + // Where appends a list predicates to the UserMutation builder. func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) @@ -8253,13 +9694,16 @@ func (m *UserMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMutation) AddedEdges() []string { - edges := make([]string, 0, 2) + edges := make([]string, 0, 3) if m.card != nil { edges = append(edges, user.EdgeCard) } if m.ue != nil { edges = append(edges, user.EdgeUe) } + if m.ma != nil { + edges = append(edges, user.EdgeMa) + } return edges } @@ -8279,19 +9723,28 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case user.EdgeMa: + ids := make([]ent.Value, 0, len(m.ma)) + for id := range m.ma { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) + edges := make([]string, 0, 3) if m.removedcard != nil { edges = append(edges, user.EdgeCard) } if m.removedue != nil { edges = append(edges, user.EdgeUe) } + if m.removedma != nil { + edges = append(edges, user.EdgeMa) + } return edges } @@ -8311,19 +9764,28 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case user.EdgeMa: + ids := make([]ent.Value, 0, len(m.removedma)) + for id := range m.removedma { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) + edges := make([]string, 0, 3) if m.clearedcard { edges = append(edges, user.EdgeCard) } if m.clearedue { edges = append(edges, user.EdgeUe) } + if m.clearedma { + edges = append(edges, user.EdgeMa) + } return edges } @@ -8335,6 +9797,8 @@ func (m *UserMutation) EdgeCleared(name string) bool { return m.clearedcard case user.EdgeUe: return m.clearedue + case user.EdgeMa: + return m.clearedma } return false } @@ -8357,6 +9821,9 @@ func (m *UserMutation) ResetEdge(name string) error { case user.EdgeUe: m.ResetUe() return nil + case user.EdgeMa: + m.ResetMa() + return nil } return fmt.Errorf("unknown User edge %s", name) } diff --git a/ent/ogent/oas_client_gen.go b/ent/ogent/oas_client_gen.go index 9cd8e3f..965601f 100644 --- a/ent/ogent/oas_client_gen.go +++ b/ent/ogent/oas_client_gen.go @@ -201,6 +201,77 @@ func (c *Client) sendCreateGroup(ctx context.Context, request *CreateGroupReq) ( return result, nil } +// CreateMa invokes createMa operation. +// +// Creates a new Ma and persists it to storage. +// +// POST /mas +func (c *Client) CreateMa(ctx context.Context, request *CreateMaReq) (CreateMaRes, error) { + res, err := c.sendCreateMa(ctx, request) + _ = res + return res, err +} + +func (c *Client) sendCreateMa(ctx context.Context, request *CreateMaReq) (res CreateMaRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("createMa"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "CreateMa", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/mas" + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "POST", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + if err := encodeCreateMaRequest(request, r); err != nil { + return res, errors.Wrap(err, "encode request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeCreateMaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // CreateUe invokes createUe operation. // // Creates a new Ue and persists it to storage. @@ -507,6 +578,88 @@ func (c *Client) sendDeleteGroup(ctx context.Context, params DeleteGroupParams) return result, nil } +// DeleteMa invokes deleteMa operation. +// +// Deletes the Ma with the requested ID. +// +// DELETE /mas/{id} +func (c *Client) DeleteMa(ctx context.Context, params DeleteMaParams) (DeleteMaRes, error) { + res, err := c.sendDeleteMa(ctx, params) + _ = res + return res, err +} + +func (c *Client) sendDeleteMa(ctx context.Context, params DeleteMaParams) (res DeleteMaRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("deleteMa"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "DeleteMa", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/mas/" + { + // Encode "id" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "id", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.IntToString(params.ID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + u.Path += e.Result() + } + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "DELETE", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeDeleteMaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // DeleteUe invokes deleteUe operation. // // Deletes the Ue with the requested ID. @@ -1170,6 +1323,112 @@ func (c *Client) sendListGroupUsers(ctx context.Context, params ListGroupUsersPa return result, nil } +// ListMa invokes listMa operation. +// +// List Mas. +// +// GET /mas +func (c *Client) ListMa(ctx context.Context, params ListMaParams) (ListMaRes, error) { + res, err := c.sendListMa(ctx, params) + _ = res + return res, err +} + +func (c *Client) sendListMa(ctx context.Context, params ListMaParams) (res ListMaRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("listMa"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ListMa", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/mas" + + stage = "EncodeQueryParams" + q := uri.NewQueryEncoder() + { + // Encode "page" parameter. + cfg := uri.QueryParameterEncodingConfig{ + Name: "page", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := params.Page.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return res, errors.Wrap(err, "encode query") + } + } + { + // Encode "itemsPerPage" parameter. + cfg := uri.QueryParameterEncodingConfig{ + Name: "itemsPerPage", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := params.ItemsPerPage.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return res, errors.Wrap(err, "encode query") + } + } + u.RawQuery = q.Values().Encode() + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "GET", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeListMaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // ListUe invokes listUe operation. // // List Ues. @@ -1503,6 +1762,127 @@ func (c *Client) sendListUserCard(ctx context.Context, params ListUserCardParams return result, nil } +// ListUserMa invokes listUserMa operation. +// +// List attached Mas. +// +// GET /users/{id}/ma +func (c *Client) ListUserMa(ctx context.Context, params ListUserMaParams) (ListUserMaRes, error) { + res, err := c.sendListUserMa(ctx, params) + _ = res + return res, err +} + +func (c *Client) sendListUserMa(ctx context.Context, params ListUserMaParams) (res ListUserMaRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("listUserMa"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ListUserMa", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/users/" + { + // Encode "id" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "id", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.IntToString(params.ID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + u.Path += e.Result() + } + u.Path += "/ma" + + stage = "EncodeQueryParams" + q := uri.NewQueryEncoder() + { + // Encode "page" parameter. + cfg := uri.QueryParameterEncodingConfig{ + Name: "page", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := params.Page.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return res, errors.Wrap(err, "encode query") + } + } + { + // Encode "itemsPerPage" parameter. + cfg := uri.QueryParameterEncodingConfig{ + Name: "itemsPerPage", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := params.ItemsPerPage.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return res, errors.Wrap(err, "encode query") + } + } + u.RawQuery = q.Values().Encode() + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "GET", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeListUserMaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // ListUserUe invokes listUserUe operation. // // List attached Ues. @@ -1871,6 +2251,171 @@ func (c *Client) sendReadGroup(ctx context.Context, params ReadGroupParams) (res return result, nil } +// ReadMa invokes readMa operation. +// +// Finds the Ma with the requested ID and returns it. +// +// GET /mas/{id} +func (c *Client) ReadMa(ctx context.Context, params ReadMaParams) (ReadMaRes, error) { + res, err := c.sendReadMa(ctx, params) + _ = res + return res, err +} + +func (c *Client) sendReadMa(ctx context.Context, params ReadMaParams) (res ReadMaRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("readMa"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ReadMa", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/mas/" + { + // Encode "id" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "id", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.IntToString(params.ID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + u.Path += e.Result() + } + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "GET", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeReadMaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// ReadMaOwner invokes readMaOwner operation. +// +// Find the attached User of the Ma with the given ID. +// +// GET /mas/{id}/owner +func (c *Client) ReadMaOwner(ctx context.Context, params ReadMaOwnerParams) (ReadMaOwnerRes, error) { + res, err := c.sendReadMaOwner(ctx, params) + _ = res + return res, err +} + +func (c *Client) sendReadMaOwner(ctx context.Context, params ReadMaOwnerParams) (res ReadMaOwnerRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("readMaOwner"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "ReadMaOwner", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/mas/" + { + // Encode "id" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "id", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.IntToString(params.ID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + u.Path += e.Result() + } + u.Path += "/owner" + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "GET", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeReadMaOwnerResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // ReadUe invokes readUe operation. // // Finds the Ue with the requested ID and returns it. @@ -2288,6 +2833,91 @@ func (c *Client) sendUpdateGroup(ctx context.Context, request *UpdateGroupReq, p return result, nil } +// UpdateMa invokes updateMa operation. +// +// Updates a Ma and persists changes to storage. +// +// PATCH /mas/{id} +func (c *Client) UpdateMa(ctx context.Context, request *UpdateMaReq, params UpdateMaParams) (UpdateMaRes, error) { + res, err := c.sendUpdateMa(ctx, request, params) + _ = res + return res, err +} + +func (c *Client) sendUpdateMa(ctx context.Context, request *UpdateMaReq, params UpdateMaParams) (res UpdateMaRes, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("updateMa"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "UpdateMa", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + u.Path += "/mas/" + { + // Encode "id" parameter. + e := uri.NewPathEncoder(uri.PathEncoderConfig{ + Param: "id", + Style: uri.PathStyleSimple, + Explode: false, + }) + if err := func() error { + return e.EncodeValue(conv.IntToString(params.ID)) + }(); err != nil { + return res, errors.Wrap(err, "encode path") + } + u.Path += e.Result() + } + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "PATCH", u, nil) + if err != nil { + return res, errors.Wrap(err, "create request") + } + if err := encodeUpdateMaRequest(request, r); err != nil { + return res, errors.Wrap(err, "encode request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeUpdateMaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // UpdateUe invokes updateUe operation. // // Updates a Ue and persists changes to storage. diff --git a/ent/ogent/oas_handlers_gen.go b/ent/ogent/oas_handlers_gen.go index 050522e..76490a8 100644 --- a/ent/ogent/oas_handlers_gen.go +++ b/ent/ogent/oas_handlers_gen.go @@ -221,6 +221,108 @@ func (s *Server) handleCreateGroupRequest(args [0]string, w http.ResponseWriter, } } +// handleCreateMaRequest handles createMa operation. +// +// Creates a new Ma and persists it to storage. +// +// POST /mas +func (s *Server) handleCreateMaRequest(args [0]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("createMa"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/mas"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "CreateMa", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "CreateMa", + ID: "createMa", + } + ) + request, close, err := s.decodeCreateMaRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response CreateMaRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "CreateMa", + OperationID: "createMa", + Body: request, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = *CreateMaReq + Params = struct{} + Response = CreateMaRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.CreateMa(ctx, request) + return response, err + }, + ) + } else { + response, err = s.h.CreateMa(ctx, request) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeCreateMaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleCreateUeRequest handles createUe operation. // // Creates a new Ue and persists it to storage. @@ -629,6 +731,108 @@ func (s *Server) handleDeleteGroupRequest(args [1]string, w http.ResponseWriter, } } +// handleDeleteMaRequest handles deleteMa operation. +// +// Deletes the Ma with the requested ID. +// +// DELETE /mas/{id} +func (s *Server) handleDeleteMaRequest(args [1]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("deleteMa"), + semconv.HTTPMethodKey.String("DELETE"), + semconv.HTTPRouteKey.String("/mas/{id}"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "DeleteMa", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "DeleteMa", + ID: "deleteMa", + } + ) + params, err := decodeDeleteMaParams(args, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response DeleteMaRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "DeleteMa", + OperationID: "deleteMa", + Body: nil, + Params: middleware.Parameters{ + { + Name: "id", + In: "path", + }: params.ID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = DeleteMaParams + Response = DeleteMaRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackDeleteMaParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.DeleteMa(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.DeleteMa(ctx, params) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeDeleteMaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleDeleteUeRequest handles deleteUe operation. // // Deletes the Ue with the requested ID. @@ -1359,6 +1563,112 @@ func (s *Server) handleListGroupUsersRequest(args [1]string, w http.ResponseWrit } } +// handleListMaRequest handles listMa operation. +// +// List Mas. +// +// GET /mas +func (s *Server) handleListMaRequest(args [0]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("listMa"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/mas"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ListMa", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ListMa", + ID: "listMa", + } + ) + params, err := decodeListMaParams(args, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response ListMaRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ListMa", + OperationID: "listMa", + Body: nil, + Params: middleware.Parameters{ + { + Name: "page", + In: "query", + }: params.Page, + { + Name: "itemsPerPage", + In: "query", + }: params.ItemsPerPage, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ListMaParams + Response = ListMaRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackListMaParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.ListMa(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.ListMa(ctx, params) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeListMaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleListUeRequest handles listUe operation. // // List Ues. @@ -1681,6 +1991,116 @@ func (s *Server) handleListUserCardRequest(args [1]string, w http.ResponseWriter } } +// handleListUserMaRequest handles listUserMa operation. +// +// List attached Mas. +// +// GET /users/{id}/ma +func (s *Server) handleListUserMaRequest(args [1]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("listUserMa"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/users/{id}/ma"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ListUserMa", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ListUserMa", + ID: "listUserMa", + } + ) + params, err := decodeListUserMaParams(args, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response ListUserMaRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ListUserMa", + OperationID: "listUserMa", + Body: nil, + Params: middleware.Parameters{ + { + Name: "id", + In: "path", + }: params.ID, + { + Name: "page", + In: "query", + }: params.Page, + { + Name: "itemsPerPage", + In: "query", + }: params.ItemsPerPage, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ListUserMaParams + Response = ListUserMaRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackListUserMaParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.ListUserMa(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.ListUserMa(ctx, params) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeListUserMaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleListUserUeRequest handles listUserUe operation. // // List attached Ues. @@ -2097,6 +2517,210 @@ func (s *Server) handleReadGroupRequest(args [1]string, w http.ResponseWriter, r } } +// handleReadMaRequest handles readMa operation. +// +// Finds the Ma with the requested ID and returns it. +// +// GET /mas/{id} +func (s *Server) handleReadMaRequest(args [1]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("readMa"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/mas/{id}"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadMa", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ReadMa", + ID: "readMa", + } + ) + params, err := decodeReadMaParams(args, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response ReadMaRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ReadMa", + OperationID: "readMa", + Body: nil, + Params: middleware.Parameters{ + { + Name: "id", + In: "path", + }: params.ID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ReadMaParams + Response = ReadMaRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackReadMaParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.ReadMa(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.ReadMa(ctx, params) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeReadMaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + +// handleReadMaOwnerRequest handles readMaOwner operation. +// +// Find the attached User of the Ma with the given ID. +// +// GET /mas/{id}/owner +func (s *Server) handleReadMaOwnerRequest(args [1]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("readMaOwner"), + semconv.HTTPMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/mas/{id}/owner"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadMaOwner", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "ReadMaOwner", + ID: "readMaOwner", + } + ) + params, err := decodeReadMaOwnerParams(args, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var response ReadMaOwnerRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "ReadMaOwner", + OperationID: "readMaOwner", + Body: nil, + Params: middleware.Parameters{ + { + Name: "id", + In: "path", + }: params.ID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ReadMaOwnerParams + Response = ReadMaOwnerRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackReadMaOwnerParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.ReadMaOwner(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.ReadMaOwner(ctx, params) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeReadMaOwnerResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleReadUeRequest handles readUe operation. // // Finds the Ue with the requested ID and returns it. @@ -2637,6 +3261,123 @@ func (s *Server) handleUpdateGroupRequest(args [1]string, w http.ResponseWriter, } } +// handleUpdateMaRequest handles updateMa operation. +// +// Updates a Ma and persists changes to storage. +// +// PATCH /mas/{id} +func (s *Server) handleUpdateMaRequest(args [1]string, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("updateMa"), + semconv.HTTPMethodKey.String("PATCH"), + semconv.HTTPRouteKey.String("/mas/{id}"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "UpdateMa", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "UpdateMa", + ID: "updateMa", + } + ) + params, err := decodeUpdateMaParams(args, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + request, close, err := s.decodeUpdateMaRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response UpdateMaRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "UpdateMa", + OperationID: "updateMa", + Body: request, + Params: middleware.Parameters{ + { + Name: "id", + In: "path", + }: params.ID, + }, + Raw: r, + } + + type ( + Request = *UpdateMaReq + Params = UpdateMaParams + Response = UpdateMaRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackUpdateMaParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.UpdateMa(ctx, request, params) + return response, err + }, + ) + } else { + response, err = s.h.UpdateMa(ctx, request, params) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeUpdateMaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleUpdateUeRequest handles updateUe operation. // // Updates a Ue and persists changes to storage. diff --git a/ent/ogent/oas_interfaces_gen.go b/ent/ogent/oas_interfaces_gen.go index 41b4b35..b7b87b5 100644 --- a/ent/ogent/oas_interfaces_gen.go +++ b/ent/ogent/oas_interfaces_gen.go @@ -9,6 +9,10 @@ type CreateGroupRes interface { createGroupRes() } +type CreateMaRes interface { + createMaRes() +} + type CreateUeRes interface { createUeRes() } @@ -25,6 +29,10 @@ type DeleteGroupRes interface { deleteGroupRes() } +type DeleteMaRes interface { + deleteMaRes() +} + type DeleteUeRes interface { deleteUeRes() } @@ -45,6 +53,10 @@ type ListGroupUsersRes interface { listGroupUsersRes() } +type ListMaRes interface { + listMaRes() +} + type ListUeRes interface { listUeRes() } @@ -53,6 +65,10 @@ type ListUserCardRes interface { listUserCardRes() } +type ListUserMaRes interface { + listUserMaRes() +} + type ListUserRes interface { listUserRes() } @@ -73,6 +89,14 @@ type ReadGroupRes interface { readGroupRes() } +type ReadMaOwnerRes interface { + readMaOwnerRes() +} + +type ReadMaRes interface { + readMaRes() +} + type ReadUeOwnerRes interface { readUeOwnerRes() } @@ -93,6 +117,10 @@ type UpdateGroupRes interface { updateGroupRes() } +type UpdateMaRes interface { + updateMaRes() +} + type UpdateUeRes interface { updateUeRes() } diff --git a/ent/ogent/oas_json_gen.go b/ent/ogent/oas_json_gen.go index f057afe..f8c97d9 100644 --- a/ent/ogent/oas_json_gen.go +++ b/ent/ogent/oas_json_gen.go @@ -2284,6 +2284,343 @@ func (s *CreateGroupReq) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *CreateMaReq) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CreateMaReq) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("password") + e.Str(s.Password) + } + { + if s.Token.Set { + e.FieldStart("token") + s.Token.Encode(e) + } + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } + { + + e.FieldStart("owner") + e.Int(s.Owner) + } +} + +var jsonFieldsNameOfCreateMaReq = [15]string{ + 0: "password", + 1: "token", + 2: "limit", + 3: "count", + 4: "handle", + 5: "text", + 6: "did", + 7: "avatar", + 8: "cid", + 9: "uri", + 10: "rkey", + 11: "bsky_url", + 12: "updated_at", + 13: "created_at", + 14: "owner", +} + +// Decode decodes CreateMaReq from json. +func (s *CreateMaReq) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CreateMaReq to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "password": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Str() + s.Password = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"password\"") + } + case "token": + if err := func() error { + s.Token.Reset() + if err := s.Token.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"token\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + case "owner": + requiredBitSet[1] |= 1 << 6 + if err := func() error { + v, err := d.Int() + s.Owner = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"owner\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CreateMaReq") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000001, + 0b01000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCreateMaReq) { + name = jsonFieldsNameOfCreateMaReq[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CreateMaReq) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CreateMaReq) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *CreateUeReq) Encode(e *jx.Encoder) { e.ObjStart() @@ -3034,9 +3371,19 @@ func (s *CreateUserReq) encodeFields(e *jx.Encoder) { e.ArrEnd() } } + { + if s.Ma != nil { + e.FieldStart("ma") + e.ArrStart() + for _, elem := range s.Ma { + e.Int(elem) + } + e.ArrEnd() + } + } } -var jsonFieldsNameOfCreateUserReq = [52]string{ +var jsonFieldsNameOfCreateUserReq = [53]string{ 0: "username", 1: "did", 2: "member", @@ -3089,6 +3436,7 @@ var jsonFieldsNameOfCreateUserReq = [52]string{ 49: "coin_at", 50: "card", 51: "ue", + 52: "ma", } // Decode decodes CreateUserReq from json. @@ -3642,6 +3990,25 @@ func (s *CreateUserReq) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"ue\"") } + case "ma": + if err := func() error { + s.Ma = make([]int, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem int + v, err := d.Int() + elem = int(v) + if err != nil { + return err + } + s.Ma = append(s.Ma, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ma\"") + } default: return d.Skip() } @@ -5234,6 +5601,56 @@ func (s *ListGroupUsersOKApplicationJSON) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes ListMaOKApplicationJSON as json. +func (s ListMaOKApplicationJSON) Encode(e *jx.Encoder) { + unwrapped := []MaList(s) + + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() +} + +// Decode decodes ListMaOKApplicationJSON from json. +func (s *ListMaOKApplicationJSON) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ListMaOKApplicationJSON to nil") + } + var unwrapped []MaList + if err := func() error { + unwrapped = make([]MaList, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem MaList + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = ListMaOKApplicationJSON(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ListMaOKApplicationJSON) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ListMaOKApplicationJSON) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes ListUeOKApplicationJSON as json. func (s ListUeOKApplicationJSON) Encode(e *jx.Encoder) { unwrapped := []UeList(s) @@ -5334,6 +5751,56 @@ func (s *ListUserCardOKApplicationJSON) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes ListUserMaOKApplicationJSON as json. +func (s ListUserMaOKApplicationJSON) Encode(e *jx.Encoder) { + unwrapped := []UserMaList(s) + + e.ArrStart() + for _, elem := range unwrapped { + elem.Encode(e) + } + e.ArrEnd() +} + +// Decode decodes ListUserMaOKApplicationJSON from json. +func (s *ListUserMaOKApplicationJSON) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ListUserMaOKApplicationJSON to nil") + } + var unwrapped []UserMaList + if err := func() error { + unwrapped = make([]UserMaList, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem UserMaList + if err := elem.Decode(d); err != nil { + return err + } + unwrapped = append(unwrapped, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "alias") + } + *s = ListUserMaOKApplicationJSON(unwrapped) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ListUserMaOKApplicationJSON) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ListUserMaOKApplicationJSON) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes ListUserOKApplicationJSON as json. func (s ListUserOKApplicationJSON) Encode(e *jx.Encoder) { unwrapped := []UserList(s) @@ -5434,6 +5901,2134 @@ func (s *ListUserUeOKApplicationJSON) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *MaCreate) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *MaCreate) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("id") + e.Int(s.ID) + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } +} + +var jsonFieldsNameOfMaCreate = [13]string{ + 0: "id", + 1: "limit", + 2: "count", + 3: "handle", + 4: "text", + 5: "did", + 6: "avatar", + 7: "cid", + 8: "uri", + 9: "rkey", + 10: "bsky_url", + 11: "updated_at", + 12: "created_at", +} + +// Decode decodes MaCreate from json. +func (s *MaCreate) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MaCreate to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.ID = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode MaCreate") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000001, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMaCreate) { + name = jsonFieldsNameOfMaCreate[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *MaCreate) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MaCreate) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *MaList) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *MaList) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("id") + e.Int(s.ID) + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } +} + +var jsonFieldsNameOfMaList = [13]string{ + 0: "id", + 1: "limit", + 2: "count", + 3: "handle", + 4: "text", + 5: "did", + 6: "avatar", + 7: "cid", + 8: "uri", + 9: "rkey", + 10: "bsky_url", + 11: "updated_at", + 12: "created_at", +} + +// Decode decodes MaList from json. +func (s *MaList) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MaList to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.ID = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode MaList") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000001, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMaList) { + name = jsonFieldsNameOfMaList[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *MaList) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MaList) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *MaOwnerRead) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *MaOwnerRead) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("id") + e.Int(s.ID) + } + { + + e.FieldStart("username") + e.Str(s.Username) + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Member.Set { + e.FieldStart("member") + s.Member.Encode(e) + } + } + { + if s.Book.Set { + e.FieldStart("book") + s.Book.Encode(e) + } + } + { + if s.Manga.Set { + e.FieldStart("manga") + s.Manga.Encode(e) + } + } + { + if s.Badge.Set { + e.FieldStart("badge") + s.Badge.Encode(e) + } + } + { + if s.Bsky.Set { + e.FieldStart("bsky") + s.Bsky.Encode(e) + } + } + { + if s.Mastodon.Set { + e.FieldStart("mastodon") + s.Mastodon.Encode(e) + } + } + { + if s.Delete.Set { + e.FieldStart("delete") + s.Delete.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.RaidAt.Set { + e.FieldStart("raid_at") + s.RaidAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.ServerAt.Set { + e.FieldStart("server_at") + s.ServerAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.EggAt.Set { + e.FieldStart("egg_at") + s.EggAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.Luck.Set { + e.FieldStart("luck") + s.Luck.Encode(e) + } + } + { + if s.LuckAt.Set { + e.FieldStart("luck_at") + s.LuckAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.Like.Set { + e.FieldStart("like") + s.Like.Encode(e) + } + } + { + if s.LikeRank.Set { + e.FieldStart("like_rank") + s.LikeRank.Encode(e) + } + } + { + if s.LikeAt.Set { + e.FieldStart("like_at") + s.LikeAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.Fav.Set { + e.FieldStart("fav") + s.Fav.Encode(e) + } + } + { + if s.Ten.Set { + e.FieldStart("ten") + s.Ten.Encode(e) + } + } + { + if s.TenSu.Set { + e.FieldStart("ten_su") + s.TenSu.Encode(e) + } + } + { + if s.TenKai.Set { + e.FieldStart("ten_kai") + s.TenKai.Encode(e) + } + } + { + if s.Aiten.Set { + e.FieldStart("aiten") + s.Aiten.Encode(e) + } + } + { + if s.TenCard.Set { + e.FieldStart("ten_card") + s.TenCard.Encode(e) + } + } + { + if s.TenDelete.Set { + e.FieldStart("ten_delete") + s.TenDelete.Encode(e) + } + } + { + if s.TenPost.Set { + e.FieldStart("ten_post") + s.TenPost.Encode(e) + } + } + { + if s.TenGet.Set { + e.FieldStart("ten_get") + s.TenGet.Encode(e) + } + } + { + if s.TenAt.Set { + e.FieldStart("ten_at") + s.TenAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.Next.Set { + e.FieldStart("next") + s.Next.Encode(e) + } + } + { + if s.Room.Set { + e.FieldStart("room") + s.Room.Encode(e) + } + } + { + if s.Model.Set { + e.FieldStart("model") + s.Model.Encode(e) + } + } + { + if s.ModelAt.Set { + e.FieldStart("model_at") + s.ModelAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.ModelAttack.Set { + e.FieldStart("model_attack") + s.ModelAttack.Encode(e) + } + } + { + if s.ModelLimit.Set { + e.FieldStart("model_limit") + s.ModelLimit.Encode(e) + } + } + { + if s.ModelSkill.Set { + e.FieldStart("model_skill") + s.ModelSkill.Encode(e) + } + } + { + if s.ModelMode.Set { + e.FieldStart("model_mode") + s.ModelMode.Encode(e) + } + } + { + if s.ModelCritical.Set { + e.FieldStart("model_critical") + s.ModelCritical.Encode(e) + } + } + { + if s.ModelCriticalD.Set { + e.FieldStart("model_critical_d") + s.ModelCriticalD.Encode(e) + } + } + { + if s.Game.Set { + e.FieldStart("game") + s.Game.Encode(e) + } + } + { + if s.GameTest.Set { + e.FieldStart("game_test") + s.GameTest.Encode(e) + } + } + { + if s.GameEnd.Set { + e.FieldStart("game_end") + s.GameEnd.Encode(e) + } + } + { + if s.GameAccount.Set { + e.FieldStart("game_account") + s.GameAccount.Encode(e) + } + } + { + if s.GameLv.Set { + e.FieldStart("game_lv") + s.GameLv.Encode(e) + } + } + { + if s.Coin.Set { + e.FieldStart("coin") + s.Coin.Encode(e) + } + } + { + if s.CoinOpen.Set { + e.FieldStart("coin_open") + s.CoinOpen.Encode(e) + } + } + { + if s.CoinAt.Set { + e.FieldStart("coin_at") + s.CoinAt.Encode(e, json.EncodeDateTime) + } + } +} + +var jsonFieldsNameOfMaOwnerRead = [49]string{ + 0: "id", + 1: "username", + 2: "did", + 3: "member", + 4: "book", + 5: "manga", + 6: "badge", + 7: "bsky", + 8: "mastodon", + 9: "delete", + 10: "handle", + 11: "created_at", + 12: "updated_at", + 13: "raid_at", + 14: "server_at", + 15: "egg_at", + 16: "luck", + 17: "luck_at", + 18: "like", + 19: "like_rank", + 20: "like_at", + 21: "fav", + 22: "ten", + 23: "ten_su", + 24: "ten_kai", + 25: "aiten", + 26: "ten_card", + 27: "ten_delete", + 28: "ten_post", + 29: "ten_get", + 30: "ten_at", + 31: "next", + 32: "room", + 33: "model", + 34: "model_at", + 35: "model_attack", + 36: "model_limit", + 37: "model_skill", + 38: "model_mode", + 39: "model_critical", + 40: "model_critical_d", + 41: "game", + 42: "game_test", + 43: "game_end", + 44: "game_account", + 45: "game_lv", + 46: "coin", + 47: "coin_open", + 48: "coin_at", +} + +// Decode decodes MaOwnerRead from json. +func (s *MaOwnerRead) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MaOwnerRead to nil") + } + var requiredBitSet [7]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.ID = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "username": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.Username = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"username\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "member": + if err := func() error { + s.Member.Reset() + if err := s.Member.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"member\"") + } + case "book": + if err := func() error { + s.Book.Reset() + if err := s.Book.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"book\"") + } + case "manga": + if err := func() error { + s.Manga.Reset() + if err := s.Manga.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"manga\"") + } + case "badge": + if err := func() error { + s.Badge.Reset() + if err := s.Badge.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"badge\"") + } + case "bsky": + if err := func() error { + s.Bsky.Reset() + if err := s.Bsky.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky\"") + } + case "mastodon": + if err := func() error { + s.Mastodon.Reset() + if err := s.Mastodon.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"mastodon\"") + } + case "delete": + if err := func() error { + s.Delete.Reset() + if err := s.Delete.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"delete\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "raid_at": + if err := func() error { + s.RaidAt.Reset() + if err := s.RaidAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"raid_at\"") + } + case "server_at": + if err := func() error { + s.ServerAt.Reset() + if err := s.ServerAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"server_at\"") + } + case "egg_at": + if err := func() error { + s.EggAt.Reset() + if err := s.EggAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"egg_at\"") + } + case "luck": + if err := func() error { + s.Luck.Reset() + if err := s.Luck.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"luck\"") + } + case "luck_at": + if err := func() error { + s.LuckAt.Reset() + if err := s.LuckAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"luck_at\"") + } + case "like": + if err := func() error { + s.Like.Reset() + if err := s.Like.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"like\"") + } + case "like_rank": + if err := func() error { + s.LikeRank.Reset() + if err := s.LikeRank.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"like_rank\"") + } + case "like_at": + if err := func() error { + s.LikeAt.Reset() + if err := s.LikeAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"like_at\"") + } + case "fav": + if err := func() error { + s.Fav.Reset() + if err := s.Fav.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"fav\"") + } + case "ten": + if err := func() error { + s.Ten.Reset() + if err := s.Ten.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten\"") + } + case "ten_su": + if err := func() error { + s.TenSu.Reset() + if err := s.TenSu.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_su\"") + } + case "ten_kai": + if err := func() error { + s.TenKai.Reset() + if err := s.TenKai.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_kai\"") + } + case "aiten": + if err := func() error { + s.Aiten.Reset() + if err := s.Aiten.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"aiten\"") + } + case "ten_card": + if err := func() error { + s.TenCard.Reset() + if err := s.TenCard.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_card\"") + } + case "ten_delete": + if err := func() error { + s.TenDelete.Reset() + if err := s.TenDelete.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_delete\"") + } + case "ten_post": + if err := func() error { + s.TenPost.Reset() + if err := s.TenPost.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_post\"") + } + case "ten_get": + if err := func() error { + s.TenGet.Reset() + if err := s.TenGet.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_get\"") + } + case "ten_at": + if err := func() error { + s.TenAt.Reset() + if err := s.TenAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ten_at\"") + } + case "next": + if err := func() error { + s.Next.Reset() + if err := s.Next.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"next\"") + } + case "room": + if err := func() error { + s.Room.Reset() + if err := s.Room.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"room\"") + } + case "model": + if err := func() error { + s.Model.Reset() + if err := s.Model.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model\"") + } + case "model_at": + if err := func() error { + s.ModelAt.Reset() + if err := s.ModelAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_at\"") + } + case "model_attack": + if err := func() error { + s.ModelAttack.Reset() + if err := s.ModelAttack.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_attack\"") + } + case "model_limit": + if err := func() error { + s.ModelLimit.Reset() + if err := s.ModelLimit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_limit\"") + } + case "model_skill": + if err := func() error { + s.ModelSkill.Reset() + if err := s.ModelSkill.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_skill\"") + } + case "model_mode": + if err := func() error { + s.ModelMode.Reset() + if err := s.ModelMode.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_mode\"") + } + case "model_critical": + if err := func() error { + s.ModelCritical.Reset() + if err := s.ModelCritical.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_critical\"") + } + case "model_critical_d": + if err := func() error { + s.ModelCriticalD.Reset() + if err := s.ModelCriticalD.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"model_critical_d\"") + } + case "game": + if err := func() error { + s.Game.Reset() + if err := s.Game.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"game\"") + } + case "game_test": + if err := func() error { + s.GameTest.Reset() + if err := s.GameTest.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"game_test\"") + } + case "game_end": + if err := func() error { + s.GameEnd.Reset() + if err := s.GameEnd.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"game_end\"") + } + case "game_account": + if err := func() error { + s.GameAccount.Reset() + if err := s.GameAccount.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"game_account\"") + } + case "game_lv": + if err := func() error { + s.GameLv.Reset() + if err := s.GameLv.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"game_lv\"") + } + case "coin": + if err := func() error { + s.Coin.Reset() + if err := s.Coin.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"coin\"") + } + case "coin_open": + if err := func() error { + s.CoinOpen.Reset() + if err := s.CoinOpen.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"coin_open\"") + } + case "coin_at": + if err := func() error { + s.CoinAt.Reset() + if err := s.CoinAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"coin_at\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode MaOwnerRead") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [7]uint8{ + 0b00000011, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMaOwnerRead) { + name = jsonFieldsNameOfMaOwnerRead[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *MaOwnerRead) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MaOwnerRead) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *MaRead) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *MaRead) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("id") + e.Int(s.ID) + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } +} + +var jsonFieldsNameOfMaRead = [13]string{ + 0: "id", + 1: "limit", + 2: "count", + 3: "handle", + 4: "text", + 5: "did", + 6: "avatar", + 7: "cid", + 8: "uri", + 9: "rkey", + 10: "bsky_url", + 11: "updated_at", + 12: "created_at", +} + +// Decode decodes MaRead from json. +func (s *MaRead) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MaRead to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.ID = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode MaRead") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000001, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMaRead) { + name = jsonFieldsNameOfMaRead[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *MaRead) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MaRead) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *MaUpdate) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *MaUpdate) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("id") + e.Int(s.ID) + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } +} + +var jsonFieldsNameOfMaUpdate = [13]string{ + 0: "id", + 1: "limit", + 2: "count", + 3: "handle", + 4: "text", + 5: "did", + 6: "avatar", + 7: "cid", + 8: "uri", + 9: "rkey", + 10: "bsky_url", + 11: "updated_at", + 12: "created_at", +} + +// Decode decodes MaUpdate from json. +func (s *MaUpdate) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MaUpdate to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.ID = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode MaUpdate") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000001, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMaUpdate) { + name = jsonFieldsNameOfMaUpdate[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *MaUpdate) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MaUpdate) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes bool as json. func (o OptBool) Encode(e *jx.Encoder) { if !o.Set { @@ -8874,6 +11469,273 @@ func (s *UpdateGroupReq) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *UpdateMaReq) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *UpdateMaReq) encodeFields(e *jx.Encoder) { + { + if s.Token.Set { + e.FieldStart("token") + s.Token.Encode(e) + } + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.Owner.Set { + e.FieldStart("owner") + s.Owner.Encode(e) + } + } +} + +var jsonFieldsNameOfUpdateMaReq = [13]string{ + 0: "token", + 1: "limit", + 2: "count", + 3: "handle", + 4: "text", + 5: "did", + 6: "avatar", + 7: "cid", + 8: "uri", + 9: "rkey", + 10: "bsky_url", + 11: "updated_at", + 12: "owner", +} + +// Decode decodes UpdateMaReq from json. +func (s *UpdateMaReq) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode UpdateMaReq to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "token": + if err := func() error { + s.Token.Reset() + if err := s.Token.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"token\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "owner": + if err := func() error { + s.Owner.Reset() + if err := s.Owner.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"owner\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode UpdateMaReq") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *UpdateMaReq) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *UpdateMaReq) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *UpdateUeReq) Encode(e *jx.Encoder) { e.ObjStart() @@ -9537,9 +12399,19 @@ func (s *UpdateUserReq) encodeFields(e *jx.Encoder) { e.ArrEnd() } } + { + if s.Ma != nil { + e.FieldStart("ma") + e.ArrStart() + for _, elem := range s.Ma { + e.Int(elem) + } + e.ArrEnd() + } + } } -var jsonFieldsNameOfUpdateUserReq = [49]string{ +var jsonFieldsNameOfUpdateUserReq = [50]string{ 0: "did", 1: "member", 2: "book", @@ -9589,6 +12461,7 @@ var jsonFieldsNameOfUpdateUserReq = [49]string{ 46: "coin_at", 47: "card", 48: "ue", + 49: "ma", } // Decode decodes UpdateUserReq from json. @@ -10107,6 +12980,25 @@ func (s *UpdateUserReq) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"ue\"") } + case "ma": + if err := func() error { + s.Ma = make([]int, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem int + v, err := d.Int() + elem = int(v) + if err != nil { + return err + } + s.Ma = append(s.Ma, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"ma\"") + } default: return d.Skip() } @@ -12205,6 +15097,308 @@ func (s *UserList) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *UserMaList) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *UserMaList) encodeFields(e *jx.Encoder) { + { + + e.FieldStart("id") + e.Int(s.ID) + } + { + if s.Limit.Set { + e.FieldStart("limit") + s.Limit.Encode(e) + } + } + { + if s.Count.Set { + e.FieldStart("count") + s.Count.Encode(e) + } + } + { + if s.Handle.Set { + e.FieldStart("handle") + s.Handle.Encode(e) + } + } + { + if s.Text.Set { + e.FieldStart("text") + s.Text.Encode(e) + } + } + { + if s.Did.Set { + e.FieldStart("did") + s.Did.Encode(e) + } + } + { + if s.Avatar.Set { + e.FieldStart("avatar") + s.Avatar.Encode(e) + } + } + { + if s.Cid.Set { + e.FieldStart("cid") + s.Cid.Encode(e) + } + } + { + if s.URI.Set { + e.FieldStart("uri") + s.URI.Encode(e) + } + } + { + if s.Rkey.Set { + e.FieldStart("rkey") + s.Rkey.Encode(e) + } + } + { + if s.BskyURL.Set { + e.FieldStart("bsky_url") + s.BskyURL.Encode(e) + } + } + { + if s.UpdatedAt.Set { + e.FieldStart("updated_at") + s.UpdatedAt.Encode(e, json.EncodeDateTime) + } + } + { + if s.CreatedAt.Set { + e.FieldStart("created_at") + s.CreatedAt.Encode(e, json.EncodeDateTime) + } + } +} + +var jsonFieldsNameOfUserMaList = [13]string{ + 0: "id", + 1: "limit", + 2: "count", + 3: "handle", + 4: "text", + 5: "did", + 6: "avatar", + 7: "cid", + 8: "uri", + 9: "rkey", + 10: "bsky_url", + 11: "updated_at", + 12: "created_at", +} + +// Decode decodes UserMaList from json. +func (s *UserMaList) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode UserMaList to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.ID = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "limit": + if err := func() error { + s.Limit.Reset() + if err := s.Limit.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"limit\"") + } + case "count": + if err := func() error { + s.Count.Reset() + if err := s.Count.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"count\"") + } + case "handle": + if err := func() error { + s.Handle.Reset() + if err := s.Handle.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"handle\"") + } + case "text": + if err := func() error { + s.Text.Reset() + if err := s.Text.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + case "did": + if err := func() error { + s.Did.Reset() + if err := s.Did.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"did\"") + } + case "avatar": + if err := func() error { + s.Avatar.Reset() + if err := s.Avatar.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"avatar\"") + } + case "cid": + if err := func() error { + s.Cid.Reset() + if err := s.Cid.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"cid\"") + } + case "uri": + if err := func() error { + s.URI.Reset() + if err := s.URI.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"uri\"") + } + case "rkey": + if err := func() error { + s.Rkey.Reset() + if err := s.Rkey.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"rkey\"") + } + case "bsky_url": + if err := func() error { + s.BskyURL.Reset() + if err := s.BskyURL.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bsky_url\"") + } + case "updated_at": + if err := func() error { + s.UpdatedAt.Reset() + if err := s.UpdatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "created_at": + if err := func() error { + s.CreatedAt.Reset() + if err := s.CreatedAt.Decode(d, json.DecodeDateTime); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode UserMaList") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b00000001, + 0b00000000, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfUserMaList) { + name = jsonFieldsNameOfUserMaList[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *UserMaList) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *UserMaList) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *UserRead) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/ent/ogent/oas_parameters_gen.go b/ent/ogent/oas_parameters_gen.go index 16c822f..1b0ee32 100644 --- a/ent/ogent/oas_parameters_gen.go +++ b/ent/ogent/oas_parameters_gen.go @@ -139,6 +139,68 @@ func decodeDeleteGroupParams(args [1]string, r *http.Request) (params DeleteGrou return params, nil } +// DeleteMaParams is parameters of deleteMa operation. +type DeleteMaParams struct { + // ID of the Ma. + ID int +} + +func unpackDeleteMaParams(packed middleware.Parameters) (params DeleteMaParams) { + { + key := middleware.ParameterKey{ + Name: "id", + In: "path", + } + params.ID = packed[key].(int) + } + return params +} + +func decodeDeleteMaParams(args [1]string, r *http.Request) (params DeleteMaParams, _ error) { + // Decode path: id. + if err := func() error { + param, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + params.ID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "id", + In: "path", + Err: err, + } + } + return params, nil +} + // DeleteUeParams is parameters of deleteUe operation. type DeleteUeParams struct { // ID of the Ue. @@ -882,6 +944,171 @@ func decodeListGroupUsersParams(args [1]string, r *http.Request) (params ListGro return params, nil } +// ListMaParams is parameters of listMa operation. +type ListMaParams struct { + // What page to render. + Page OptInt + // Item count to render per page. + ItemsPerPage OptInt +} + +func unpackListMaParams(packed middleware.Parameters) (params ListMaParams) { + { + key := middleware.ParameterKey{ + Name: "page", + In: "query", + } + if v, ok := packed[key]; ok { + params.Page = v.(OptInt) + } + } + { + key := middleware.ParameterKey{ + Name: "itemsPerPage", + In: "query", + } + if v, ok := packed[key]; ok { + params.ItemsPerPage = v.(OptInt) + } + } + return params +} + +func decodeListMaParams(args [0]string, r *http.Request) (params ListMaParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) + // Decode query: page. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "page", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotPageVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + paramsDotPageVal = c + return nil + }(); err != nil { + return err + } + params.Page.SetTo(paramsDotPageVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if params.Page.Set { + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + }).Validate(int64(params.Page.Value)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "page", + In: "query", + Err: err, + } + } + // Decode query: itemsPerPage. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "itemsPerPage", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotItemsPerPageVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + paramsDotItemsPerPageVal = c + return nil + }(); err != nil { + return err + } + params.ItemsPerPage.SetTo(paramsDotItemsPerPageVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if params.ItemsPerPage.Set { + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: true, + Max: 5000, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + }).Validate(int64(params.ItemsPerPage.Value)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "itemsPerPage", + In: "query", + Err: err, + } + } + return params, nil +} + // ListUeParams is parameters of listUe operation. type ListUeParams struct { // What page to render. @@ -1379,6 +1606,173 @@ func decodeListUserCardParams(args [1]string, r *http.Request) (params ListUserC return params, nil } +// ListUserMaParams is parameters of listUserMa operation. +type ListUserMaParams struct { + // ID of the User. + ID int + // What page to render. + Page OptInt + // Item count to render per page. + ItemsPerPage OptInt +} + +func unpackListUserMaParams(packed middleware.Parameters) (params ListUserMaParams) { + { + key := middleware.ParameterKey{ + Name: "id", + In: "path", + } + params.ID = packed[key].(int) + } + { + key := middleware.ParameterKey{ + Name: "page", + In: "query", + } + if v, ok := packed[key]; ok { + params.Page = v.(OptInt) + } + } + { + key := middleware.ParameterKey{ + Name: "itemsPerPage", + In: "query", + } + if v, ok := packed[key]; ok { + params.ItemsPerPage = v.(OptInt) + } + } + return params +} + +func decodeListUserMaParams(args [1]string, r *http.Request) (params ListUserMaParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) + // Decode path: id. + if err := func() error { + param, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + params.ID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "id", + In: "path", + Err: err, + } + } + // Decode query: page. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "page", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotPageVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + paramsDotPageVal = c + return nil + }(); err != nil { + return err + } + params.Page.SetTo(paramsDotPageVal) + return nil + }); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "page", + In: "query", + Err: err, + } + } + // Decode query: itemsPerPage. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "itemsPerPage", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotItemsPerPageVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + paramsDotItemsPerPageVal = c + return nil + }(); err != nil { + return err + } + params.ItemsPerPage.SetTo(paramsDotItemsPerPageVal) + return nil + }); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "itemsPerPage", + In: "query", + Err: err, + } + } + return params, nil +} + // ListUserUeParams is parameters of listUserUe operation. type ListUserUeParams struct { // ID of the User. @@ -1732,6 +2126,130 @@ func decodeReadGroupParams(args [1]string, r *http.Request) (params ReadGroupPar return params, nil } +// ReadMaParams is parameters of readMa operation. +type ReadMaParams struct { + // ID of the Ma. + ID int +} + +func unpackReadMaParams(packed middleware.Parameters) (params ReadMaParams) { + { + key := middleware.ParameterKey{ + Name: "id", + In: "path", + } + params.ID = packed[key].(int) + } + return params +} + +func decodeReadMaParams(args [1]string, r *http.Request) (params ReadMaParams, _ error) { + // Decode path: id. + if err := func() error { + param, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + params.ID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "id", + In: "path", + Err: err, + } + } + return params, nil +} + +// ReadMaOwnerParams is parameters of readMaOwner operation. +type ReadMaOwnerParams struct { + // ID of the Ma. + ID int +} + +func unpackReadMaOwnerParams(packed middleware.Parameters) (params ReadMaOwnerParams) { + { + key := middleware.ParameterKey{ + Name: "id", + In: "path", + } + params.ID = packed[key].(int) + } + return params +} + +func decodeReadMaOwnerParams(args [1]string, r *http.Request) (params ReadMaOwnerParams, _ error) { + // Decode path: id. + if err := func() error { + param, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + params.ID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "id", + In: "path", + Err: err, + } + } + return params, nil +} + // ReadUeParams is parameters of readUe operation. type ReadUeParams struct { // ID of the Ue. @@ -2042,6 +2560,68 @@ func decodeUpdateGroupParams(args [1]string, r *http.Request) (params UpdateGrou return params, nil } +// UpdateMaParams is parameters of updateMa operation. +type UpdateMaParams struct { + // ID of the Ma. + ID int +} + +func unpackUpdateMaParams(packed middleware.Parameters) (params UpdateMaParams) { + { + key := middleware.ParameterKey{ + Name: "id", + In: "path", + } + params.ID = packed[key].(int) + } + return params +} + +func decodeUpdateMaParams(args [1]string, r *http.Request) (params UpdateMaParams, _ error) { + // Decode path: id. + if err := func() error { + param, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + params.ID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "id", + In: "path", + Err: err, + } + } + return params, nil +} + // UpdateUeParams is parameters of updateUe operation. type UpdateUeParams struct { // ID of the Ue. diff --git a/ent/ogent/oas_request_decoders_gen.go b/ent/ogent/oas_request_decoders_gen.go index 4c026f4..982725c 100644 --- a/ent/ogent/oas_request_decoders_gen.go +++ b/ent/ogent/oas_request_decoders_gen.go @@ -141,6 +141,69 @@ func (s *Server) decodeCreateGroupRequest(r *http.Request) ( } } +func (s *Server) decodeCreateMaRequest(r *http.Request) ( + req *CreateMaReq, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = multierr.Append(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = multierr.Append(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + if r.ContentLength == 0 { + return req, close, validate.ErrBodyRequired + } + buf, err := io.ReadAll(r.Body) + if err != nil { + return req, close, err + } + + if len(buf) == 0 { + return req, close, validate.ErrBodyRequired + } + + d := jx.DecodeBytes(buf) + + var request CreateMaReq + if err := func() error { + if err := request.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return req, close, err + } + return &request, close, nil + default: + return req, close, validate.InvalidContentType(ct) + } +} + func (s *Server) decodeCreateUeRequest(r *http.Request) ( req *CreateUeReq, close func() error, @@ -393,6 +456,69 @@ func (s *Server) decodeUpdateGroupRequest(r *http.Request) ( } } +func (s *Server) decodeUpdateMaRequest(r *http.Request) ( + req *UpdateMaReq, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = multierr.Append(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = multierr.Append(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + if r.ContentLength == 0 { + return req, close, validate.ErrBodyRequired + } + buf, err := io.ReadAll(r.Body) + if err != nil { + return req, close, err + } + + if len(buf) == 0 { + return req, close, validate.ErrBodyRequired + } + + d := jx.DecodeBytes(buf) + + var request UpdateMaReq + if err := func() error { + if err := request.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return req, close, err + } + return &request, close, nil + default: + return req, close, validate.InvalidContentType(ct) + } +} + func (s *Server) decodeUpdateUeRequest(r *http.Request) ( req *UpdateUeReq, close func() error, diff --git a/ent/ogent/oas_request_encoders_gen.go b/ent/ogent/oas_request_encoders_gen.go index e755d49..f0321d0 100644 --- a/ent/ogent/oas_request_encoders_gen.go +++ b/ent/ogent/oas_request_encoders_gen.go @@ -39,6 +39,20 @@ func encodeCreateGroupRequest( return nil } +func encodeCreateMaRequest( + req *CreateMaReq, + r *http.Request, +) error { + const contentType = "application/json" + e := jx.GetEncoder() + { + req.Encode(e) + } + encoded := e.Bytes() + ht.SetBody(r, bytes.NewReader(encoded), contentType) + return nil +} + func encodeCreateUeRequest( req *CreateUeReq, r *http.Request, @@ -95,6 +109,20 @@ func encodeUpdateGroupRequest( return nil } +func encodeUpdateMaRequest( + req *UpdateMaReq, + r *http.Request, +) error { + const contentType = "application/json" + e := jx.GetEncoder() + { + req.Encode(e) + } + encoded := e.Bytes() + ht.SetBody(r, bytes.NewReader(encoded), contentType) + return nil +} + func encodeUpdateUeRequest( req *UpdateUeReq, r *http.Request, diff --git a/ent/ogent/oas_response_decoders_gen.go b/ent/ogent/oas_response_decoders_gen.go index 53fbc89..8dd8a33 100644 --- a/ent/ogent/oas_response_decoders_gen.go +++ b/ent/ogent/oas_response_decoders_gen.go @@ -306,6 +306,152 @@ func decodeCreateGroupResponse(resp *http.Response) (res CreateGroupRes, err err return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeCreateMaResponse(resp *http.Response) (res CreateMaRes, err error) { + switch resp.StatusCode { + case 200: + // Code 200. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response MaCreate + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeCreateUeResponse(resp *http.Response) (res CreateUeRes, err error) { switch resp.StatusCode { case 200: @@ -896,6 +1042,155 @@ func decodeDeleteGroupResponse(resp *http.Response) (res DeleteGroupRes, err err return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeDeleteMaResponse(resp *http.Response) (res DeleteMaRes, err error) { + switch resp.StatusCode { + case 204: + // Code 204. + return &DeleteMaNoContent{}, nil + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 404: + // Code 404. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R404 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeDeleteUeResponse(resp *http.Response) (res DeleteUeRes, err error) { switch resp.StatusCode { case 204: @@ -1755,6 +2050,187 @@ func decodeListGroupUsersResponse(resp *http.Response) (res ListGroupUsersRes, e return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeListMaResponse(resp *http.Response) (res ListMaRes, err error) { + switch resp.StatusCode { + case 200: + // Code 200. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response ListMaOKApplicationJSON + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 404: + // Code 404. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R404 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeListUeResponse(resp *http.Response) (res ListUeRes, err error) { switch resp.StatusCode { case 200: @@ -2298,6 +2774,187 @@ func decodeListUserCardResponse(resp *http.Response) (res ListUserCardRes, err e return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeListUserMaResponse(resp *http.Response) (res ListUserMaRes, err error) { + switch resp.StatusCode { + case 200: + // Code 200. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response ListUserMaOKApplicationJSON + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 404: + // Code 404. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R404 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeListUserUeResponse(resp *http.Response) (res ListUserUeRes, err error) { switch resp.StatusCode { case 200: @@ -3022,6 +3679,368 @@ func decodeReadGroupResponse(resp *http.Response) (res ReadGroupRes, err error) return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeReadMaResponse(resp *http.Response) (res ReadMaRes, err error) { + switch resp.StatusCode { + case 200: + // Code 200. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response MaRead + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 404: + // Code 404. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R404 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + +func decodeReadMaOwnerResponse(resp *http.Response) (res ReadMaOwnerRes, err error) { + switch resp.StatusCode { + case 200: + // Code 200. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response MaOwnerRead + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 404: + // Code 404. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R404 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeReadUeResponse(resp *http.Response) (res ReadUeRes, err error) { switch resp.StatusCode { case 200: @@ -3927,6 +4946,187 @@ func decodeUpdateGroupResponse(resp *http.Response) (res UpdateGroupRes, err err return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeUpdateMaResponse(resp *http.Response) (res UpdateMaRes, err error) { + switch resp.StatusCode { + case 200: + // Code 200. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response MaUpdate + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 400: + // Code 400. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R400 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 404: + // Code 404. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R404 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 409: + // Code 409. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R409 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + case 500: + // Code 500. + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response R500 + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeUpdateUeResponse(resp *http.Response) (res UpdateUeRes, err error) { switch resp.StatusCode { case 200: diff --git a/ent/ogent/oas_router_gen.go b/ent/ogent/oas_router_gen.go index ed71449..86dff67 100644 --- a/ent/ogent/oas_router_gen.go +++ b/ent/ogent/oas_router_gen.go @@ -239,6 +239,85 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.notAllowed(w, r, "GET") } + return + } + } + } + case 'm': // Prefix: "mas" + if l := len("mas"); len(elem) >= l && elem[0:l] == "mas" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch r.Method { + case "GET": + s.handleListMaRequest([0]string{}, w, r) + case "POST": + s.handleCreateMaRequest([0]string{}, w, r) + default: + s.notAllowed(w, r, "GET,POST") + } + + return + } + switch elem[0] { + case '/': // Prefix: "/" + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "id" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + + if len(elem) == 0 { + switch r.Method { + case "DELETE": + s.handleDeleteMaRequest([1]string{ + args[0], + }, w, r) + case "GET": + s.handleReadMaRequest([1]string{ + args[0], + }, w, r) + case "PATCH": + s.handleUpdateMaRequest([1]string{ + args[0], + }, w, r) + default: + s.notAllowed(w, r, "DELETE,GET,PATCH") + } + + return + } + switch elem[0] { + case '/': // Prefix: "/owner" + if l := len("/owner"); len(elem) >= l && elem[0:l] == "/owner" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleReadMaOwnerRequest([1]string{ + args[0], + }, w, r) + default: + s.notAllowed(w, r, "GET") + } + return } } @@ -442,6 +521,26 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } } + case 'm': // Prefix: "ma" + if l := len("ma"); len(elem) >= l && elem[0:l] == "ma" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleListUserMaRequest([1]string{ + args[0], + }, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } case 'u': // Prefix: "ue" if l := len("ue"); len(elem) >= l && elem[0:l] == "ue" { elem = elem[l:] @@ -770,6 +869,101 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } } } + case 'm': // Prefix: "mas" + if l := len("mas"); len(elem) >= l && elem[0:l] == "mas" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "GET": + r.name = "ListMa" + r.operationID = "listMa" + r.pathPattern = "/mas" + r.args = args + r.count = 0 + return r, true + case "POST": + r.name = "CreateMa" + r.operationID = "createMa" + r.pathPattern = "/mas" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/" + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "id" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + + if len(elem) == 0 { + switch method { + case "DELETE": + r.name = "DeleteMa" + r.operationID = "deleteMa" + r.pathPattern = "/mas/{id}" + r.args = args + r.count = 1 + return r, true + case "GET": + r.name = "ReadMa" + r.operationID = "readMa" + r.pathPattern = "/mas/{id}" + r.args = args + r.count = 1 + return r, true + case "PATCH": + r.name = "UpdateMa" + r.operationID = "updateMa" + r.pathPattern = "/mas/{id}" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/owner" + if l := len("/owner"); len(elem) >= l && elem[0:l] == "/owner" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "GET": + // Leaf: ReadMaOwner + r.name = "ReadMaOwner" + r.operationID = "readMaOwner" + r.pathPattern = "/mas/{id}/owner" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + } + } case 'u': // Prefix: "u" if l := len("u"); len(elem) >= l && elem[0:l] == "u" { elem = elem[l:] @@ -1002,6 +1196,27 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } } } + case 'm': // Prefix: "ma" + if l := len("ma"); len(elem) >= l && elem[0:l] == "ma" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "GET": + // Leaf: ListUserMa + r.name = "ListUserMa" + r.operationID = "listUserMa" + r.pathPattern = "/users/{id}/ma" + r.args = args + r.count = 1 + return r, true + default: + return + } + } case 'u': // Prefix: "ue" if l := len("ue"); len(elem) >= l && elem[0:l] == "ue" { elem = elem[l:] diff --git a/ent/ogent/oas_schemas_gen.go b/ent/ogent/oas_schemas_gen.go index a14d150..48243c9 100644 --- a/ent/ogent/oas_schemas_gen.go +++ b/ent/ogent/oas_schemas_gen.go @@ -1131,6 +1131,174 @@ func (s *CreateGroupReq) SetUsers(val []int) { s.Users = val } +type CreateMaReq struct { + Password string `json:"password"` + Token OptString `json:"token"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + CreatedAt OptDateTime `json:"created_at"` + Owner int `json:"owner"` +} + +// GetPassword returns the value of Password. +func (s *CreateMaReq) GetPassword() string { + return s.Password +} + +// GetToken returns the value of Token. +func (s *CreateMaReq) GetToken() OptString { + return s.Token +} + +// GetLimit returns the value of Limit. +func (s *CreateMaReq) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *CreateMaReq) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *CreateMaReq) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *CreateMaReq) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *CreateMaReq) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *CreateMaReq) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *CreateMaReq) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *CreateMaReq) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *CreateMaReq) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *CreateMaReq) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *CreateMaReq) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *CreateMaReq) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// GetOwner returns the value of Owner. +func (s *CreateMaReq) GetOwner() int { + return s.Owner +} + +// SetPassword sets the value of Password. +func (s *CreateMaReq) SetPassword(val string) { + s.Password = val +} + +// SetToken sets the value of Token. +func (s *CreateMaReq) SetToken(val OptString) { + s.Token = val +} + +// SetLimit sets the value of Limit. +func (s *CreateMaReq) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *CreateMaReq) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *CreateMaReq) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *CreateMaReq) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *CreateMaReq) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *CreateMaReq) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *CreateMaReq) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *CreateMaReq) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *CreateMaReq) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *CreateMaReq) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *CreateMaReq) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *CreateMaReq) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + +// SetOwner sets the value of Owner. +func (s *CreateMaReq) SetOwner(val int) { + s.Owner = val +} + type CreateUeReq struct { Limit OptBool `json:"limit"` LimitBoss OptBool `json:"limit_boss"` @@ -1407,6 +1575,7 @@ type CreateUserReq struct { CoinAt OptDateTime `json:"coin_at"` Card []int `json:"card"` Ue []int `json:"ue"` + Ma []int `json:"ma"` } // GetUsername returns the value of Username. @@ -1669,6 +1838,11 @@ func (s *CreateUserReq) GetUe() []int { return s.Ue } +// GetMa returns the value of Ma. +func (s *CreateUserReq) GetMa() []int { + return s.Ma +} + // SetUsername sets the value of Username. func (s *CreateUserReq) SetUsername(val string) { s.Username = val @@ -1929,6 +2103,11 @@ func (s *CreateUserReq) SetUe(val []int) { s.Ue = val } +// SetMa sets the value of Ma. +func (s *CreateUserReq) SetMa(val []int) { + s.Ma = val +} + // DeleteCardNoContent is response for DeleteCard operation. type DeleteCardNoContent struct{} @@ -1939,6 +2118,11 @@ type DeleteGroupNoContent struct{} func (*DeleteGroupNoContent) deleteGroupRes() {} +// DeleteMaNoContent is response for DeleteMa operation. +type DeleteMaNoContent struct{} + +func (*DeleteMaNoContent) deleteMaRes() {} + // DeleteUeNoContent is response for DeleteUe operation. type DeleteUeNoContent struct{} @@ -2620,6 +2804,10 @@ type ListGroupUsersOKApplicationJSON []GroupUsersList func (*ListGroupUsersOKApplicationJSON) listGroupUsersRes() {} +type ListMaOKApplicationJSON []MaList + +func (*ListMaOKApplicationJSON) listMaRes() {} + type ListUeOKApplicationJSON []UeList func (*ListUeOKApplicationJSON) listUeRes() {} @@ -2628,6 +2816,10 @@ type ListUserCardOKApplicationJSON []UserCardList func (*ListUserCardOKApplicationJSON) listUserCardRes() {} +type ListUserMaOKApplicationJSON []UserMaList + +func (*ListUserMaOKApplicationJSON) listUserMaRes() {} + type ListUserOKApplicationJSON []UserList func (*ListUserOKApplicationJSON) listUserRes() {} @@ -2636,6 +2828,1145 @@ type ListUserUeOKApplicationJSON []UserUeList func (*ListUserUeOKApplicationJSON) listUserUeRes() {} +// Ref: #/components/schemas/MaCreate +type MaCreate struct { + ID int `json:"id"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + CreatedAt OptDateTime `json:"created_at"` +} + +// GetID returns the value of ID. +func (s *MaCreate) GetID() int { + return s.ID +} + +// GetLimit returns the value of Limit. +func (s *MaCreate) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *MaCreate) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *MaCreate) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *MaCreate) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *MaCreate) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *MaCreate) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *MaCreate) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *MaCreate) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *MaCreate) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *MaCreate) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *MaCreate) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *MaCreate) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// SetID sets the value of ID. +func (s *MaCreate) SetID(val int) { + s.ID = val +} + +// SetLimit sets the value of Limit. +func (s *MaCreate) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *MaCreate) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *MaCreate) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *MaCreate) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *MaCreate) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *MaCreate) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *MaCreate) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *MaCreate) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *MaCreate) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *MaCreate) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *MaCreate) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *MaCreate) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + +func (*MaCreate) createMaRes() {} + +// Ref: #/components/schemas/MaList +type MaList struct { + ID int `json:"id"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + CreatedAt OptDateTime `json:"created_at"` +} + +// GetID returns the value of ID. +func (s *MaList) GetID() int { + return s.ID +} + +// GetLimit returns the value of Limit. +func (s *MaList) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *MaList) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *MaList) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *MaList) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *MaList) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *MaList) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *MaList) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *MaList) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *MaList) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *MaList) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *MaList) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *MaList) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// SetID sets the value of ID. +func (s *MaList) SetID(val int) { + s.ID = val +} + +// SetLimit sets the value of Limit. +func (s *MaList) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *MaList) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *MaList) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *MaList) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *MaList) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *MaList) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *MaList) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *MaList) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *MaList) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *MaList) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *MaList) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *MaList) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + +// Ref: #/components/schemas/Ma_OwnerRead +type MaOwnerRead struct { + ID int `json:"id"` + Username string `json:"username"` + Did OptString `json:"did"` + Member OptBool `json:"member"` + Book OptBool `json:"book"` + Manga OptBool `json:"manga"` + Badge OptBool `json:"badge"` + Bsky OptBool `json:"bsky"` + Mastodon OptBool `json:"mastodon"` + Delete OptBool `json:"delete"` + Handle OptBool `json:"handle"` + CreatedAt OptDateTime `json:"created_at"` + UpdatedAt OptDateTime `json:"updated_at"` + RaidAt OptDateTime `json:"raid_at"` + ServerAt OptDateTime `json:"server_at"` + EggAt OptDateTime `json:"egg_at"` + Luck OptInt `json:"luck"` + LuckAt OptDateTime `json:"luck_at"` + Like OptInt `json:"like"` + LikeRank OptInt `json:"like_rank"` + LikeAt OptDateTime `json:"like_at"` + Fav OptInt `json:"fav"` + Ten OptBool `json:"ten"` + TenSu OptInt `json:"ten_su"` + TenKai OptInt `json:"ten_kai"` + Aiten OptInt `json:"aiten"` + TenCard OptString `json:"ten_card"` + TenDelete OptString `json:"ten_delete"` + TenPost OptString `json:"ten_post"` + TenGet OptString `json:"ten_get"` + TenAt OptDateTime `json:"ten_at"` + Next OptString `json:"next"` + Room OptInt `json:"room"` + Model OptBool `json:"model"` + ModelAt OptDateTime `json:"model_at"` + ModelAttack OptInt `json:"model_attack"` + ModelLimit OptInt `json:"model_limit"` + ModelSkill OptInt `json:"model_skill"` + ModelMode OptInt `json:"model_mode"` + ModelCritical OptInt `json:"model_critical"` + ModelCriticalD OptInt `json:"model_critical_d"` + Game OptBool `json:"game"` + GameTest OptBool `json:"game_test"` + GameEnd OptBool `json:"game_end"` + GameAccount OptBool `json:"game_account"` + GameLv OptInt `json:"game_lv"` + Coin OptInt `json:"coin"` + CoinOpen OptBool `json:"coin_open"` + CoinAt OptDateTime `json:"coin_at"` +} + +// GetID returns the value of ID. +func (s *MaOwnerRead) GetID() int { + return s.ID +} + +// GetUsername returns the value of Username. +func (s *MaOwnerRead) GetUsername() string { + return s.Username +} + +// GetDid returns the value of Did. +func (s *MaOwnerRead) GetDid() OptString { + return s.Did +} + +// GetMember returns the value of Member. +func (s *MaOwnerRead) GetMember() OptBool { + return s.Member +} + +// GetBook returns the value of Book. +func (s *MaOwnerRead) GetBook() OptBool { + return s.Book +} + +// GetManga returns the value of Manga. +func (s *MaOwnerRead) GetManga() OptBool { + return s.Manga +} + +// GetBadge returns the value of Badge. +func (s *MaOwnerRead) GetBadge() OptBool { + return s.Badge +} + +// GetBsky returns the value of Bsky. +func (s *MaOwnerRead) GetBsky() OptBool { + return s.Bsky +} + +// GetMastodon returns the value of Mastodon. +func (s *MaOwnerRead) GetMastodon() OptBool { + return s.Mastodon +} + +// GetDelete returns the value of Delete. +func (s *MaOwnerRead) GetDelete() OptBool { + return s.Delete +} + +// GetHandle returns the value of Handle. +func (s *MaOwnerRead) GetHandle() OptBool { + return s.Handle +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *MaOwnerRead) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *MaOwnerRead) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetRaidAt returns the value of RaidAt. +func (s *MaOwnerRead) GetRaidAt() OptDateTime { + return s.RaidAt +} + +// GetServerAt returns the value of ServerAt. +func (s *MaOwnerRead) GetServerAt() OptDateTime { + return s.ServerAt +} + +// GetEggAt returns the value of EggAt. +func (s *MaOwnerRead) GetEggAt() OptDateTime { + return s.EggAt +} + +// GetLuck returns the value of Luck. +func (s *MaOwnerRead) GetLuck() OptInt { + return s.Luck +} + +// GetLuckAt returns the value of LuckAt. +func (s *MaOwnerRead) GetLuckAt() OptDateTime { + return s.LuckAt +} + +// GetLike returns the value of Like. +func (s *MaOwnerRead) GetLike() OptInt { + return s.Like +} + +// GetLikeRank returns the value of LikeRank. +func (s *MaOwnerRead) GetLikeRank() OptInt { + return s.LikeRank +} + +// GetLikeAt returns the value of LikeAt. +func (s *MaOwnerRead) GetLikeAt() OptDateTime { + return s.LikeAt +} + +// GetFav returns the value of Fav. +func (s *MaOwnerRead) GetFav() OptInt { + return s.Fav +} + +// GetTen returns the value of Ten. +func (s *MaOwnerRead) GetTen() OptBool { + return s.Ten +} + +// GetTenSu returns the value of TenSu. +func (s *MaOwnerRead) GetTenSu() OptInt { + return s.TenSu +} + +// GetTenKai returns the value of TenKai. +func (s *MaOwnerRead) GetTenKai() OptInt { + return s.TenKai +} + +// GetAiten returns the value of Aiten. +func (s *MaOwnerRead) GetAiten() OptInt { + return s.Aiten +} + +// GetTenCard returns the value of TenCard. +func (s *MaOwnerRead) GetTenCard() OptString { + return s.TenCard +} + +// GetTenDelete returns the value of TenDelete. +func (s *MaOwnerRead) GetTenDelete() OptString { + return s.TenDelete +} + +// GetTenPost returns the value of TenPost. +func (s *MaOwnerRead) GetTenPost() OptString { + return s.TenPost +} + +// GetTenGet returns the value of TenGet. +func (s *MaOwnerRead) GetTenGet() OptString { + return s.TenGet +} + +// GetTenAt returns the value of TenAt. +func (s *MaOwnerRead) GetTenAt() OptDateTime { + return s.TenAt +} + +// GetNext returns the value of Next. +func (s *MaOwnerRead) GetNext() OptString { + return s.Next +} + +// GetRoom returns the value of Room. +func (s *MaOwnerRead) GetRoom() OptInt { + return s.Room +} + +// GetModel returns the value of Model. +func (s *MaOwnerRead) GetModel() OptBool { + return s.Model +} + +// GetModelAt returns the value of ModelAt. +func (s *MaOwnerRead) GetModelAt() OptDateTime { + return s.ModelAt +} + +// GetModelAttack returns the value of ModelAttack. +func (s *MaOwnerRead) GetModelAttack() OptInt { + return s.ModelAttack +} + +// GetModelLimit returns the value of ModelLimit. +func (s *MaOwnerRead) GetModelLimit() OptInt { + return s.ModelLimit +} + +// GetModelSkill returns the value of ModelSkill. +func (s *MaOwnerRead) GetModelSkill() OptInt { + return s.ModelSkill +} + +// GetModelMode returns the value of ModelMode. +func (s *MaOwnerRead) GetModelMode() OptInt { + return s.ModelMode +} + +// GetModelCritical returns the value of ModelCritical. +func (s *MaOwnerRead) GetModelCritical() OptInt { + return s.ModelCritical +} + +// GetModelCriticalD returns the value of ModelCriticalD. +func (s *MaOwnerRead) GetModelCriticalD() OptInt { + return s.ModelCriticalD +} + +// GetGame returns the value of Game. +func (s *MaOwnerRead) GetGame() OptBool { + return s.Game +} + +// GetGameTest returns the value of GameTest. +func (s *MaOwnerRead) GetGameTest() OptBool { + return s.GameTest +} + +// GetGameEnd returns the value of GameEnd. +func (s *MaOwnerRead) GetGameEnd() OptBool { + return s.GameEnd +} + +// GetGameAccount returns the value of GameAccount. +func (s *MaOwnerRead) GetGameAccount() OptBool { + return s.GameAccount +} + +// GetGameLv returns the value of GameLv. +func (s *MaOwnerRead) GetGameLv() OptInt { + return s.GameLv +} + +// GetCoin returns the value of Coin. +func (s *MaOwnerRead) GetCoin() OptInt { + return s.Coin +} + +// GetCoinOpen returns the value of CoinOpen. +func (s *MaOwnerRead) GetCoinOpen() OptBool { + return s.CoinOpen +} + +// GetCoinAt returns the value of CoinAt. +func (s *MaOwnerRead) GetCoinAt() OptDateTime { + return s.CoinAt +} + +// SetID sets the value of ID. +func (s *MaOwnerRead) SetID(val int) { + s.ID = val +} + +// SetUsername sets the value of Username. +func (s *MaOwnerRead) SetUsername(val string) { + s.Username = val +} + +// SetDid sets the value of Did. +func (s *MaOwnerRead) SetDid(val OptString) { + s.Did = val +} + +// SetMember sets the value of Member. +func (s *MaOwnerRead) SetMember(val OptBool) { + s.Member = val +} + +// SetBook sets the value of Book. +func (s *MaOwnerRead) SetBook(val OptBool) { + s.Book = val +} + +// SetManga sets the value of Manga. +func (s *MaOwnerRead) SetManga(val OptBool) { + s.Manga = val +} + +// SetBadge sets the value of Badge. +func (s *MaOwnerRead) SetBadge(val OptBool) { + s.Badge = val +} + +// SetBsky sets the value of Bsky. +func (s *MaOwnerRead) SetBsky(val OptBool) { + s.Bsky = val +} + +// SetMastodon sets the value of Mastodon. +func (s *MaOwnerRead) SetMastodon(val OptBool) { + s.Mastodon = val +} + +// SetDelete sets the value of Delete. +func (s *MaOwnerRead) SetDelete(val OptBool) { + s.Delete = val +} + +// SetHandle sets the value of Handle. +func (s *MaOwnerRead) SetHandle(val OptBool) { + s.Handle = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *MaOwnerRead) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *MaOwnerRead) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetRaidAt sets the value of RaidAt. +func (s *MaOwnerRead) SetRaidAt(val OptDateTime) { + s.RaidAt = val +} + +// SetServerAt sets the value of ServerAt. +func (s *MaOwnerRead) SetServerAt(val OptDateTime) { + s.ServerAt = val +} + +// SetEggAt sets the value of EggAt. +func (s *MaOwnerRead) SetEggAt(val OptDateTime) { + s.EggAt = val +} + +// SetLuck sets the value of Luck. +func (s *MaOwnerRead) SetLuck(val OptInt) { + s.Luck = val +} + +// SetLuckAt sets the value of LuckAt. +func (s *MaOwnerRead) SetLuckAt(val OptDateTime) { + s.LuckAt = val +} + +// SetLike sets the value of Like. +func (s *MaOwnerRead) SetLike(val OptInt) { + s.Like = val +} + +// SetLikeRank sets the value of LikeRank. +func (s *MaOwnerRead) SetLikeRank(val OptInt) { + s.LikeRank = val +} + +// SetLikeAt sets the value of LikeAt. +func (s *MaOwnerRead) SetLikeAt(val OptDateTime) { + s.LikeAt = val +} + +// SetFav sets the value of Fav. +func (s *MaOwnerRead) SetFav(val OptInt) { + s.Fav = val +} + +// SetTen sets the value of Ten. +func (s *MaOwnerRead) SetTen(val OptBool) { + s.Ten = val +} + +// SetTenSu sets the value of TenSu. +func (s *MaOwnerRead) SetTenSu(val OptInt) { + s.TenSu = val +} + +// SetTenKai sets the value of TenKai. +func (s *MaOwnerRead) SetTenKai(val OptInt) { + s.TenKai = val +} + +// SetAiten sets the value of Aiten. +func (s *MaOwnerRead) SetAiten(val OptInt) { + s.Aiten = val +} + +// SetTenCard sets the value of TenCard. +func (s *MaOwnerRead) SetTenCard(val OptString) { + s.TenCard = val +} + +// SetTenDelete sets the value of TenDelete. +func (s *MaOwnerRead) SetTenDelete(val OptString) { + s.TenDelete = val +} + +// SetTenPost sets the value of TenPost. +func (s *MaOwnerRead) SetTenPost(val OptString) { + s.TenPost = val +} + +// SetTenGet sets the value of TenGet. +func (s *MaOwnerRead) SetTenGet(val OptString) { + s.TenGet = val +} + +// SetTenAt sets the value of TenAt. +func (s *MaOwnerRead) SetTenAt(val OptDateTime) { + s.TenAt = val +} + +// SetNext sets the value of Next. +func (s *MaOwnerRead) SetNext(val OptString) { + s.Next = val +} + +// SetRoom sets the value of Room. +func (s *MaOwnerRead) SetRoom(val OptInt) { + s.Room = val +} + +// SetModel sets the value of Model. +func (s *MaOwnerRead) SetModel(val OptBool) { + s.Model = val +} + +// SetModelAt sets the value of ModelAt. +func (s *MaOwnerRead) SetModelAt(val OptDateTime) { + s.ModelAt = val +} + +// SetModelAttack sets the value of ModelAttack. +func (s *MaOwnerRead) SetModelAttack(val OptInt) { + s.ModelAttack = val +} + +// SetModelLimit sets the value of ModelLimit. +func (s *MaOwnerRead) SetModelLimit(val OptInt) { + s.ModelLimit = val +} + +// SetModelSkill sets the value of ModelSkill. +func (s *MaOwnerRead) SetModelSkill(val OptInt) { + s.ModelSkill = val +} + +// SetModelMode sets the value of ModelMode. +func (s *MaOwnerRead) SetModelMode(val OptInt) { + s.ModelMode = val +} + +// SetModelCritical sets the value of ModelCritical. +func (s *MaOwnerRead) SetModelCritical(val OptInt) { + s.ModelCritical = val +} + +// SetModelCriticalD sets the value of ModelCriticalD. +func (s *MaOwnerRead) SetModelCriticalD(val OptInt) { + s.ModelCriticalD = val +} + +// SetGame sets the value of Game. +func (s *MaOwnerRead) SetGame(val OptBool) { + s.Game = val +} + +// SetGameTest sets the value of GameTest. +func (s *MaOwnerRead) SetGameTest(val OptBool) { + s.GameTest = val +} + +// SetGameEnd sets the value of GameEnd. +func (s *MaOwnerRead) SetGameEnd(val OptBool) { + s.GameEnd = val +} + +// SetGameAccount sets the value of GameAccount. +func (s *MaOwnerRead) SetGameAccount(val OptBool) { + s.GameAccount = val +} + +// SetGameLv sets the value of GameLv. +func (s *MaOwnerRead) SetGameLv(val OptInt) { + s.GameLv = val +} + +// SetCoin sets the value of Coin. +func (s *MaOwnerRead) SetCoin(val OptInt) { + s.Coin = val +} + +// SetCoinOpen sets the value of CoinOpen. +func (s *MaOwnerRead) SetCoinOpen(val OptBool) { + s.CoinOpen = val +} + +// SetCoinAt sets the value of CoinAt. +func (s *MaOwnerRead) SetCoinAt(val OptDateTime) { + s.CoinAt = val +} + +func (*MaOwnerRead) readMaOwnerRes() {} + +// Ref: #/components/schemas/MaRead +type MaRead struct { + ID int `json:"id"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + CreatedAt OptDateTime `json:"created_at"` +} + +// GetID returns the value of ID. +func (s *MaRead) GetID() int { + return s.ID +} + +// GetLimit returns the value of Limit. +func (s *MaRead) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *MaRead) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *MaRead) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *MaRead) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *MaRead) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *MaRead) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *MaRead) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *MaRead) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *MaRead) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *MaRead) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *MaRead) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *MaRead) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// SetID sets the value of ID. +func (s *MaRead) SetID(val int) { + s.ID = val +} + +// SetLimit sets the value of Limit. +func (s *MaRead) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *MaRead) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *MaRead) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *MaRead) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *MaRead) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *MaRead) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *MaRead) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *MaRead) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *MaRead) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *MaRead) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *MaRead) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *MaRead) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + +func (*MaRead) readMaRes() {} + +// Ref: #/components/schemas/MaUpdate +type MaUpdate struct { + ID int `json:"id"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + CreatedAt OptDateTime `json:"created_at"` +} + +// GetID returns the value of ID. +func (s *MaUpdate) GetID() int { + return s.ID +} + +// GetLimit returns the value of Limit. +func (s *MaUpdate) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *MaUpdate) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *MaUpdate) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *MaUpdate) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *MaUpdate) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *MaUpdate) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *MaUpdate) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *MaUpdate) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *MaUpdate) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *MaUpdate) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *MaUpdate) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *MaUpdate) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// SetID sets the value of ID. +func (s *MaUpdate) SetID(val int) { + s.ID = val +} + +// SetLimit sets the value of Limit. +func (s *MaUpdate) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *MaUpdate) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *MaUpdate) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *MaUpdate) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *MaUpdate) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *MaUpdate) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *MaUpdate) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *MaUpdate) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *MaUpdate) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *MaUpdate) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *MaUpdate) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *MaUpdate) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + +func (*MaUpdate) updateMaRes() {} + // NewOptBool returns new OptBool with value set to v. func NewOptBool(v bool) OptBool { return OptBool{ @@ -2858,27 +4189,34 @@ func (s *R400) SetErrors(val jx.Raw) { func (*R400) createCardRes() {} func (*R400) createGroupRes() {} +func (*R400) createMaRes() {} func (*R400) createUeRes() {} func (*R400) createUserRes() {} func (*R400) deleteCardRes() {} func (*R400) deleteGroupRes() {} +func (*R400) deleteMaRes() {} func (*R400) deleteUeRes() {} func (*R400) deleteUserRes() {} func (*R400) listCardRes() {} func (*R400) listGroupRes() {} func (*R400) listGroupUsersRes() {} +func (*R400) listMaRes() {} func (*R400) listUeRes() {} func (*R400) listUserCardRes() {} +func (*R400) listUserMaRes() {} func (*R400) listUserRes() {} func (*R400) listUserUeRes() {} func (*R400) readCardOwnerRes() {} func (*R400) readCardRes() {} func (*R400) readGroupRes() {} +func (*R400) readMaOwnerRes() {} +func (*R400) readMaRes() {} func (*R400) readUeOwnerRes() {} func (*R400) readUeRes() {} func (*R400) readUserRes() {} func (*R400) updateCardRes() {} func (*R400) updateGroupRes() {} +func (*R400) updateMaRes() {} func (*R400) updateUeRes() {} func (*R400) updateUserRes() {} @@ -2920,23 +4258,29 @@ func (s *R404) SetErrors(val jx.Raw) { func (*R404) deleteCardRes() {} func (*R404) deleteGroupRes() {} +func (*R404) deleteMaRes() {} func (*R404) deleteUeRes() {} func (*R404) deleteUserRes() {} func (*R404) listCardRes() {} func (*R404) listGroupRes() {} func (*R404) listGroupUsersRes() {} +func (*R404) listMaRes() {} func (*R404) listUeRes() {} func (*R404) listUserCardRes() {} +func (*R404) listUserMaRes() {} func (*R404) listUserRes() {} func (*R404) listUserUeRes() {} func (*R404) readCardOwnerRes() {} func (*R404) readCardRes() {} func (*R404) readGroupRes() {} +func (*R404) readMaOwnerRes() {} +func (*R404) readMaRes() {} func (*R404) readUeOwnerRes() {} func (*R404) readUeRes() {} func (*R404) readUserRes() {} func (*R404) updateCardRes() {} func (*R404) updateGroupRes() {} +func (*R404) updateMaRes() {} func (*R404) updateUeRes() {} func (*R404) updateUserRes() {} @@ -2978,27 +4322,34 @@ func (s *R409) SetErrors(val jx.Raw) { func (*R409) createCardRes() {} func (*R409) createGroupRes() {} +func (*R409) createMaRes() {} func (*R409) createUeRes() {} func (*R409) createUserRes() {} func (*R409) deleteCardRes() {} func (*R409) deleteGroupRes() {} +func (*R409) deleteMaRes() {} func (*R409) deleteUeRes() {} func (*R409) deleteUserRes() {} func (*R409) listCardRes() {} func (*R409) listGroupRes() {} func (*R409) listGroupUsersRes() {} +func (*R409) listMaRes() {} func (*R409) listUeRes() {} func (*R409) listUserCardRes() {} +func (*R409) listUserMaRes() {} func (*R409) listUserRes() {} func (*R409) listUserUeRes() {} func (*R409) readCardOwnerRes() {} func (*R409) readCardRes() {} func (*R409) readGroupRes() {} +func (*R409) readMaOwnerRes() {} +func (*R409) readMaRes() {} func (*R409) readUeOwnerRes() {} func (*R409) readUeRes() {} func (*R409) readUserRes() {} func (*R409) updateCardRes() {} func (*R409) updateGroupRes() {} +func (*R409) updateMaRes() {} func (*R409) updateUeRes() {} func (*R409) updateUserRes() {} @@ -3040,27 +4391,34 @@ func (s *R500) SetErrors(val jx.Raw) { func (*R500) createCardRes() {} func (*R500) createGroupRes() {} +func (*R500) createMaRes() {} func (*R500) createUeRes() {} func (*R500) createUserRes() {} func (*R500) deleteCardRes() {} func (*R500) deleteGroupRes() {} +func (*R500) deleteMaRes() {} func (*R500) deleteUeRes() {} func (*R500) deleteUserRes() {} func (*R500) listCardRes() {} func (*R500) listGroupRes() {} func (*R500) listGroupUsersRes() {} +func (*R500) listMaRes() {} func (*R500) listUeRes() {} func (*R500) listUserCardRes() {} +func (*R500) listUserMaRes() {} func (*R500) listUserRes() {} func (*R500) listUserUeRes() {} func (*R500) readCardOwnerRes() {} func (*R500) readCardRes() {} func (*R500) readGroupRes() {} +func (*R500) readMaOwnerRes() {} +func (*R500) readMaRes() {} func (*R500) readUeOwnerRes() {} func (*R500) readUeRes() {} func (*R500) readUserRes() {} func (*R500) updateCardRes() {} func (*R500) updateGroupRes() {} +func (*R500) updateMaRes() {} func (*R500) updateUeRes() {} func (*R500) updateUserRes() {} @@ -4550,6 +5908,152 @@ func (s *UpdateGroupReq) SetUsers(val []int) { s.Users = val } +type UpdateMaReq struct { + Token OptString `json:"token"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + Owner OptInt `json:"owner"` +} + +// GetToken returns the value of Token. +func (s *UpdateMaReq) GetToken() OptString { + return s.Token +} + +// GetLimit returns the value of Limit. +func (s *UpdateMaReq) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *UpdateMaReq) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *UpdateMaReq) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *UpdateMaReq) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *UpdateMaReq) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *UpdateMaReq) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *UpdateMaReq) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *UpdateMaReq) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *UpdateMaReq) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *UpdateMaReq) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *UpdateMaReq) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetOwner returns the value of Owner. +func (s *UpdateMaReq) GetOwner() OptInt { + return s.Owner +} + +// SetToken sets the value of Token. +func (s *UpdateMaReq) SetToken(val OptString) { + s.Token = val +} + +// SetLimit sets the value of Limit. +func (s *UpdateMaReq) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *UpdateMaReq) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *UpdateMaReq) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *UpdateMaReq) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *UpdateMaReq) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *UpdateMaReq) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *UpdateMaReq) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *UpdateMaReq) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *UpdateMaReq) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *UpdateMaReq) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *UpdateMaReq) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetOwner sets the value of Owner. +func (s *UpdateMaReq) SetOwner(val OptInt) { + s.Owner = val +} + type UpdateUeReq struct { Limit OptBool `json:"limit"` LimitBoss OptBool `json:"limit_boss"` @@ -4801,6 +6305,7 @@ type UpdateUserReq struct { CoinAt OptDateTime `json:"coin_at"` Card []int `json:"card"` Ue []int `json:"ue"` + Ma []int `json:"ma"` } // GetDid returns the value of Did. @@ -5048,6 +6553,11 @@ func (s *UpdateUserReq) GetUe() []int { return s.Ue } +// GetMa returns the value of Ma. +func (s *UpdateUserReq) GetMa() []int { + return s.Ma +} + // SetDid sets the value of Did. func (s *UpdateUserReq) SetDid(val OptString) { s.Did = val @@ -5293,6 +6803,11 @@ func (s *UpdateUserReq) SetUe(val []int) { s.Ue = val } +// SetMa sets the value of Ma. +func (s *UpdateUserReq) SetMa(val []int) { + s.Ma = val +} + // Ref: #/components/schemas/User_CardList type UserCardList struct { ID int `json:"id"` @@ -6484,6 +7999,153 @@ func (s *UserList) SetCoinAt(val OptDateTime) { s.CoinAt = val } +// Ref: #/components/schemas/User_MaList +type UserMaList struct { + ID int `json:"id"` + Limit OptBool `json:"limit"` + Count OptInt `json:"count"` + Handle OptString `json:"handle"` + Text OptString `json:"text"` + Did OptString `json:"did"` + Avatar OptString `json:"avatar"` + Cid OptString `json:"cid"` + URI OptString `json:"uri"` + Rkey OptString `json:"rkey"` + BskyURL OptString `json:"bsky_url"` + UpdatedAt OptDateTime `json:"updated_at"` + CreatedAt OptDateTime `json:"created_at"` +} + +// GetID returns the value of ID. +func (s *UserMaList) GetID() int { + return s.ID +} + +// GetLimit returns the value of Limit. +func (s *UserMaList) GetLimit() OptBool { + return s.Limit +} + +// GetCount returns the value of Count. +func (s *UserMaList) GetCount() OptInt { + return s.Count +} + +// GetHandle returns the value of Handle. +func (s *UserMaList) GetHandle() OptString { + return s.Handle +} + +// GetText returns the value of Text. +func (s *UserMaList) GetText() OptString { + return s.Text +} + +// GetDid returns the value of Did. +func (s *UserMaList) GetDid() OptString { + return s.Did +} + +// GetAvatar returns the value of Avatar. +func (s *UserMaList) GetAvatar() OptString { + return s.Avatar +} + +// GetCid returns the value of Cid. +func (s *UserMaList) GetCid() OptString { + return s.Cid +} + +// GetURI returns the value of URI. +func (s *UserMaList) GetURI() OptString { + return s.URI +} + +// GetRkey returns the value of Rkey. +func (s *UserMaList) GetRkey() OptString { + return s.Rkey +} + +// GetBskyURL returns the value of BskyURL. +func (s *UserMaList) GetBskyURL() OptString { + return s.BskyURL +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *UserMaList) GetUpdatedAt() OptDateTime { + return s.UpdatedAt +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *UserMaList) GetCreatedAt() OptDateTime { + return s.CreatedAt +} + +// SetID sets the value of ID. +func (s *UserMaList) SetID(val int) { + s.ID = val +} + +// SetLimit sets the value of Limit. +func (s *UserMaList) SetLimit(val OptBool) { + s.Limit = val +} + +// SetCount sets the value of Count. +func (s *UserMaList) SetCount(val OptInt) { + s.Count = val +} + +// SetHandle sets the value of Handle. +func (s *UserMaList) SetHandle(val OptString) { + s.Handle = val +} + +// SetText sets the value of Text. +func (s *UserMaList) SetText(val OptString) { + s.Text = val +} + +// SetDid sets the value of Did. +func (s *UserMaList) SetDid(val OptString) { + s.Did = val +} + +// SetAvatar sets the value of Avatar. +func (s *UserMaList) SetAvatar(val OptString) { + s.Avatar = val +} + +// SetCid sets the value of Cid. +func (s *UserMaList) SetCid(val OptString) { + s.Cid = val +} + +// SetURI sets the value of URI. +func (s *UserMaList) SetURI(val OptString) { + s.URI = val +} + +// SetRkey sets the value of Rkey. +func (s *UserMaList) SetRkey(val OptString) { + s.Rkey = val +} + +// SetBskyURL sets the value of BskyURL. +func (s *UserMaList) SetBskyURL(val OptString) { + s.BskyURL = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *UserMaList) SetUpdatedAt(val OptDateTime) { + s.UpdatedAt = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *UserMaList) SetCreatedAt(val OptDateTime) { + s.CreatedAt = val +} + // Ref: #/components/schemas/UserRead type UserRead struct { ID int `json:"id"` diff --git a/ent/ogent/oas_server_gen.go b/ent/ogent/oas_server_gen.go index 91275b1..d07cd1c 100644 --- a/ent/ogent/oas_server_gen.go +++ b/ent/ogent/oas_server_gen.go @@ -20,6 +20,12 @@ type Handler interface { // // POST /groups CreateGroup(ctx context.Context, req *CreateGroupReq) (CreateGroupRes, error) + // CreateMa implements createMa operation. + // + // Creates a new Ma and persists it to storage. + // + // POST /mas + CreateMa(ctx context.Context, req *CreateMaReq) (CreateMaRes, error) // CreateUe implements createUe operation. // // Creates a new Ue and persists it to storage. @@ -44,6 +50,12 @@ type Handler interface { // // DELETE /groups/{id} DeleteGroup(ctx context.Context, params DeleteGroupParams) (DeleteGroupRes, error) + // DeleteMa implements deleteMa operation. + // + // Deletes the Ma with the requested ID. + // + // DELETE /mas/{id} + DeleteMa(ctx context.Context, params DeleteMaParams) (DeleteMaRes, error) // DeleteUe implements deleteUe operation. // // Deletes the Ue with the requested ID. @@ -86,6 +98,12 @@ type Handler interface { // // GET /groups/{id}/users ListGroupUsers(ctx context.Context, params ListGroupUsersParams) (ListGroupUsersRes, error) + // ListMa implements listMa operation. + // + // List Mas. + // + // GET /mas + ListMa(ctx context.Context, params ListMaParams) (ListMaRes, error) // ListUe implements listUe operation. // // List Ues. @@ -104,6 +122,12 @@ type Handler interface { // // GET /users/{id}/card ListUserCard(ctx context.Context, params ListUserCardParams) (ListUserCardRes, error) + // ListUserMa implements listUserMa operation. + // + // List attached Mas. + // + // GET /users/{id}/ma + ListUserMa(ctx context.Context, params ListUserMaParams) (ListUserMaRes, error) // ListUserUe implements listUserUe operation. // // List attached Ues. @@ -128,6 +152,18 @@ type Handler interface { // // GET /groups/{id} ReadGroup(ctx context.Context, params ReadGroupParams) (ReadGroupRes, error) + // ReadMa implements readMa operation. + // + // Finds the Ma with the requested ID and returns it. + // + // GET /mas/{id} + ReadMa(ctx context.Context, params ReadMaParams) (ReadMaRes, error) + // ReadMaOwner implements readMaOwner operation. + // + // Find the attached User of the Ma with the given ID. + // + // GET /mas/{id}/owner + ReadMaOwner(ctx context.Context, params ReadMaOwnerParams) (ReadMaOwnerRes, error) // ReadUe implements readUe operation. // // Finds the Ue with the requested ID and returns it. @@ -158,6 +194,12 @@ type Handler interface { // // PATCH /groups/{id} UpdateGroup(ctx context.Context, req *UpdateGroupReq, params UpdateGroupParams) (UpdateGroupRes, error) + // UpdateMa implements updateMa operation. + // + // Updates a Ma and persists changes to storage. + // + // PATCH /mas/{id} + UpdateMa(ctx context.Context, req *UpdateMaReq, params UpdateMaParams) (UpdateMaRes, error) // UpdateUe implements updateUe operation. // // Updates a Ue and persists changes to storage. diff --git a/ent/ogent/oas_unimplemented_gen.go b/ent/ogent/oas_unimplemented_gen.go index d2b1c82..944d471 100644 --- a/ent/ogent/oas_unimplemented_gen.go +++ b/ent/ogent/oas_unimplemented_gen.go @@ -31,6 +31,15 @@ func (UnimplementedHandler) CreateGroup(ctx context.Context, req *CreateGroupReq return r, ht.ErrNotImplemented } +// CreateMa implements createMa operation. +// +// Creates a new Ma and persists it to storage. +// +// POST /mas +func (UnimplementedHandler) CreateMa(ctx context.Context, req *CreateMaReq) (r CreateMaRes, _ error) { + return r, ht.ErrNotImplemented +} + // CreateUe implements createUe operation. // // Creates a new Ue and persists it to storage. @@ -67,6 +76,15 @@ func (UnimplementedHandler) DeleteGroup(ctx context.Context, params DeleteGroupP return r, ht.ErrNotImplemented } +// DeleteMa implements deleteMa operation. +// +// Deletes the Ma with the requested ID. +// +// DELETE /mas/{id} +func (UnimplementedHandler) DeleteMa(ctx context.Context, params DeleteMaParams) (r DeleteMaRes, _ error) { + return r, ht.ErrNotImplemented +} + // DeleteUe implements deleteUe operation. // // Deletes the Ue with the requested ID. @@ -130,6 +148,15 @@ func (UnimplementedHandler) ListGroupUsers(ctx context.Context, params ListGroup return r, ht.ErrNotImplemented } +// ListMa implements listMa operation. +// +// List Mas. +// +// GET /mas +func (UnimplementedHandler) ListMa(ctx context.Context, params ListMaParams) (r ListMaRes, _ error) { + return r, ht.ErrNotImplemented +} + // ListUe implements listUe operation. // // List Ues. @@ -157,6 +184,15 @@ func (UnimplementedHandler) ListUserCard(ctx context.Context, params ListUserCar return r, ht.ErrNotImplemented } +// ListUserMa implements listUserMa operation. +// +// List attached Mas. +// +// GET /users/{id}/ma +func (UnimplementedHandler) ListUserMa(ctx context.Context, params ListUserMaParams) (r ListUserMaRes, _ error) { + return r, ht.ErrNotImplemented +} + // ListUserUe implements listUserUe operation. // // List attached Ues. @@ -193,6 +229,24 @@ func (UnimplementedHandler) ReadGroup(ctx context.Context, params ReadGroupParam return r, ht.ErrNotImplemented } +// ReadMa implements readMa operation. +// +// Finds the Ma with the requested ID and returns it. +// +// GET /mas/{id} +func (UnimplementedHandler) ReadMa(ctx context.Context, params ReadMaParams) (r ReadMaRes, _ error) { + return r, ht.ErrNotImplemented +} + +// ReadMaOwner implements readMaOwner operation. +// +// Find the attached User of the Ma with the given ID. +// +// GET /mas/{id}/owner +func (UnimplementedHandler) ReadMaOwner(ctx context.Context, params ReadMaOwnerParams) (r ReadMaOwnerRes, _ error) { + return r, ht.ErrNotImplemented +} + // ReadUe implements readUe operation. // // Finds the Ue with the requested ID and returns it. @@ -238,6 +292,15 @@ func (UnimplementedHandler) UpdateGroup(ctx context.Context, req *UpdateGroupReq return r, ht.ErrNotImplemented } +// UpdateMa implements updateMa operation. +// +// Updates a Ma and persists changes to storage. +// +// PATCH /mas/{id} +func (UnimplementedHandler) UpdateMa(ctx context.Context, req *UpdateMaReq, params UpdateMaParams) (r UpdateMaRes, _ error) { + return r, ht.ErrNotImplemented +} + // UpdateUe implements updateUe operation. // // Updates a Ue and persists changes to storage. diff --git a/ent/ogent/oas_validators_gen.go b/ent/ogent/oas_validators_gen.go index 02236c4..e379a73 100644 --- a/ent/ogent/oas_validators_gen.go +++ b/ent/ogent/oas_validators_gen.go @@ -24,6 +24,12 @@ func (s ListGroupUsersOKApplicationJSON) Validate() error { } return nil } +func (s ListMaOKApplicationJSON) Validate() error { + if s == nil { + return errors.New("nil is invalid value") + } + return nil +} func (s ListUeOKApplicationJSON) Validate() error { if s == nil { return errors.New("nil is invalid value") @@ -36,6 +42,12 @@ func (s ListUserCardOKApplicationJSON) Validate() error { } return nil } +func (s ListUserMaOKApplicationJSON) Validate() error { + if s == nil { + return errors.New("nil is invalid value") + } + return nil +} func (s ListUserOKApplicationJSON) Validate() error { if s == nil { return errors.New("nil is invalid value") diff --git a/ent/ogent/ogent.go b/ent/ogent/ogent.go index f6478ef..5a0fa89 100644 --- a/ent/ogent/ogent.go +++ b/ent/ogent/ogent.go @@ -9,9 +9,10 @@ import ( "api/ent" "api/ent/card" "api/ent/group" + "api/ent/ma" "api/ent/ue" "api/ent/user" - "os" + "github.com/go-faster/jx" ) @@ -66,12 +67,12 @@ func (h *OgentHandler) CreateCard(ctx context.Context, req *CreateCardReq) (Crea if v, ok := req.CreatedAt.Get(); ok { b.SetCreatedAt(v) } - // Add all edges. if req.Password == password { b.SetOwnerID(req.Owner) } else { b.SetOwnerID(0) } + // Add all edges. //b.SetOwnerID(req.Owner) // Persist to storage. e, err := b.Save(ctx) @@ -143,6 +144,9 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param if v, ok := req.Status.Get(); ok { b.SetStatus(v) } + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } if v, ok := req.Cp.Get(); ok { b.SetCp(v) } @@ -156,6 +160,9 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param b.SetAuthor(v) } // Add all edges. + //if v, ok := req.Owner.Get(); ok { + // b.SetOwnerID(v) + //} if v, ok := req.Token.Get(); ok { if v == token { b.SetToken(v) @@ -164,7 +171,6 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param } } } - // Persist to storage. e, err := b.Save(ctx) if err != nil { @@ -198,8 +204,8 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param // DeleteCard handles DELETE /cards/{id} requests. func (h *OgentHandler) DeleteCard(ctx context.Context, params DeleteCardParams) (DeleteCardRes, error) { - err := h.client.Card.DeleteOneID(params.ID).Exec(ctx) - //err := h.client.Card.DeleteOneID(0).Exec(ctx) + //err := h.client.Card.DeleteOneID(params.ID).Exec(ctx) + err := h.client.Card.DeleteOneID(0).Exec(ctx) if err != nil { switch { case ent.IsNotFound(err): @@ -353,8 +359,7 @@ func (h *OgentHandler) ReadGroup(ctx context.Context, params ReadGroupParams) (R // UpdateGroup handles PATCH /groups/{id} requests. func (h *OgentHandler) UpdateGroup(ctx context.Context, req *UpdateGroupReq, params UpdateGroupParams) (UpdateGroupRes, error) { - b := h.client.Group.UpdateOneID(0) - //b := h.client.Group.UpdateOneID(params.ID) + b := h.client.Group.UpdateOneID(params.ID) // Add all fields. if v, ok := req.Name.Get(); ok { b.SetName(v) @@ -494,6 +499,287 @@ func (h *OgentHandler) ListGroupUsers(ctx context.Context, params ListGroupUsers return (*ListGroupUsersOKApplicationJSON)(&r), nil } +// CreateMa handles POST /mas requests. +func (h *OgentHandler) CreateMa(ctx context.Context, req *CreateMaReq) (CreateMaRes, error) { + b := h.client.Ma.Create() + // Add all fields. + b.SetPassword(req.Password) + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } + if v, ok := req.Limit.Get(); ok { + b.SetLimit(v) + } + if v, ok := req.Count.Get(); ok { + b.SetCount(v) + } + if v, ok := req.Handle.Get(); ok { + b.SetHandle(v) + } + if v, ok := req.Text.Get(); ok { + b.SetText(v) + } + if v, ok := req.Did.Get(); ok { + b.SetDid(v) + } + if v, ok := req.Avatar.Get(); ok { + b.SetAvatar(v) + } + if v, ok := req.Cid.Get(); ok { + b.SetCid(v) + } + if v, ok := req.URI.Get(); ok { + b.SetURI(v) + } + if v, ok := req.Rkey.Get(); ok { + b.SetRkey(v) + } + if v, ok := req.BskyURL.Get(); ok { + b.SetBskyURL(v) + } + if v, ok := req.UpdatedAt.Get(); ok { + b.SetUpdatedAt(v) + } + if v, ok := req.CreatedAt.Get(); ok { + b.SetCreatedAt(v) + } + // Add all edges. + //b.SetOwnerID(req.Owner) + if req.Password == password { + b.SetOwnerID(req.Owner) + } else { + b.SetOwnerID(0) + } + // Persist to storage. + e, err := b.Save(ctx) + if err != nil { + switch { + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + case ent.IsConstraintError(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + // Reload the entity to attach all eager-loaded edges. + q := h.client.Ma.Query().Where(ma.ID(e.ID)) + e, err = q.Only(ctx) + if err != nil { + // This should never happen. + return nil, err + } + return NewMaCreate(e), nil +} + +// ReadMa handles GET /mas/{id} requests. +func (h *OgentHandler) ReadMa(ctx context.Context, params ReadMaParams) (ReadMaRes, error) { + q := h.client.Ma.Query().Where(ma.IDEQ(params.ID)) + e, err := q.Only(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + return NewMaRead(e), nil +} + +// UpdateMa handles PATCH /mas/{id} requests. +func (h *OgentHandler) UpdateMa(ctx context.Context, req *UpdateMaReq, params UpdateMaParams) (UpdateMaRes, error) { + b := h.client.Ma.UpdateOneID(params.ID) + // Add all fields. + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } + if v, ok := req.Limit.Get(); ok { + b.SetLimit(v) + } + if v, ok := req.Count.Get(); ok { + b.SetCount(v) + } + if v, ok := req.Handle.Get(); ok { + b.SetHandle(v) + } + if v, ok := req.Text.Get(); ok { + b.SetText(v) + } + if v, ok := req.Did.Get(); ok { + b.SetDid(v) + } + if v, ok := req.Avatar.Get(); ok { + b.SetAvatar(v) + } + if v, ok := req.Cid.Get(); ok { + b.SetCid(v) + } + if v, ok := req.URI.Get(); ok { + b.SetURI(v) + } + if v, ok := req.Rkey.Get(); ok { + b.SetRkey(v) + } + if v, ok := req.BskyURL.Get(); ok { + b.SetBskyURL(v) + } + if v, ok := req.UpdatedAt.Get(); ok { + b.SetUpdatedAt(v) + } + // Add all edges. + //if v, ok := req.Owner.Get(); ok { + // b.SetOwnerID(v) + //} + if v, ok := req.Token.Get(); ok { + if v == token { + b.SetToken(v) + if v, ok := req.Owner.Get(); ok { + b.SetOwnerID(v) + } + } + } + // Persist to storage. + e, err := b.Save(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsConstraintError(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + // Reload the entity to attach all eager-loaded edges. + q := h.client.Ma.Query().Where(ma.ID(e.ID)) + e, err = q.Only(ctx) + if err != nil { + // This should never happen. + return nil, err + } + return NewMaUpdate(e), nil +} + +// DeleteMa handles DELETE /mas/{id} requests. +func (h *OgentHandler) DeleteMa(ctx context.Context, params DeleteMaParams) (DeleteMaRes, error) { + err := h.client.Ma.DeleteOneID(0).Exec(ctx) + //err := h.client.Ma.DeleteOneID(params.ID).Exec(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsConstraintError(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + return new(DeleteMaNoContent), nil + +} + +// ListMa handles GET /mas requests. +func (h *OgentHandler) ListMa(ctx context.Context, params ListMaParams) (ListMaRes, error) { + q := h.client.Ma.Query() + page := 1 + if v, ok := params.Page.Get(); ok { + page = v + } + itemsPerPage := 30 + if v, ok := params.ItemsPerPage.Get(); ok { + itemsPerPage = v + } + q.Limit(itemsPerPage).Offset((page - 1) * itemsPerPage) + + es, err := q.All(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + r := NewMaLists(es) + return (*ListMaOKApplicationJSON)(&r), nil +} + +// ReadMaOwner handles GET /mas/{id}/owner requests. +func (h *OgentHandler) ReadMaOwner(ctx context.Context, params ReadMaOwnerParams) (ReadMaOwnerRes, error) { + q := h.client.Ma.Query().Where(ma.IDEQ(params.ID)).QueryOwner() + e, err := q.Only(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + return NewMaOwnerRead(e), nil +} + // CreateUe handles POST /ues requests. func (h *OgentHandler) CreateUe(ctx context.Context, req *CreateUeReq) (CreateUeRes, error) { b := h.client.Ue.Create() @@ -648,6 +934,9 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up if v, ok := req.Mode.Get(); ok { b.SetMode(v) } + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } if v, ok := req.Cp.Get(); ok { b.SetCp(v) } @@ -670,6 +959,9 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up b.SetAuthor(v) } // Add all edges. + //if v, ok := req.Owner.Get(); ok { + // b.SetOwnerID(v) + //} if v, ok := req.Token.Get(); ok { if v == token { b.SetToken(v) @@ -678,7 +970,6 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up } } } - // Persist to storage. e, err := b.Save(ctx) if err != nil { @@ -712,8 +1003,8 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up // DeleteUe handles DELETE /ues/{id} requests. func (h *OgentHandler) DeleteUe(ctx context.Context, params DeleteUeParams) (DeleteUeRes, error) { - err := h.client.Ue.DeleteOneID(0).Exec(ctx) //err := h.client.Ue.DeleteOneID(params.ID).Exec(ctx) + err := h.client.Ue.DeleteOneID(0).Exec(ctx) if err != nil { switch { case ent.IsNotFound(err): @@ -803,7 +1094,14 @@ func (h *OgentHandler) ReadUeOwner(ctx context.Context, params ReadUeOwnerParams // CreateUser handles POST /users requests. func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (CreateUserRes, error) { b := h.client.User.Create() - if v, ok := req.Did.Get(); ok { + // Add all fields. + //b.SetUsername(req.Username) + if req.Password == password { + b.SetUsername(req.Username) + } else { + b.SetUsername("") + } + if v, ok := req.Did.Get(); ok { b.SetDid(v) } if v, ok := req.Member.Get(); ok { @@ -948,17 +1246,10 @@ func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (Crea if v, ok := req.CoinAt.Get(); ok { b.SetCoinAt(v) } - - // Add all fields. - //b.SetUsername(req.Username) - if req.Password == password { - b.SetUsername(req.Username) - } else { - b.SetUsername("") - } // Add all edges. b.AddCardIDs(req.Card...) b.AddUeIDs(req.Ue...) + b.AddMaIDs(req.Ma...) // Persist to storage. e, err := b.Save(ctx) if err != nil { @@ -1021,152 +1312,159 @@ func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, param b := h.client.User.UpdateOneID(params.ID) if v, ok := req.Token.Get(); ok { if v == token { - // Add all fields. - if v, ok := req.Did.Get(); ok { - b.SetDid(v) - } - if v, ok := req.Member.Get(); ok { - b.SetMember(v) - } - if v, ok := req.Book.Get(); ok { - b.SetBook(v) - } - if v, ok := req.Manga.Get(); ok { - b.SetManga(v) - } - if v, ok := req.Badge.Get(); ok { - b.SetBadge(v) - } - if v, ok := req.Bsky.Get(); ok { - b.SetBsky(v) - } - if v, ok := req.Mastodon.Get(); ok { - b.SetMastodon(v) - } - if v, ok := req.Delete.Get(); ok { - b.SetDelete(v) - } - if v, ok := req.Handle.Get(); ok { - b.SetHandle(v) - } - if v, ok := req.UpdatedAt.Get(); ok { - b.SetUpdatedAt(v) - } - if v, ok := req.RaidAt.Get(); ok { - b.SetRaidAt(v) - } - if v, ok := req.ServerAt.Get(); ok { - b.SetServerAt(v) - } - if v, ok := req.EggAt.Get(); ok { - b.SetEggAt(v) - } - if v, ok := req.Luck.Get(); ok { - b.SetLuck(v) - } - if v, ok := req.LuckAt.Get(); ok { - b.SetLuckAt(v) - } - if v, ok := req.Like.Get(); ok { - b.SetLike(v) - } - if v, ok := req.LikeRank.Get(); ok { - b.SetLikeRank(v) - } - if v, ok := req.LikeAt.Get(); ok { - b.SetLikeAt(v) - } - if v, ok := req.Fav.Get(); ok { - b.SetFav(v) - } - if v, ok := req.Ten.Get(); ok { - b.SetTen(v) - } - if v, ok := req.TenSu.Get(); ok { - b.SetTenSu(v) - } - if v, ok := req.TenKai.Get(); ok { - b.SetTenKai(v) - } - if v, ok := req.Aiten.Get(); ok { - b.SetAiten(v) - } - if v, ok := req.TenCard.Get(); ok { - b.SetTenCard(v) - } - if v, ok := req.TenDelete.Get(); ok { - b.SetTenDelete(v) - } - if v, ok := req.TenPost.Get(); ok { - b.SetTenPost(v) - } - if v, ok := req.TenGet.Get(); ok { - b.SetTenGet(v) - } - if v, ok := req.TenAt.Get(); ok { - b.SetTenAt(v) - } - if v, ok := req.Next.Get(); ok { - b.SetNext(v) - } - if v, ok := req.Room.Get(); ok { - b.SetRoom(v) - } - if v, ok := req.Model.Get(); ok { - b.SetModel(v) - } - if v, ok := req.ModelAt.Get(); ok { - b.SetModelAt(v) - } - if v, ok := req.ModelAttack.Get(); ok { - b.SetModelAttack(v) - } - if v, ok := req.ModelLimit.Get(); ok { - b.SetModelLimit(v) - } - if v, ok := req.ModelSkill.Get(); ok { - b.SetModelSkill(v) - } - if v, ok := req.ModelMode.Get(); ok { - b.SetModelMode(v) - } - if v, ok := req.ModelCritical.Get(); ok { - b.SetModelCritical(v) - } - if v, ok := req.ModelCriticalD.Get(); ok { - b.SetModelCriticalD(v) - } - if v, ok := req.Game.Get(); ok { - b.SetGame(v) - } - if v, ok := req.GameTest.Get(); ok { - b.SetGameTest(v) - } - if v, ok := req.GameEnd.Get(); ok { - b.SetGameEnd(v) - } - if v, ok := req.GameAccount.Get(); ok { - b.SetGameAccount(v) - } - if v, ok := req.GameLv.Get(); ok { - b.SetGameLv(v) - } - if v, ok := req.Coin.Get(); ok { - b.SetCoin(v) - } - if v, ok := req.CoinOpen.Get(); ok { - b.SetCoinOpen(v) - } - if v, ok := req.CoinAt.Get(); ok { - b.SetCoinAt(v) - } - // Add all edges. - if req.Card != nil { - b.ClearCard().AddCardIDs(req.Card...) - } - if req.Ue != nil { - b.ClearUe().AddUeIDs(req.Ue...) - } + + // Add all fields. + if v, ok := req.Did.Get(); ok { + b.SetDid(v) + } + if v, ok := req.Member.Get(); ok { + b.SetMember(v) + } + if v, ok := req.Book.Get(); ok { + b.SetBook(v) + } + if v, ok := req.Manga.Get(); ok { + b.SetManga(v) + } + if v, ok := req.Badge.Get(); ok { + b.SetBadge(v) + } + if v, ok := req.Bsky.Get(); ok { + b.SetBsky(v) + } + if v, ok := req.Mastodon.Get(); ok { + b.SetMastodon(v) + } + if v, ok := req.Delete.Get(); ok { + b.SetDelete(v) + } + if v, ok := req.Handle.Get(); ok { + b.SetHandle(v) + } + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } + if v, ok := req.UpdatedAt.Get(); ok { + b.SetUpdatedAt(v) + } + if v, ok := req.RaidAt.Get(); ok { + b.SetRaidAt(v) + } + if v, ok := req.ServerAt.Get(); ok { + b.SetServerAt(v) + } + if v, ok := req.EggAt.Get(); ok { + b.SetEggAt(v) + } + if v, ok := req.Luck.Get(); ok { + b.SetLuck(v) + } + if v, ok := req.LuckAt.Get(); ok { + b.SetLuckAt(v) + } + if v, ok := req.Like.Get(); ok { + b.SetLike(v) + } + if v, ok := req.LikeRank.Get(); ok { + b.SetLikeRank(v) + } + if v, ok := req.LikeAt.Get(); ok { + b.SetLikeAt(v) + } + if v, ok := req.Fav.Get(); ok { + b.SetFav(v) + } + if v, ok := req.Ten.Get(); ok { + b.SetTen(v) + } + if v, ok := req.TenSu.Get(); ok { + b.SetTenSu(v) + } + if v, ok := req.TenKai.Get(); ok { + b.SetTenKai(v) + } + if v, ok := req.Aiten.Get(); ok { + b.SetAiten(v) + } + if v, ok := req.TenCard.Get(); ok { + b.SetTenCard(v) + } + if v, ok := req.TenDelete.Get(); ok { + b.SetTenDelete(v) + } + if v, ok := req.TenPost.Get(); ok { + b.SetTenPost(v) + } + if v, ok := req.TenGet.Get(); ok { + b.SetTenGet(v) + } + if v, ok := req.TenAt.Get(); ok { + b.SetTenAt(v) + } + if v, ok := req.Next.Get(); ok { + b.SetNext(v) + } + if v, ok := req.Room.Get(); ok { + b.SetRoom(v) + } + if v, ok := req.Model.Get(); ok { + b.SetModel(v) + } + if v, ok := req.ModelAt.Get(); ok { + b.SetModelAt(v) + } + if v, ok := req.ModelAttack.Get(); ok { + b.SetModelAttack(v) + } + if v, ok := req.ModelLimit.Get(); ok { + b.SetModelLimit(v) + } + if v, ok := req.ModelSkill.Get(); ok { + b.SetModelSkill(v) + } + if v, ok := req.ModelMode.Get(); ok { + b.SetModelMode(v) + } + if v, ok := req.ModelCritical.Get(); ok { + b.SetModelCritical(v) + } + if v, ok := req.ModelCriticalD.Get(); ok { + b.SetModelCriticalD(v) + } + if v, ok := req.Game.Get(); ok { + b.SetGame(v) + } + if v, ok := req.GameTest.Get(); ok { + b.SetGameTest(v) + } + if v, ok := req.GameEnd.Get(); ok { + b.SetGameEnd(v) + } + if v, ok := req.GameAccount.Get(); ok { + b.SetGameAccount(v) + } + if v, ok := req.GameLv.Get(); ok { + b.SetGameLv(v) + } + if v, ok := req.Coin.Get(); ok { + b.SetCoin(v) + } + if v, ok := req.CoinOpen.Get(); ok { + b.SetCoinOpen(v) + } + if v, ok := req.CoinAt.Get(); ok { + b.SetCoinAt(v) + } + // Add all edges. + if req.Card != nil { + b.ClearCard().AddCardIDs(req.Card...) + } + if req.Ue != nil { + b.ClearUe().AddUeIDs(req.Ue...) + } + if req.Ma != nil { + b.ClearMa().AddMaIDs(req.Ma...) + } b.SetToken(v) } } @@ -1336,3 +1634,39 @@ func (h *OgentHandler) ListUserUe(ctx context.Context, params ListUserUeParams) r := NewUserUeLists(es) return (*ListUserUeOKApplicationJSON)(&r), nil } + +// ListUserMa handles GET /users/{id}/ma requests. +func (h *OgentHandler) ListUserMa(ctx context.Context, params ListUserMaParams) (ListUserMaRes, error) { + q := h.client.User.Query().Where(user.IDEQ(params.ID)).QueryMa() + page := 1 + if v, ok := params.Page.Get(); ok { + page = v + } + itemsPerPage := 30 + if v, ok := params.ItemsPerPage.Get(); ok { + itemsPerPage = v + } + q.Limit(itemsPerPage).Offset((page - 1) * itemsPerPage) + es, err := q.All(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + r := NewUserMaLists(es) + return (*ListUserMaOKApplicationJSON)(&r), nil +} diff --git a/ent/ogent/responses.go b/ent/ogent/responses.go index 417aaae..5069716 100644 --- a/ent/ogent/responses.go +++ b/ent/ogent/responses.go @@ -406,6 +406,237 @@ func (u *GroupUsersList) Elem() GroupUsersList { return *u } +func NewMaCreate(e *ent.Ma) *MaCreate { + if e == nil { + return nil + } + var ret MaCreate + ret.ID = e.ID + ret.Limit = NewOptBool(e.Limit) + ret.Count = NewOptInt(e.Count) + ret.Handle = NewOptString(e.Handle) + ret.Text = NewOptString(e.Text) + ret.Did = NewOptString(e.Did) + ret.Avatar = NewOptString(e.Avatar) + ret.Cid = NewOptString(e.Cid) + ret.URI = NewOptString(e.URI) + ret.Rkey = NewOptString(e.Rkey) + ret.BskyURL = NewOptString(e.BskyURL) + ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) + ret.CreatedAt = NewOptDateTime(e.CreatedAt) + return &ret +} + +func NewMaCreates(es []*ent.Ma) []MaCreate { + if len(es) == 0 { + return nil + } + r := make([]MaCreate, len(es)) + for i, e := range es { + r[i] = NewMaCreate(e).Elem() + } + return r +} + +func (m *MaCreate) Elem() MaCreate { + if m == nil { + return MaCreate{} + } + return *m +} + +func NewMaList(e *ent.Ma) *MaList { + if e == nil { + return nil + } + var ret MaList + ret.ID = e.ID + ret.Limit = NewOptBool(e.Limit) + ret.Count = NewOptInt(e.Count) + ret.Handle = NewOptString(e.Handle) + ret.Text = NewOptString(e.Text) + ret.Did = NewOptString(e.Did) + ret.Avatar = NewOptString(e.Avatar) + ret.Cid = NewOptString(e.Cid) + ret.URI = NewOptString(e.URI) + ret.Rkey = NewOptString(e.Rkey) + ret.BskyURL = NewOptString(e.BskyURL) + ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) + ret.CreatedAt = NewOptDateTime(e.CreatedAt) + return &ret +} + +func NewMaLists(es []*ent.Ma) []MaList { + if len(es) == 0 { + return nil + } + r := make([]MaList, len(es)) + for i, e := range es { + r[i] = NewMaList(e).Elem() + } + return r +} + +func (m *MaList) Elem() MaList { + if m == nil { + return MaList{} + } + return *m +} + +func NewMaRead(e *ent.Ma) *MaRead { + if e == nil { + return nil + } + var ret MaRead + ret.ID = e.ID + ret.Limit = NewOptBool(e.Limit) + ret.Count = NewOptInt(e.Count) + ret.Handle = NewOptString(e.Handle) + ret.Text = NewOptString(e.Text) + ret.Did = NewOptString(e.Did) + ret.Avatar = NewOptString(e.Avatar) + ret.Cid = NewOptString(e.Cid) + ret.URI = NewOptString(e.URI) + ret.Rkey = NewOptString(e.Rkey) + ret.BskyURL = NewOptString(e.BskyURL) + ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) + ret.CreatedAt = NewOptDateTime(e.CreatedAt) + return &ret +} + +func NewMaReads(es []*ent.Ma) []MaRead { + if len(es) == 0 { + return nil + } + r := make([]MaRead, len(es)) + for i, e := range es { + r[i] = NewMaRead(e).Elem() + } + return r +} + +func (m *MaRead) Elem() MaRead { + if m == nil { + return MaRead{} + } + return *m +} + +func NewMaUpdate(e *ent.Ma) *MaUpdate { + if e == nil { + return nil + } + var ret MaUpdate + ret.ID = e.ID + ret.Limit = NewOptBool(e.Limit) + ret.Count = NewOptInt(e.Count) + ret.Handle = NewOptString(e.Handle) + ret.Text = NewOptString(e.Text) + ret.Did = NewOptString(e.Did) + ret.Avatar = NewOptString(e.Avatar) + ret.Cid = NewOptString(e.Cid) + ret.URI = NewOptString(e.URI) + ret.Rkey = NewOptString(e.Rkey) + ret.BskyURL = NewOptString(e.BskyURL) + ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) + ret.CreatedAt = NewOptDateTime(e.CreatedAt) + return &ret +} + +func NewMaUpdates(es []*ent.Ma) []MaUpdate { + if len(es) == 0 { + return nil + } + r := make([]MaUpdate, len(es)) + for i, e := range es { + r[i] = NewMaUpdate(e).Elem() + } + return r +} + +func (m *MaUpdate) Elem() MaUpdate { + if m == nil { + return MaUpdate{} + } + return *m +} + +func NewMaOwnerRead(e *ent.User) *MaOwnerRead { + if e == nil { + return nil + } + var ret MaOwnerRead + ret.ID = e.ID + ret.Username = e.Username + ret.Did = NewOptString(e.Did) + ret.Member = NewOptBool(e.Member) + ret.Book = NewOptBool(e.Book) + ret.Manga = NewOptBool(e.Manga) + ret.Badge = NewOptBool(e.Badge) + ret.Bsky = NewOptBool(e.Bsky) + ret.Mastodon = NewOptBool(e.Mastodon) + ret.Delete = NewOptBool(e.Delete) + ret.Handle = NewOptBool(e.Handle) + ret.CreatedAt = NewOptDateTime(e.CreatedAt) + ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) + ret.RaidAt = NewOptDateTime(e.RaidAt) + ret.ServerAt = NewOptDateTime(e.ServerAt) + ret.EggAt = NewOptDateTime(e.EggAt) + ret.Luck = NewOptInt(e.Luck) + ret.LuckAt = NewOptDateTime(e.LuckAt) + ret.Like = NewOptInt(e.Like) + ret.LikeRank = NewOptInt(e.LikeRank) + ret.LikeAt = NewOptDateTime(e.LikeAt) + ret.Fav = NewOptInt(e.Fav) + ret.Ten = NewOptBool(e.Ten) + ret.TenSu = NewOptInt(e.TenSu) + ret.TenKai = NewOptInt(e.TenKai) + ret.Aiten = NewOptInt(e.Aiten) + ret.TenCard = NewOptString(e.TenCard) + ret.TenDelete = NewOptString(e.TenDelete) + ret.TenPost = NewOptString(e.TenPost) + ret.TenGet = NewOptString(e.TenGet) + ret.TenAt = NewOptDateTime(e.TenAt) + ret.Next = NewOptString(e.Next) + ret.Room = NewOptInt(e.Room) + ret.Model = NewOptBool(e.Model) + ret.ModelAt = NewOptDateTime(e.ModelAt) + ret.ModelAttack = NewOptInt(e.ModelAttack) + ret.ModelLimit = NewOptInt(e.ModelLimit) + ret.ModelSkill = NewOptInt(e.ModelSkill) + ret.ModelMode = NewOptInt(e.ModelMode) + ret.ModelCritical = NewOptInt(e.ModelCritical) + ret.ModelCriticalD = NewOptInt(e.ModelCriticalD) + ret.Game = NewOptBool(e.Game) + ret.GameTest = NewOptBool(e.GameTest) + ret.GameEnd = NewOptBool(e.GameEnd) + ret.GameAccount = NewOptBool(e.GameAccount) + ret.GameLv = NewOptInt(e.GameLv) + ret.Coin = NewOptInt(e.Coin) + ret.CoinOpen = NewOptBool(e.CoinOpen) + ret.CoinAt = NewOptDateTime(e.CoinAt) + return &ret +} + +func NewMaOwnerReads(es []*ent.User) []MaOwnerRead { + if len(es) == 0 { + return nil + } + r := make([]MaOwnerRead, len(es)) + for i, e := range es { + r[i] = NewMaOwnerRead(e).Elem() + } + return r +} + +func (u *MaOwnerRead) Elem() MaOwnerRead { + if u == nil { + return MaOwnerRead{} + } + return *u +} + func NewUeCreate(e *ent.Ue) *UeCreate { if e == nil { return nil @@ -992,6 +1223,45 @@ func (c *UserCardList) Elem() UserCardList { return *c } +func NewUserMaList(e *ent.Ma) *UserMaList { + if e == nil { + return nil + } + var ret UserMaList + ret.ID = e.ID + ret.Limit = NewOptBool(e.Limit) + ret.Count = NewOptInt(e.Count) + ret.Handle = NewOptString(e.Handle) + ret.Text = NewOptString(e.Text) + ret.Did = NewOptString(e.Did) + ret.Avatar = NewOptString(e.Avatar) + ret.Cid = NewOptString(e.Cid) + ret.URI = NewOptString(e.URI) + ret.Rkey = NewOptString(e.Rkey) + ret.BskyURL = NewOptString(e.BskyURL) + ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) + ret.CreatedAt = NewOptDateTime(e.CreatedAt) + return &ret +} + +func NewUserMaLists(es []*ent.Ma) []UserMaList { + if len(es) == 0 { + return nil + } + r := make([]UserMaList, len(es)) + for i, e := range es { + r[i] = NewUserMaList(e).Elem() + } + return r +} + +func (m *UserMaList) Elem() UserMaList { + if m == nil { + return UserMaList{} + } + return *m +} + func NewUserUeList(e *ent.Ue) *UserUeList { if e == nil { return nil diff --git a/ent/openapi.json b/ent/openapi.json index 5e384d6..d375483 100644 --- a/ent/openapi.json +++ b/ent/openapi.json @@ -704,6 +704,379 @@ } } }, + "/mas": { + "get": { + "tags": [ + "Ma" + ], + "summary": "List Mas", + "description": "List Mas.", + "operationId": "listMa", + "parameters": [ + { + "name": "page", + "in": "query", + "description": "what page to render", + "schema": { + "type": "integer", + "minimum": 1 + } + }, + { + "name": "itemsPerPage", + "in": "query", + "description": "item count to render per page", + "schema": { + "type": "integer", + "maximum": 5000, + "minimum": 1 + } + } + ], + "responses": { + "200": { + "description": "result Ma list", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MaList" + } + } + } + } + }, + "400": { + "$ref": "#/components/responses/400" + }, + "404": { + "$ref": "#/components/responses/404" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + }, + "post": { + "tags": [ + "Ma" + ], + "summary": "Create a new Ma", + "description": "Creates a new Ma and persists it to storage.", + "operationId": "createMa", + "requestBody": { + "description": "Ma to create", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "password": { + "type": "string" + }, + "token": { + "type": "string" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "owner": { + "type": "integer" + } + }, + "required": [ + "password", + "owner" + ] + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Ma created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MaCreate" + } + } + } + }, + "400": { + "$ref": "#/components/responses/400" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + } + }, + "/mas/{id}": { + "get": { + "tags": [ + "Ma" + ], + "summary": "Find a Ma by ID", + "description": "Finds the Ma with the requested ID and returns it.", + "operationId": "readMa", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of the Ma", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Ma with requested ID was found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MaRead" + } + } + } + }, + "400": { + "$ref": "#/components/responses/400" + }, + "404": { + "$ref": "#/components/responses/404" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + }, + "delete": { + "tags": [ + "Ma" + ], + "summary": "Deletes a Ma by ID", + "description": "Deletes the Ma with the requested ID.", + "operationId": "deleteMa", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of the Ma", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "204": { + "description": "Ma with requested ID was deleted" + }, + "400": { + "$ref": "#/components/responses/400" + }, + "404": { + "$ref": "#/components/responses/404" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + }, + "patch": { + "tags": [ + "Ma" + ], + "summary": "Updates a Ma", + "description": "Updates a Ma and persists changes to storage.", + "operationId": "updateMa", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of the Ma", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "requestBody": { + "description": "Ma properties to update", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "token": { + "type": "string" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "owner": { + "type": "integer" + } + } + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Ma updated", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MaUpdate" + } + } + } + }, + "400": { + "$ref": "#/components/responses/400" + }, + "404": { + "$ref": "#/components/responses/404" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + } + }, + "/mas/{id}/owner": { + "get": { + "tags": [ + "Ma" + ], + "summary": "Find the attached User", + "description": "Find the attached User of the Ma with the given ID", + "operationId": "readMaOwner", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of the Ma", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "User attached to Ma with requested ID was found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Ma_OwnerRead" + } + } + } + }, + "400": { + "$ref": "#/components/responses/400" + }, + "404": { + "$ref": "#/components/responses/404" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + } + }, "/ues": { "get": { "tags": [ @@ -1347,6 +1720,12 @@ "items": { "type": "integer" } + }, + "ma": { + "type": "array", + "items": { + "type": "integer" + } } }, "required": [ @@ -1647,6 +2026,12 @@ "items": { "type": "integer" } + }, + "ma": { + "type": "array", + "items": { + "type": "integer" + } } } } @@ -1769,6 +2154,70 @@ } ] }, + "/users/{id}/ma": { + "get": { + "tags": [ + "User" + ], + "summary": "List attached Mas", + "description": "List attached Mas.", + "operationId": "listUserMa", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of the User", + "required": true, + "schema": { + "type": "integer" + } + }, + { + "name": "page", + "in": "query", + "description": "what page to render", + "schema": { + "type": "integer" + } + }, + { + "name": "itemsPerPage", + "in": "query", + "description": "item count to render per page", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "result Users list", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/User_MaList" + } + } + } + } + }, + "400": { + "$ref": "#/components/responses/400" + }, + "404": { + "$ref": "#/components/responses/404" + }, + "409": { + "$ref": "#/components/responses/409" + }, + "500": { + "$ref": "#/components/responses/500" + } + } + } + }, "/users/{id}/ue": { "get": { "tags": [ @@ -2444,6 +2893,428 @@ "username" ] }, + "Ma": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "password": { + "type": "string" + }, + "token": { + "type": "string" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "owner": { + "$ref": "#/components/schemas/User" + } + }, + "required": [ + "id", + "password", + "owner" + ] + }, + "MaCreate": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + } + }, + "required": [ + "id" + ] + }, + "MaList": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + } + }, + "required": [ + "id" + ] + }, + "MaRead": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + } + }, + "required": [ + "id" + ] + }, + "MaUpdate": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + } + }, + "required": [ + "id" + ] + }, + "Ma_OwnerRead": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + }, + "did": { + "type": "string" + }, + "member": { + "type": "boolean" + }, + "book": { + "type": "boolean" + }, + "manga": { + "type": "boolean" + }, + "badge": { + "type": "boolean" + }, + "bsky": { + "type": "boolean" + }, + "mastodon": { + "type": "boolean" + }, + "delete": { + "type": "boolean" + }, + "handle": { + "type": "boolean" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "raid_at": { + "type": "string", + "format": "date-time" + }, + "server_at": { + "type": "string", + "format": "date-time" + }, + "egg_at": { + "type": "string", + "format": "date-time" + }, + "luck": { + "type": "integer" + }, + "luck_at": { + "type": "string", + "format": "date-time" + }, + "like": { + "type": "integer" + }, + "like_rank": { + "type": "integer" + }, + "like_at": { + "type": "string", + "format": "date-time" + }, + "fav": { + "type": "integer" + }, + "ten": { + "type": "boolean" + }, + "ten_su": { + "type": "integer" + }, + "ten_kai": { + "type": "integer" + }, + "aiten": { + "type": "integer" + }, + "ten_card": { + "type": "string" + }, + "ten_delete": { + "type": "string" + }, + "ten_post": { + "type": "string" + }, + "ten_get": { + "type": "string" + }, + "ten_at": { + "type": "string", + "format": "date-time" + }, + "next": { + "type": "string" + }, + "room": { + "type": "integer" + }, + "model": { + "type": "boolean" + }, + "model_at": { + "type": "string", + "format": "date-time" + }, + "model_attack": { + "type": "integer" + }, + "model_limit": { + "type": "integer" + }, + "model_skill": { + "type": "integer" + }, + "model_mode": { + "type": "integer" + }, + "model_critical": { + "type": "integer" + }, + "model_critical_d": { + "type": "integer" + }, + "game": { + "type": "boolean" + }, + "game_test": { + "type": "boolean" + }, + "game_end": { + "type": "boolean" + }, + "game_account": { + "type": "boolean" + }, + "game_lv": { + "type": "integer" + }, + "coin": { + "type": "integer" + }, + "coin_open": { + "type": "boolean" + }, + "coin_at": { + "type": "string", + "format": "date-time" + } + }, + "required": [ + "id", + "username" + ] + }, "Ue": { "type": "object", "properties": { @@ -3113,6 +3984,12 @@ "items": { "$ref": "#/components/schemas/Ue" } + }, + "ma": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Ma" + } } }, "required": [ @@ -3821,6 +4698,55 @@ "id" ] }, + "User_MaList": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "limit": { + "type": "boolean" + }, + "count": { + "type": "integer" + }, + "handle": { + "type": "string" + }, + "text": { + "type": "string" + }, + "did": { + "type": "string" + }, + "avatar": { + "type": "string" + }, + "cid": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "rkey": { + "type": "string" + }, + "bsky_url": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "created_at": { + "type": "string", + "format": "date-time" + } + }, + "required": [ + "id" + ] + }, "User_UeList": { "type": "object", "properties": { diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index 221303d..432eb21 100644 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -12,6 +12,9 @@ type Card func(*sql.Selector) // Group is the predicate function for group builders. type Group func(*sql.Selector) +// Ma is the predicate function for ma builders. +type Ma func(*sql.Selector) + // Ue is the predicate function for ue builders. type Ue func(*sql.Selector) diff --git a/ent/runtime.go b/ent/runtime.go index 5744b3a..f8cdd75 100644 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -5,6 +5,7 @@ package ent import ( "api/ent/card" "api/ent/group" + "api/ent/ma" "api/ent/schema" "api/ent/ue" "api/ent/user" @@ -51,6 +52,20 @@ func init() { groupDescPassword := groupFields[1].Descriptor() // group.PasswordValidator is a validator for the "password" field. It is called by the builders before save. group.PasswordValidator = groupDescPassword.Validators[0].(func(string) error) + maFields := schema.Ma{}.Fields() + _ = maFields + // maDescPassword is the schema descriptor for password field. + maDescPassword := maFields[0].Descriptor() + // ma.PasswordValidator is a validator for the "password" field. It is called by the builders before save. + ma.PasswordValidator = maDescPassword.Validators[0].(func(string) error) + // maDescLimit is the schema descriptor for limit field. + maDescLimit := maFields[2].Descriptor() + // ma.DefaultLimit holds the default value on creation for the limit field. + ma.DefaultLimit = maDescLimit.Default.(bool) + // maDescCreatedAt is the schema descriptor for created_at field. + maDescCreatedAt := maFields[13].Descriptor() + // ma.DefaultCreatedAt holds the default value on creation for the created_at field. + ma.DefaultCreatedAt = maDescCreatedAt.Default.(func() time.Time) ueFields := schema.Ue{}.Fields() _ = ueFields // ueDescLimit is the schema descriptor for limit field. diff --git a/ent/schema/manga.go b/ent/schema/manga.go new file mode 100644 index 0000000..b8e2bd1 --- /dev/null +++ b/ent/schema/manga.go @@ -0,0 +1,77 @@ +package schema + +import ( + "time" + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" +) + +// Game holds the schema definition for the Game entity. +type Ma struct { + ent.Schema +} + +func (Ma) Fields() []ent.Field { + return []ent.Field{ + + field.String("password"). + NotEmpty(). + Immutable(). + Sensitive(), + + field.String("token"). + Optional(). + Sensitive(), + + field.Bool("limit"). + Default(false). + Optional(), + + field.Int("count"). + Optional(), + + field.String("handle"). + Optional(), + + field.String("text"). + Optional(), + + field.String("did"). + Optional(), + + field.String("avatar"). + Optional(), + + field.String("cid"). + Optional(), + + field.String("uri"). + Optional(), + + field.String("rkey"). + Optional(), + + field.String("bsky_url"). + Optional(), + + field.Time("updated_at"). + Optional(), + + field.Time("created_at"). + Immutable(). + Optional(). + Default(func() time.Time { + return time.Now().In(jst) + }), + } +} + +func (Ma) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("owner", User.Type). + Ref("ma"). + Unique(). + Required(), + } +} diff --git a/ent/schema/user.go b/ent/schema/user.go index b9de7ad..bc6da1d 100644 --- a/ent/schema/user.go +++ b/ent/schema/user.go @@ -245,6 +245,7 @@ func (User) Edges() []ent.Edge { return []ent.Edge{ edge.To("card", Card.Type), edge.To("ue", Ue.Type), + edge.To("ma", Ma.Type), //Unique(), } } diff --git a/ent/tx.go b/ent/tx.go index 26bdf04..9c7f793 100644 --- a/ent/tx.go +++ b/ent/tx.go @@ -16,6 +16,8 @@ type Tx struct { Card *CardClient // Group is the client for interacting with the Group builders. Group *GroupClient + // Ma is the client for interacting with the Ma builders. + Ma *MaClient // Ue is the client for interacting with the Ue builders. Ue *UeClient // User is the client for interacting with the User builders. @@ -153,6 +155,7 @@ func (tx *Tx) Client() *Client { func (tx *Tx) init() { tx.Card = NewCardClient(tx.config) tx.Group = NewGroupClient(tx.config) + tx.Ma = NewMaClient(tx.config) tx.Ue = NewUeClient(tx.config) tx.User = NewUserClient(tx.config) } diff --git a/ent/user.go b/ent/user.go index d070c73..e0aeab5 100644 --- a/ent/user.go +++ b/ent/user.go @@ -130,9 +130,11 @@ type UserEdges struct { Card []*Card `json:"card,omitempty"` // Ue holds the value of the ue edge. Ue []*Ue `json:"ue,omitempty"` + // Ma holds the value of the ma edge. + Ma []*Ma `json:"ma,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [2]bool + loadedTypes [3]bool } // CardOrErr returns the Card value or an error if the edge @@ -153,6 +155,15 @@ func (e UserEdges) UeOrErr() ([]*Ue, error) { return nil, &NotLoadedError{edge: "ue"} } +// MaOrErr returns the Ma value or an error if the edge +// was not loaded in eager-loading. +func (e UserEdges) MaOrErr() ([]*Ma, error) { + if e.loadedTypes[2] { + return e.Ma, nil + } + return nil, &NotLoadedError{edge: "ma"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -519,6 +530,11 @@ func (u *User) QueryUe() *UeQuery { return NewUserClient(u.config).QueryUe(u) } +// QueryMa queries the "ma" edge of the User entity. +func (u *User) QueryMa() *MaQuery { + return NewUserClient(u.config).QueryMa(u) +} + // Update returns a builder for updating this User. // Note that you need to call User.Unwrap() before calling this method if this User // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/user/user.go b/ent/user/user.go index 31a9add..dbf0881 100644 --- a/ent/user/user.go +++ b/ent/user/user.go @@ -118,6 +118,8 @@ const ( EdgeCard = "card" // EdgeUe holds the string denoting the ue edge name in mutations. EdgeUe = "ue" + // EdgeMa holds the string denoting the ma edge name in mutations. + EdgeMa = "ma" // Table holds the table name of the user in the database. Table = "users" // CardTable is the table that holds the card relation/edge. @@ -134,6 +136,13 @@ const ( UeInverseTable = "ues" // UeColumn is the table column denoting the ue relation/edge. UeColumn = "user_ue" + // MaTable is the table that holds the ma relation/edge. + MaTable = "mas" + // MaInverseTable is the table name for the Ma entity. + // It exists in this package in order to avoid circular dependency with the "ma" package. + MaInverseTable = "mas" + // MaColumn is the table column denoting the ma relation/edge. + MaColumn = "user_ma" ) // Columns holds all SQL columns for user fields. @@ -552,6 +561,20 @@ func ByUe(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newUeStep(), append([]sql.OrderTerm{term}, terms...)...) } } + +// ByMaCount orders the results by ma count. +func ByMaCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newMaStep(), opts...) + } +} + +// ByMa orders the results by ma terms. +func ByMa(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newMaStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} func newCardStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -566,3 +589,10 @@ func newUeStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, UeTable, UeColumn), ) } +func newMaStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MaInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MaTable, MaColumn), + ) +} diff --git a/ent/user/where.go b/ent/user/where.go index d29af29..3e3b9d8 100644 --- a/ent/user/where.go +++ b/ent/user/where.go @@ -2606,6 +2606,29 @@ func HasUeWith(preds ...predicate.Ue) predicate.User { }) } +// HasMa applies the HasEdge predicate on the "ma" edge. +func HasMa() predicate.User { + return predicate.User(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MaTable, MaColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasMaWith applies the HasEdge predicate on the "ma" edge with a given conditions (other predicates). +func HasMaWith(preds ...predicate.Ma) predicate.User { + return predicate.User(func(s *sql.Selector) { + step := newMaStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/ent/user_create.go b/ent/user_create.go index f23cc36..d8039d7 100644 --- a/ent/user_create.go +++ b/ent/user_create.go @@ -4,6 +4,7 @@ package ent import ( "api/ent/card" + "api/ent/ma" "api/ent/ue" "api/ent/user" "context" @@ -736,6 +737,21 @@ func (uc *UserCreate) AddUe(u ...*Ue) *UserCreate { return uc.AddUeIDs(ids...) } +// AddMaIDs adds the "ma" edge to the Ma entity by IDs. +func (uc *UserCreate) AddMaIDs(ids ...int) *UserCreate { + uc.mutation.AddMaIDs(ids...) + return uc +} + +// AddMa adds the "ma" edges to the Ma entity. +func (uc *UserCreate) AddMa(m ...*Ma) *UserCreate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return uc.AddMaIDs(ids...) +} + // Mutation returns the UserMutation object of the builder. func (uc *UserCreate) Mutation() *UserMutation { return uc.mutation @@ -1145,6 +1161,22 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := uc.mutation.MaIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/ent/user_query.go b/ent/user_query.go index c1739bd..77b01de 100644 --- a/ent/user_query.go +++ b/ent/user_query.go @@ -4,6 +4,7 @@ package ent import ( "api/ent/card" + "api/ent/ma" "api/ent/predicate" "api/ent/ue" "api/ent/user" @@ -26,6 +27,7 @@ type UserQuery struct { predicates []predicate.User withCard *CardQuery withUe *UeQuery + withMa *MaQuery withFKs bool // intermediate query (i.e. traversal path). sql *sql.Selector @@ -107,6 +109,28 @@ func (uq *UserQuery) QueryUe() *UeQuery { return query } +// QueryMa chains the current query on the "ma" edge. +func (uq *UserQuery) QueryMa() *MaQuery { + query := (&MaClient{config: uq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := uq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := uq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(user.Table, user.FieldID, selector), + sqlgraph.To(ma.Table, ma.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.MaTable, user.MaColumn), + ) + fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first User entity from the query. // Returns a *NotFoundError when no User was found. func (uq *UserQuery) First(ctx context.Context) (*User, error) { @@ -301,6 +325,7 @@ func (uq *UserQuery) Clone() *UserQuery { predicates: append([]predicate.User{}, uq.predicates...), withCard: uq.withCard.Clone(), withUe: uq.withUe.Clone(), + withMa: uq.withMa.Clone(), // clone intermediate query. sql: uq.sql.Clone(), path: uq.path, @@ -329,6 +354,17 @@ func (uq *UserQuery) WithUe(opts ...func(*UeQuery)) *UserQuery { return uq } +// WithMa tells the query-builder to eager-load the nodes that are connected to +// the "ma" edge. The optional arguments are used to configure the query builder of the edge. +func (uq *UserQuery) WithMa(opts ...func(*MaQuery)) *UserQuery { + query := (&MaClient{config: uq.config}).Query() + for _, opt := range opts { + opt(query) + } + uq.withMa = query + return uq +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -408,9 +444,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e nodes = []*User{} withFKs = uq.withFKs _spec = uq.querySpec() - loadedTypes = [2]bool{ + loadedTypes = [3]bool{ uq.withCard != nil, uq.withUe != nil, + uq.withMa != nil, } ) if withFKs { @@ -448,6 +485,13 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e return nil, err } } + if query := uq.withMa; query != nil { + if err := uq.loadMa(ctx, query, nodes, + func(n *User) { n.Edges.Ma = []*Ma{} }, + func(n *User, e *Ma) { n.Edges.Ma = append(n.Edges.Ma, e) }); err != nil { + return nil, err + } + } return nodes, nil } @@ -513,6 +557,37 @@ func (uq *UserQuery) loadUe(ctx context.Context, query *UeQuery, nodes []*User, } return nil } +func (uq *UserQuery) loadMa(ctx context.Context, query *MaQuery, nodes []*User, init func(*User), assign func(*User, *Ma)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*User) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.Ma(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(user.MaColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.user_ma + if fk == nil { + return fmt.Errorf(`foreign-key "user_ma" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "user_ma" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { _spec := uq.querySpec() diff --git a/ent/user_update.go b/ent/user_update.go index 25bf427..ed074ba 100644 --- a/ent/user_update.go +++ b/ent/user_update.go @@ -4,6 +4,7 @@ package ent import ( "api/ent/card" + "api/ent/ma" "api/ent/predicate" "api/ent/ue" "api/ent/user" @@ -1112,6 +1113,21 @@ func (uu *UserUpdate) AddUe(u ...*Ue) *UserUpdate { return uu.AddUeIDs(ids...) } +// AddMaIDs adds the "ma" edge to the Ma entity by IDs. +func (uu *UserUpdate) AddMaIDs(ids ...int) *UserUpdate { + uu.mutation.AddMaIDs(ids...) + return uu +} + +// AddMa adds the "ma" edges to the Ma entity. +func (uu *UserUpdate) AddMa(m ...*Ma) *UserUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return uu.AddMaIDs(ids...) +} + // Mutation returns the UserMutation object of the builder. func (uu *UserUpdate) Mutation() *UserMutation { return uu.mutation @@ -1159,6 +1175,27 @@ func (uu *UserUpdate) RemoveUe(u ...*Ue) *UserUpdate { return uu.RemoveUeIDs(ids...) } +// ClearMa clears all "ma" edges to the Ma entity. +func (uu *UserUpdate) ClearMa() *UserUpdate { + uu.mutation.ClearMa() + return uu +} + +// RemoveMaIDs removes the "ma" edge to Ma entities by IDs. +func (uu *UserUpdate) RemoveMaIDs(ids ...int) *UserUpdate { + uu.mutation.RemoveMaIDs(ids...) + return uu +} + +// RemoveMa removes "ma" edges to Ma entities. +func (uu *UserUpdate) RemoveMa(m ...*Ma) *UserUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return uu.RemoveMaIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) @@ -1618,6 +1655,51 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if uu.mutation.MaCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uu.mutation.RemovedMaIDs(); len(nodes) > 0 && !uu.mutation.MaCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uu.mutation.MaIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{user.Label} @@ -2720,6 +2802,21 @@ func (uuo *UserUpdateOne) AddUe(u ...*Ue) *UserUpdateOne { return uuo.AddUeIDs(ids...) } +// AddMaIDs adds the "ma" edge to the Ma entity by IDs. +func (uuo *UserUpdateOne) AddMaIDs(ids ...int) *UserUpdateOne { + uuo.mutation.AddMaIDs(ids...) + return uuo +} + +// AddMa adds the "ma" edges to the Ma entity. +func (uuo *UserUpdateOne) AddMa(m ...*Ma) *UserUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return uuo.AddMaIDs(ids...) +} + // Mutation returns the UserMutation object of the builder. func (uuo *UserUpdateOne) Mutation() *UserMutation { return uuo.mutation @@ -2767,6 +2864,27 @@ func (uuo *UserUpdateOne) RemoveUe(u ...*Ue) *UserUpdateOne { return uuo.RemoveUeIDs(ids...) } +// ClearMa clears all "ma" edges to the Ma entity. +func (uuo *UserUpdateOne) ClearMa() *UserUpdateOne { + uuo.mutation.ClearMa() + return uuo +} + +// RemoveMaIDs removes the "ma" edge to Ma entities by IDs. +func (uuo *UserUpdateOne) RemoveMaIDs(ids ...int) *UserUpdateOne { + uuo.mutation.RemoveMaIDs(ids...) + return uuo +} + +// RemoveMa removes "ma" edges to Ma entities. +func (uuo *UserUpdateOne) RemoveMa(m ...*Ma) *UserUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return uuo.RemoveMaIDs(ids...) +} + // Where appends a list predicates to the UserUpdate builder. func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne { uuo.mutation.Where(ps...) @@ -3256,6 +3374,51 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if uuo.mutation.MaCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uuo.mutation.RemovedMaIDs(); len(nodes) > 0 && !uuo.mutation.MaCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uuo.mutation.MaIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.MaTable, + Columns: []string{user.MaColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &User{config: uuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/tmp/ogent/ogent.go b/tmp/ogent/ogent.go index f6478ef..5a0fa89 100644 --- a/tmp/ogent/ogent.go +++ b/tmp/ogent/ogent.go @@ -9,9 +9,10 @@ import ( "api/ent" "api/ent/card" "api/ent/group" + "api/ent/ma" "api/ent/ue" "api/ent/user" - "os" + "github.com/go-faster/jx" ) @@ -66,12 +67,12 @@ func (h *OgentHandler) CreateCard(ctx context.Context, req *CreateCardReq) (Crea if v, ok := req.CreatedAt.Get(); ok { b.SetCreatedAt(v) } - // Add all edges. if req.Password == password { b.SetOwnerID(req.Owner) } else { b.SetOwnerID(0) } + // Add all edges. //b.SetOwnerID(req.Owner) // Persist to storage. e, err := b.Save(ctx) @@ -143,6 +144,9 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param if v, ok := req.Status.Get(); ok { b.SetStatus(v) } + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } if v, ok := req.Cp.Get(); ok { b.SetCp(v) } @@ -156,6 +160,9 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param b.SetAuthor(v) } // Add all edges. + //if v, ok := req.Owner.Get(); ok { + // b.SetOwnerID(v) + //} if v, ok := req.Token.Get(); ok { if v == token { b.SetToken(v) @@ -164,7 +171,6 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param } } } - // Persist to storage. e, err := b.Save(ctx) if err != nil { @@ -198,8 +204,8 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param // DeleteCard handles DELETE /cards/{id} requests. func (h *OgentHandler) DeleteCard(ctx context.Context, params DeleteCardParams) (DeleteCardRes, error) { - err := h.client.Card.DeleteOneID(params.ID).Exec(ctx) - //err := h.client.Card.DeleteOneID(0).Exec(ctx) + //err := h.client.Card.DeleteOneID(params.ID).Exec(ctx) + err := h.client.Card.DeleteOneID(0).Exec(ctx) if err != nil { switch { case ent.IsNotFound(err): @@ -353,8 +359,7 @@ func (h *OgentHandler) ReadGroup(ctx context.Context, params ReadGroupParams) (R // UpdateGroup handles PATCH /groups/{id} requests. func (h *OgentHandler) UpdateGroup(ctx context.Context, req *UpdateGroupReq, params UpdateGroupParams) (UpdateGroupRes, error) { - b := h.client.Group.UpdateOneID(0) - //b := h.client.Group.UpdateOneID(params.ID) + b := h.client.Group.UpdateOneID(params.ID) // Add all fields. if v, ok := req.Name.Get(); ok { b.SetName(v) @@ -494,6 +499,287 @@ func (h *OgentHandler) ListGroupUsers(ctx context.Context, params ListGroupUsers return (*ListGroupUsersOKApplicationJSON)(&r), nil } +// CreateMa handles POST /mas requests. +func (h *OgentHandler) CreateMa(ctx context.Context, req *CreateMaReq) (CreateMaRes, error) { + b := h.client.Ma.Create() + // Add all fields. + b.SetPassword(req.Password) + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } + if v, ok := req.Limit.Get(); ok { + b.SetLimit(v) + } + if v, ok := req.Count.Get(); ok { + b.SetCount(v) + } + if v, ok := req.Handle.Get(); ok { + b.SetHandle(v) + } + if v, ok := req.Text.Get(); ok { + b.SetText(v) + } + if v, ok := req.Did.Get(); ok { + b.SetDid(v) + } + if v, ok := req.Avatar.Get(); ok { + b.SetAvatar(v) + } + if v, ok := req.Cid.Get(); ok { + b.SetCid(v) + } + if v, ok := req.URI.Get(); ok { + b.SetURI(v) + } + if v, ok := req.Rkey.Get(); ok { + b.SetRkey(v) + } + if v, ok := req.BskyURL.Get(); ok { + b.SetBskyURL(v) + } + if v, ok := req.UpdatedAt.Get(); ok { + b.SetUpdatedAt(v) + } + if v, ok := req.CreatedAt.Get(); ok { + b.SetCreatedAt(v) + } + // Add all edges. + //b.SetOwnerID(req.Owner) + if req.Password == password { + b.SetOwnerID(req.Owner) + } else { + b.SetOwnerID(0) + } + // Persist to storage. + e, err := b.Save(ctx) + if err != nil { + switch { + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + case ent.IsConstraintError(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + // Reload the entity to attach all eager-loaded edges. + q := h.client.Ma.Query().Where(ma.ID(e.ID)) + e, err = q.Only(ctx) + if err != nil { + // This should never happen. + return nil, err + } + return NewMaCreate(e), nil +} + +// ReadMa handles GET /mas/{id} requests. +func (h *OgentHandler) ReadMa(ctx context.Context, params ReadMaParams) (ReadMaRes, error) { + q := h.client.Ma.Query().Where(ma.IDEQ(params.ID)) + e, err := q.Only(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + return NewMaRead(e), nil +} + +// UpdateMa handles PATCH /mas/{id} requests. +func (h *OgentHandler) UpdateMa(ctx context.Context, req *UpdateMaReq, params UpdateMaParams) (UpdateMaRes, error) { + b := h.client.Ma.UpdateOneID(params.ID) + // Add all fields. + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } + if v, ok := req.Limit.Get(); ok { + b.SetLimit(v) + } + if v, ok := req.Count.Get(); ok { + b.SetCount(v) + } + if v, ok := req.Handle.Get(); ok { + b.SetHandle(v) + } + if v, ok := req.Text.Get(); ok { + b.SetText(v) + } + if v, ok := req.Did.Get(); ok { + b.SetDid(v) + } + if v, ok := req.Avatar.Get(); ok { + b.SetAvatar(v) + } + if v, ok := req.Cid.Get(); ok { + b.SetCid(v) + } + if v, ok := req.URI.Get(); ok { + b.SetURI(v) + } + if v, ok := req.Rkey.Get(); ok { + b.SetRkey(v) + } + if v, ok := req.BskyURL.Get(); ok { + b.SetBskyURL(v) + } + if v, ok := req.UpdatedAt.Get(); ok { + b.SetUpdatedAt(v) + } + // Add all edges. + //if v, ok := req.Owner.Get(); ok { + // b.SetOwnerID(v) + //} + if v, ok := req.Token.Get(); ok { + if v == token { + b.SetToken(v) + if v, ok := req.Owner.Get(); ok { + b.SetOwnerID(v) + } + } + } + // Persist to storage. + e, err := b.Save(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsConstraintError(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + // Reload the entity to attach all eager-loaded edges. + q := h.client.Ma.Query().Where(ma.ID(e.ID)) + e, err = q.Only(ctx) + if err != nil { + // This should never happen. + return nil, err + } + return NewMaUpdate(e), nil +} + +// DeleteMa handles DELETE /mas/{id} requests. +func (h *OgentHandler) DeleteMa(ctx context.Context, params DeleteMaParams) (DeleteMaRes, error) { + err := h.client.Ma.DeleteOneID(0).Exec(ctx) + //err := h.client.Ma.DeleteOneID(params.ID).Exec(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsConstraintError(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + return new(DeleteMaNoContent), nil + +} + +// ListMa handles GET /mas requests. +func (h *OgentHandler) ListMa(ctx context.Context, params ListMaParams) (ListMaRes, error) { + q := h.client.Ma.Query() + page := 1 + if v, ok := params.Page.Get(); ok { + page = v + } + itemsPerPage := 30 + if v, ok := params.ItemsPerPage.Get(); ok { + itemsPerPage = v + } + q.Limit(itemsPerPage).Offset((page - 1) * itemsPerPage) + + es, err := q.All(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + r := NewMaLists(es) + return (*ListMaOKApplicationJSON)(&r), nil +} + +// ReadMaOwner handles GET /mas/{id}/owner requests. +func (h *OgentHandler) ReadMaOwner(ctx context.Context, params ReadMaOwnerParams) (ReadMaOwnerRes, error) { + q := h.client.Ma.Query().Where(ma.IDEQ(params.ID)).QueryOwner() + e, err := q.Only(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + return NewMaOwnerRead(e), nil +} + // CreateUe handles POST /ues requests. func (h *OgentHandler) CreateUe(ctx context.Context, req *CreateUeReq) (CreateUeRes, error) { b := h.client.Ue.Create() @@ -648,6 +934,9 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up if v, ok := req.Mode.Get(); ok { b.SetMode(v) } + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } if v, ok := req.Cp.Get(); ok { b.SetCp(v) } @@ -670,6 +959,9 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up b.SetAuthor(v) } // Add all edges. + //if v, ok := req.Owner.Get(); ok { + // b.SetOwnerID(v) + //} if v, ok := req.Token.Get(); ok { if v == token { b.SetToken(v) @@ -678,7 +970,6 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up } } } - // Persist to storage. e, err := b.Save(ctx) if err != nil { @@ -712,8 +1003,8 @@ func (h *OgentHandler) UpdateUe(ctx context.Context, req *UpdateUeReq, params Up // DeleteUe handles DELETE /ues/{id} requests. func (h *OgentHandler) DeleteUe(ctx context.Context, params DeleteUeParams) (DeleteUeRes, error) { - err := h.client.Ue.DeleteOneID(0).Exec(ctx) //err := h.client.Ue.DeleteOneID(params.ID).Exec(ctx) + err := h.client.Ue.DeleteOneID(0).Exec(ctx) if err != nil { switch { case ent.IsNotFound(err): @@ -803,7 +1094,14 @@ func (h *OgentHandler) ReadUeOwner(ctx context.Context, params ReadUeOwnerParams // CreateUser handles POST /users requests. func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (CreateUserRes, error) { b := h.client.User.Create() - if v, ok := req.Did.Get(); ok { + // Add all fields. + //b.SetUsername(req.Username) + if req.Password == password { + b.SetUsername(req.Username) + } else { + b.SetUsername("") + } + if v, ok := req.Did.Get(); ok { b.SetDid(v) } if v, ok := req.Member.Get(); ok { @@ -948,17 +1246,10 @@ func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (Crea if v, ok := req.CoinAt.Get(); ok { b.SetCoinAt(v) } - - // Add all fields. - //b.SetUsername(req.Username) - if req.Password == password { - b.SetUsername(req.Username) - } else { - b.SetUsername("") - } // Add all edges. b.AddCardIDs(req.Card...) b.AddUeIDs(req.Ue...) + b.AddMaIDs(req.Ma...) // Persist to storage. e, err := b.Save(ctx) if err != nil { @@ -1021,152 +1312,159 @@ func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, param b := h.client.User.UpdateOneID(params.ID) if v, ok := req.Token.Get(); ok { if v == token { - // Add all fields. - if v, ok := req.Did.Get(); ok { - b.SetDid(v) - } - if v, ok := req.Member.Get(); ok { - b.SetMember(v) - } - if v, ok := req.Book.Get(); ok { - b.SetBook(v) - } - if v, ok := req.Manga.Get(); ok { - b.SetManga(v) - } - if v, ok := req.Badge.Get(); ok { - b.SetBadge(v) - } - if v, ok := req.Bsky.Get(); ok { - b.SetBsky(v) - } - if v, ok := req.Mastodon.Get(); ok { - b.SetMastodon(v) - } - if v, ok := req.Delete.Get(); ok { - b.SetDelete(v) - } - if v, ok := req.Handle.Get(); ok { - b.SetHandle(v) - } - if v, ok := req.UpdatedAt.Get(); ok { - b.SetUpdatedAt(v) - } - if v, ok := req.RaidAt.Get(); ok { - b.SetRaidAt(v) - } - if v, ok := req.ServerAt.Get(); ok { - b.SetServerAt(v) - } - if v, ok := req.EggAt.Get(); ok { - b.SetEggAt(v) - } - if v, ok := req.Luck.Get(); ok { - b.SetLuck(v) - } - if v, ok := req.LuckAt.Get(); ok { - b.SetLuckAt(v) - } - if v, ok := req.Like.Get(); ok { - b.SetLike(v) - } - if v, ok := req.LikeRank.Get(); ok { - b.SetLikeRank(v) - } - if v, ok := req.LikeAt.Get(); ok { - b.SetLikeAt(v) - } - if v, ok := req.Fav.Get(); ok { - b.SetFav(v) - } - if v, ok := req.Ten.Get(); ok { - b.SetTen(v) - } - if v, ok := req.TenSu.Get(); ok { - b.SetTenSu(v) - } - if v, ok := req.TenKai.Get(); ok { - b.SetTenKai(v) - } - if v, ok := req.Aiten.Get(); ok { - b.SetAiten(v) - } - if v, ok := req.TenCard.Get(); ok { - b.SetTenCard(v) - } - if v, ok := req.TenDelete.Get(); ok { - b.SetTenDelete(v) - } - if v, ok := req.TenPost.Get(); ok { - b.SetTenPost(v) - } - if v, ok := req.TenGet.Get(); ok { - b.SetTenGet(v) - } - if v, ok := req.TenAt.Get(); ok { - b.SetTenAt(v) - } - if v, ok := req.Next.Get(); ok { - b.SetNext(v) - } - if v, ok := req.Room.Get(); ok { - b.SetRoom(v) - } - if v, ok := req.Model.Get(); ok { - b.SetModel(v) - } - if v, ok := req.ModelAt.Get(); ok { - b.SetModelAt(v) - } - if v, ok := req.ModelAttack.Get(); ok { - b.SetModelAttack(v) - } - if v, ok := req.ModelLimit.Get(); ok { - b.SetModelLimit(v) - } - if v, ok := req.ModelSkill.Get(); ok { - b.SetModelSkill(v) - } - if v, ok := req.ModelMode.Get(); ok { - b.SetModelMode(v) - } - if v, ok := req.ModelCritical.Get(); ok { - b.SetModelCritical(v) - } - if v, ok := req.ModelCriticalD.Get(); ok { - b.SetModelCriticalD(v) - } - if v, ok := req.Game.Get(); ok { - b.SetGame(v) - } - if v, ok := req.GameTest.Get(); ok { - b.SetGameTest(v) - } - if v, ok := req.GameEnd.Get(); ok { - b.SetGameEnd(v) - } - if v, ok := req.GameAccount.Get(); ok { - b.SetGameAccount(v) - } - if v, ok := req.GameLv.Get(); ok { - b.SetGameLv(v) - } - if v, ok := req.Coin.Get(); ok { - b.SetCoin(v) - } - if v, ok := req.CoinOpen.Get(); ok { - b.SetCoinOpen(v) - } - if v, ok := req.CoinAt.Get(); ok { - b.SetCoinAt(v) - } - // Add all edges. - if req.Card != nil { - b.ClearCard().AddCardIDs(req.Card...) - } - if req.Ue != nil { - b.ClearUe().AddUeIDs(req.Ue...) - } + + // Add all fields. + if v, ok := req.Did.Get(); ok { + b.SetDid(v) + } + if v, ok := req.Member.Get(); ok { + b.SetMember(v) + } + if v, ok := req.Book.Get(); ok { + b.SetBook(v) + } + if v, ok := req.Manga.Get(); ok { + b.SetManga(v) + } + if v, ok := req.Badge.Get(); ok { + b.SetBadge(v) + } + if v, ok := req.Bsky.Get(); ok { + b.SetBsky(v) + } + if v, ok := req.Mastodon.Get(); ok { + b.SetMastodon(v) + } + if v, ok := req.Delete.Get(); ok { + b.SetDelete(v) + } + if v, ok := req.Handle.Get(); ok { + b.SetHandle(v) + } + if v, ok := req.Token.Get(); ok { + b.SetToken(v) + } + if v, ok := req.UpdatedAt.Get(); ok { + b.SetUpdatedAt(v) + } + if v, ok := req.RaidAt.Get(); ok { + b.SetRaidAt(v) + } + if v, ok := req.ServerAt.Get(); ok { + b.SetServerAt(v) + } + if v, ok := req.EggAt.Get(); ok { + b.SetEggAt(v) + } + if v, ok := req.Luck.Get(); ok { + b.SetLuck(v) + } + if v, ok := req.LuckAt.Get(); ok { + b.SetLuckAt(v) + } + if v, ok := req.Like.Get(); ok { + b.SetLike(v) + } + if v, ok := req.LikeRank.Get(); ok { + b.SetLikeRank(v) + } + if v, ok := req.LikeAt.Get(); ok { + b.SetLikeAt(v) + } + if v, ok := req.Fav.Get(); ok { + b.SetFav(v) + } + if v, ok := req.Ten.Get(); ok { + b.SetTen(v) + } + if v, ok := req.TenSu.Get(); ok { + b.SetTenSu(v) + } + if v, ok := req.TenKai.Get(); ok { + b.SetTenKai(v) + } + if v, ok := req.Aiten.Get(); ok { + b.SetAiten(v) + } + if v, ok := req.TenCard.Get(); ok { + b.SetTenCard(v) + } + if v, ok := req.TenDelete.Get(); ok { + b.SetTenDelete(v) + } + if v, ok := req.TenPost.Get(); ok { + b.SetTenPost(v) + } + if v, ok := req.TenGet.Get(); ok { + b.SetTenGet(v) + } + if v, ok := req.TenAt.Get(); ok { + b.SetTenAt(v) + } + if v, ok := req.Next.Get(); ok { + b.SetNext(v) + } + if v, ok := req.Room.Get(); ok { + b.SetRoom(v) + } + if v, ok := req.Model.Get(); ok { + b.SetModel(v) + } + if v, ok := req.ModelAt.Get(); ok { + b.SetModelAt(v) + } + if v, ok := req.ModelAttack.Get(); ok { + b.SetModelAttack(v) + } + if v, ok := req.ModelLimit.Get(); ok { + b.SetModelLimit(v) + } + if v, ok := req.ModelSkill.Get(); ok { + b.SetModelSkill(v) + } + if v, ok := req.ModelMode.Get(); ok { + b.SetModelMode(v) + } + if v, ok := req.ModelCritical.Get(); ok { + b.SetModelCritical(v) + } + if v, ok := req.ModelCriticalD.Get(); ok { + b.SetModelCriticalD(v) + } + if v, ok := req.Game.Get(); ok { + b.SetGame(v) + } + if v, ok := req.GameTest.Get(); ok { + b.SetGameTest(v) + } + if v, ok := req.GameEnd.Get(); ok { + b.SetGameEnd(v) + } + if v, ok := req.GameAccount.Get(); ok { + b.SetGameAccount(v) + } + if v, ok := req.GameLv.Get(); ok { + b.SetGameLv(v) + } + if v, ok := req.Coin.Get(); ok { + b.SetCoin(v) + } + if v, ok := req.CoinOpen.Get(); ok { + b.SetCoinOpen(v) + } + if v, ok := req.CoinAt.Get(); ok { + b.SetCoinAt(v) + } + // Add all edges. + if req.Card != nil { + b.ClearCard().AddCardIDs(req.Card...) + } + if req.Ue != nil { + b.ClearUe().AddUeIDs(req.Ue...) + } + if req.Ma != nil { + b.ClearMa().AddMaIDs(req.Ma...) + } b.SetToken(v) } } @@ -1336,3 +1634,39 @@ func (h *OgentHandler) ListUserUe(ctx context.Context, params ListUserUeParams) r := NewUserUeLists(es) return (*ListUserUeOKApplicationJSON)(&r), nil } + +// ListUserMa handles GET /users/{id}/ma requests. +func (h *OgentHandler) ListUserMa(ctx context.Context, params ListUserMaParams) (ListUserMaRes, error) { + q := h.client.User.Query().Where(user.IDEQ(params.ID)).QueryMa() + page := 1 + if v, ok := params.Page.Get(); ok { + page = v + } + itemsPerPage := 30 + if v, ok := params.ItemsPerPage.Get(); ok { + itemsPerPage = v + } + q.Limit(itemsPerPage).Offset((page - 1) * itemsPerPage) + es, err := q.All(ctx) + if err != nil { + switch { + case ent.IsNotFound(err): + return &R404{ + Code: http.StatusNotFound, + Status: http.StatusText(http.StatusNotFound), + Errors: rawError(err), + }, nil + case ent.IsNotSingular(err): + return &R409{ + Code: http.StatusConflict, + Status: http.StatusText(http.StatusConflict), + Errors: rawError(err), + }, nil + default: + // Let the server handle the error. + return nil, err + } + } + r := NewUserMaLists(es) + return (*ListUserMaOKApplicationJSON)(&r), nil +}