test manga
This commit is contained in:
parent
b48ec9e88c
commit
6a868436e7
164
ent/client.go
164
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
|
||||
}
|
||||
)
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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)
|
||||
|
290
ent/ma.go
Normal file
290
ent/ma.go
Normal file
@ -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=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("token=<sensitive>")
|
||||
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
|
197
ent/ma/ma.go
Normal file
197
ent/ma/ma.go
Normal file
@ -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),
|
||||
)
|
||||
}
|
1091
ent/ma/where.go
Normal file
1091
ent/ma/where.go
Normal file
File diff suppressed because it is too large
Load Diff
465
ent/ma_create.go
Normal file
465
ent/ma_create.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
88
ent/ma_delete.go
Normal file
88
ent/ma_delete.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
613
ent/ma_query.go
Normal file
613
ent/ma_query.go
Normal file
@ -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)
|
||||
}
|
941
ent/ma_update.go
Normal file
941
ent/ma_update.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
1473
ent/mutation.go
1473
ent/mutation.go
File diff suppressed because it is too large
Load Diff
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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()
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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:]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
926
ent/openapi.json
926
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": {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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.
|
||||
|
77
ent/schema/manga.go
Normal file
77
ent/schema/manga.go
Normal file
@ -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(),
|
||||
}
|
||||
}
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
18
ent/user.go
18
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.
|
||||
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user