diff --git a/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl b/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl index b68f8a86f..c22529684 100644 --- a/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl +++ b/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl @@ -68,21 +68,25 @@ {{- end }} {{- end }} {{- range .G.FieldMap.Edges }} - {{- if .EntEdge.Unique }} - {{- $varName := camel (printf "%s_%s" $reqVar .EntEdge.Name) -}} - {{- $id := printf "%s.Get%s().Get%s()" $reqVar .PbStructField .EdgeIDPbStructField }} - {{- $other := printf "%s.Get%s()" $reqVar .PbStructField }} - if {{ $other }} != nil { - {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} - m.Set{{ .EntEdge.StructField }}ID({{ $varName }}) - } - {{- else }} - for _, item := range {{ $reqVar }}.Get{{ .PbStructField }}() { - {{- $varName := camel .EntEdge.StructField }} - {{- $id := printf "item.Get%s()" .EdgeIDPbStructField }} - {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} - m.Add{{ singular .EntEdge.StructField }}IDs({{ $varName }}) - } + {{- $skipImmutable := and ( eq $methodName "Update" ) .EntEdge.Immutable -}} + {{- $skip := $skipImmutable -}} + {{- if not $skip }} + {{- if .EntEdge.Unique }} + {{- $varName := camel (printf "%s_%s" $reqVar .EntEdge.Name) -}} + {{- $id := printf "%s.Get%s().Get%s()" $reqVar .PbStructField .EdgeIDPbStructField }} + {{- $other := printf "%s.Get%s()" $reqVar .PbStructField }} + if {{ $other }} != nil { + {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} + m.Set{{ .EntEdge.StructField }}ID({{ $varName }}) + } + {{- else }} + for _, item := range {{ $reqVar }}.Get{{ .PbStructField }}() { + {{- $varName := camel .EntEdge.StructField }} + {{- $id := printf "item.Get%s()" .EdgeIDPbStructField }} + {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} + m.Add{{ singular .EntEdge.StructField }}IDs({{ $varName }}) + } + {{- end }} {{- end }} {{- end }} -{{ end }} \ No newline at end of file +{{ end }} diff --git a/entproto/internal/altdir/ent/account.go b/entproto/internal/altdir/ent/account.go new file mode 100644 index 000000000..be420686d --- /dev/null +++ b/entproto/internal/altdir/ent/account.go @@ -0,0 +1,132 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + + "entgo.io/contrib/entproto/internal/altdir/ent/account" + "entgo.io/contrib/entproto/internal/altdir/ent/user" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// Account is the model entity for the Account schema. +type Account struct { + config + // ID of the ent. + ID int `json:"id,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the AccountQuery when eager-loading is set. + Edges AccountEdges `json:"edges"` + user_accounts *int + selectValues sql.SelectValues +} + +// AccountEdges holds the relations/edges for other nodes in the graph. +type AccountEdges 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 AccountEdges) 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 (*Account) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case account.FieldID: + values[i] = new(sql.NullInt64) + case account.ForeignKeys[0]: // user_accounts + 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 Account fields. +func (a *Account) 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 account.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + a.ID = int(value.Int64) + case account.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field user_accounts", value) + } else if value.Valid { + a.user_accounts = new(int) + *a.user_accounts = int(value.Int64) + } + default: + a.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Account. +// This includes values selected through modifiers, order, etc. +func (a *Account) Value(name string) (ent.Value, error) { + return a.selectValues.Get(name) +} + +// QueryOwner queries the "owner" edge of the Account entity. +func (a *Account) QueryOwner() *UserQuery { + return NewAccountClient(a.config).QueryOwner(a) +} + +// Update returns a builder for updating this Account. +// Note that you need to call Account.Unwrap() before calling this method if this Account +// was returned from a transaction, and the transaction was committed or rolled back. +func (a *Account) Update() *AccountUpdateOne { + return NewAccountClient(a.config).UpdateOne(a) +} + +// Unwrap unwraps the Account 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 (a *Account) Unwrap() *Account { + _tx, ok := a.config.driver.(*txDriver) + if !ok { + panic("ent: Account is not a transactional entity") + } + a.config.driver = _tx.drv + return a +} + +// String implements the fmt.Stringer. +func (a *Account) String() string { + var builder strings.Builder + builder.WriteString("Account(") + builder.WriteString(fmt.Sprintf("id=%v", a.ID)) + builder.WriteByte(')') + return builder.String() +} + +// Accounts is a parsable slice of Account. +type Accounts []*Account diff --git a/entproto/internal/altdir/ent/account/account.go b/entproto/internal/altdir/ent/account/account.go new file mode 100644 index 000000000..afaa5b887 --- /dev/null +++ b/entproto/internal/altdir/ent/account/account.go @@ -0,0 +1,74 @@ +// Code generated by ent, DO NOT EDIT. + +package account + +import ( + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the account type in the database. + Label = "account" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // EdgeOwner holds the string denoting the owner edge name in mutations. + EdgeOwner = "owner" + // Table holds the table name of the account in the database. + Table = "accounts" + // OwnerTable is the table that holds the owner relation/edge. + OwnerTable = "accounts" + // 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_accounts" +) + +// Columns holds all SQL columns for account fields. +var Columns = []string{ + FieldID, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "accounts" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "user_accounts", +} + +// 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 +} + +// OrderOption defines the ordering options for the Account 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() +} + +// ByOwnerField orders the results by owner field. +func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...)) + } +} +func newOwnerStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(OwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn), + ) +} diff --git a/entproto/internal/altdir/ent/account/where.go b/entproto/internal/altdir/ent/account/where.go new file mode 100644 index 000000000..f33603c16 --- /dev/null +++ b/entproto/internal/altdir/ent/account/where.go @@ -0,0 +1,92 @@ +// Code generated by ent, DO NOT EDIT. + +package account + +import ( + "entgo.io/contrib/entproto/internal/altdir/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.Account { + return predicate.Account(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.Account { + return predicate.Account(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.Account { + return predicate.Account(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.Account { + return predicate.Account(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.Account { + return predicate.Account(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.Account { + return predicate.Account(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.Account { + return predicate.Account(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.Account { + return predicate.Account(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.Account { + return predicate.Account(sql.FieldLTE(FieldID, id)) +} + +// HasOwner applies the HasEdge predicate on the "owner" edge. +func HasOwner() predicate.Account { + return predicate.Account(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates). +func HasOwnerWith(preds ...predicate.User) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + step := newOwnerStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Account) predicate.Account { + return predicate.Account(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Account) predicate.Account { + return predicate.Account(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Account) predicate.Account { + return predicate.Account(sql.NotPredicates(p)) +} diff --git a/entproto/internal/altdir/ent/account_create.go b/entproto/internal/altdir/ent/account_create.go new file mode 100644 index 000000000..243c44a52 --- /dev/null +++ b/entproto/internal/altdir/ent/account_create.go @@ -0,0 +1,206 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "entgo.io/contrib/entproto/internal/altdir/ent/account" + "entgo.io/contrib/entproto/internal/altdir/ent/user" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountCreate is the builder for creating a Account entity. +type AccountCreate struct { + config + mutation *AccountMutation + hooks []Hook +} + +// SetOwnerID sets the "owner" edge to the User entity by ID. +func (ac *AccountCreate) SetOwnerID(id int) *AccountCreate { + ac.mutation.SetOwnerID(id) + return ac +} + +// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil. +func (ac *AccountCreate) SetNillableOwnerID(id *int) *AccountCreate { + if id != nil { + ac = ac.SetOwnerID(*id) + } + return ac +} + +// SetOwner sets the "owner" edge to the User entity. +func (ac *AccountCreate) SetOwner(u *User) *AccountCreate { + return ac.SetOwnerID(u.ID) +} + +// Mutation returns the AccountMutation object of the builder. +func (ac *AccountCreate) Mutation() *AccountMutation { + return ac.mutation +} + +// Save creates the Account in the database. +func (ac *AccountCreate) Save(ctx context.Context) (*Account, error) { + return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (ac *AccountCreate) SaveX(ctx context.Context) *Account { + v, err := ac.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ac *AccountCreate) Exec(ctx context.Context) error { + _, err := ac.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ac *AccountCreate) ExecX(ctx context.Context) { + if err := ac.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ac *AccountCreate) check() error { + return nil +} + +func (ac *AccountCreate) sqlSave(ctx context.Context) (*Account, error) { + if err := ac.check(); err != nil { + return nil, err + } + _node, _spec := ac.createSpec() + if err := sqlgraph.CreateNode(ctx, ac.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) + ac.mutation.id = &_node.ID + ac.mutation.done = true + return _node, nil +} + +func (ac *AccountCreate) createSpec() (*Account, *sqlgraph.CreateSpec) { + var ( + _node = &Account{config: ac.config} + _spec = sqlgraph.NewCreateSpec(account.Table, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt)) + ) + if nodes := ac.mutation.OwnerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: account.OwnerTable, + Columns: []string{account.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_accounts = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// AccountCreateBulk is the builder for creating many Account entities in bulk. +type AccountCreateBulk struct { + config + err error + builders []*AccountCreate +} + +// Save creates the Account entities in the database. +func (acb *AccountCreateBulk) Save(ctx context.Context) ([]*Account, error) { + if acb.err != nil { + return nil, acb.err + } + specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) + nodes := make([]*Account, len(acb.builders)) + mutators := make([]Mutator, len(acb.builders)) + for i := range acb.builders { + func(i int, root context.Context) { + builder := acb.builders[i] + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AccountMutation) + 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, acb.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, acb.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, acb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (acb *AccountCreateBulk) SaveX(ctx context.Context) []*Account { + v, err := acb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (acb *AccountCreateBulk) Exec(ctx context.Context) error { + _, err := acb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (acb *AccountCreateBulk) ExecX(ctx context.Context) { + if err := acb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/entproto/internal/altdir/ent/account_delete.go b/entproto/internal/altdir/ent/account_delete.go new file mode 100644 index 000000000..e749afb95 --- /dev/null +++ b/entproto/internal/altdir/ent/account_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/contrib/entproto/internal/altdir/ent/account" + "entgo.io/contrib/entproto/internal/altdir/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountDelete is the builder for deleting a Account entity. +type AccountDelete struct { + config + hooks []Hook + mutation *AccountMutation +} + +// Where appends a list predicates to the AccountDelete builder. +func (ad *AccountDelete) Where(ps ...predicate.Account) *AccountDelete { + ad.mutation.Where(ps...) + return ad +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ad *AccountDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, ad.sqlExec, ad.mutation, ad.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (ad *AccountDelete) ExecX(ctx context.Context) int { + n, err := ad.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ad *AccountDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(account.Table, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt)) + if ps := ad.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, ad.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + ad.mutation.done = true + return affected, err +} + +// AccountDeleteOne is the builder for deleting a single Account entity. +type AccountDeleteOne struct { + ad *AccountDelete +} + +// Where appends a list predicates to the AccountDelete builder. +func (ado *AccountDeleteOne) Where(ps ...predicate.Account) *AccountDeleteOne { + ado.ad.mutation.Where(ps...) + return ado +} + +// Exec executes the deletion query. +func (ado *AccountDeleteOne) Exec(ctx context.Context) error { + n, err := ado.ad.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{account.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ado *AccountDeleteOne) ExecX(ctx context.Context) { + if err := ado.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/entproto/internal/altdir/ent/account_query.go b/entproto/internal/altdir/ent/account_query.go new file mode 100644 index 000000000..9bcd9c071 --- /dev/null +++ b/entproto/internal/altdir/ent/account_query.go @@ -0,0 +1,591 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/contrib/entproto/internal/altdir/ent/account" + "entgo.io/contrib/entproto/internal/altdir/ent/predicate" + "entgo.io/contrib/entproto/internal/altdir/ent/user" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountQuery is the builder for querying Account entities. +type AccountQuery struct { + config + ctx *QueryContext + order []account.OrderOption + inters []Interceptor + predicates []predicate.Account + 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 AccountQuery builder. +func (aq *AccountQuery) Where(ps ...predicate.Account) *AccountQuery { + aq.predicates = append(aq.predicates, ps...) + return aq +} + +// Limit the number of records to be returned by this query. +func (aq *AccountQuery) Limit(limit int) *AccountQuery { + aq.ctx.Limit = &limit + return aq +} + +// Offset to start from. +func (aq *AccountQuery) Offset(offset int) *AccountQuery { + aq.ctx.Offset = &offset + return aq +} + +// 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 (aq *AccountQuery) Unique(unique bool) *AccountQuery { + aq.ctx.Unique = &unique + return aq +} + +// Order specifies how the records should be ordered. +func (aq *AccountQuery) Order(o ...account.OrderOption) *AccountQuery { + aq.order = append(aq.order, o...) + return aq +} + +// QueryOwner chains the current query on the "owner" edge. +func (aq *AccountQuery) QueryOwner() *UserQuery { + query := (&UserClient{config: aq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := aq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(account.Table, account.FieldID, selector), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, account.OwnerTable, account.OwnerColumn), + ) + fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Account entity from the query. +// Returns a *NotFoundError when no Account was found. +func (aq *AccountQuery) First(ctx context.Context) (*Account, error) { + nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, "First")) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{account.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (aq *AccountQuery) FirstX(ctx context.Context) *Account { + node, err := aq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Account ID from the query. +// Returns a *NotFoundError when no Account ID was found. +func (aq *AccountQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, "FirstID")); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{account.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (aq *AccountQuery) FirstIDX(ctx context.Context) int { + id, err := aq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Account entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Account entity is found. +// Returns a *NotFoundError when no Account entities are found. +func (aq *AccountQuery) Only(ctx context.Context) (*Account, error) { + nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, "Only")) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{account.Label} + default: + return nil, &NotSingularError{account.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (aq *AccountQuery) OnlyX(ctx context.Context) *Account { + node, err := aq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Account ID in the query. +// Returns a *NotSingularError when more than one Account ID is found. +// Returns a *NotFoundError when no entities are found. +func (aq *AccountQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, "OnlyID")); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{account.Label} + default: + err = &NotSingularError{account.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (aq *AccountQuery) OnlyIDX(ctx context.Context) int { + id, err := aq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Accounts. +func (aq *AccountQuery) All(ctx context.Context) ([]*Account, error) { + ctx = setContextOp(ctx, aq.ctx, "All") + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Account, *AccountQuery]() + return withInterceptors[[]*Account](ctx, aq, qr, aq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (aq *AccountQuery) AllX(ctx context.Context) []*Account { + nodes, err := aq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Account IDs. +func (aq *AccountQuery) IDs(ctx context.Context) (ids []int, err error) { + if aq.ctx.Unique == nil && aq.path != nil { + aq.Unique(true) + } + ctx = setContextOp(ctx, aq.ctx, "IDs") + if err = aq.Select(account.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (aq *AccountQuery) IDsX(ctx context.Context) []int { + ids, err := aq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (aq *AccountQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, aq.ctx, "Count") + if err := aq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, aq, querierCount[*AccountQuery](), aq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (aq *AccountQuery) CountX(ctx context.Context) int { + count, err := aq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (aq *AccountQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, aq.ctx, "Exist") + switch _, err := aq.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 (aq *AccountQuery) ExistX(ctx context.Context) bool { + exist, err := aq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AccountQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (aq *AccountQuery) Clone() *AccountQuery { + if aq == nil { + return nil + } + return &AccountQuery{ + config: aq.config, + ctx: aq.ctx.Clone(), + order: append([]account.OrderOption{}, aq.order...), + inters: append([]Interceptor{}, aq.inters...), + predicates: append([]predicate.Account{}, aq.predicates...), + withOwner: aq.withOwner.Clone(), + // clone intermediate query. + sql: aq.sql.Clone(), + path: aq.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 (aq *AccountQuery) WithOwner(opts ...func(*UserQuery)) *AccountQuery { + query := (&UserClient{config: aq.config}).Query() + for _, opt := range opts { + opt(query) + } + aq.withOwner = query + return aq +} + +// 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. +func (aq *AccountQuery) GroupBy(field string, fields ...string) *AccountGroupBy { + aq.ctx.Fields = append([]string{field}, fields...) + grbuild := &AccountGroupBy{build: aq} + grbuild.flds = &aq.ctx.Fields + grbuild.label = account.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. +func (aq *AccountQuery) Select(fields ...string) *AccountSelect { + aq.ctx.Fields = append(aq.ctx.Fields, fields...) + sbuild := &AccountSelect{AccountQuery: aq} + sbuild.label = account.Label + sbuild.flds, sbuild.scan = &aq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AccountSelect configured with the given aggregations. +func (aq *AccountQuery) Aggregate(fns ...AggregateFunc) *AccountSelect { + return aq.Select().Aggregate(fns...) +} + +func (aq *AccountQuery) prepareQuery(ctx context.Context) error { + for _, inter := range aq.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, aq); err != nil { + return err + } + } + } + for _, f := range aq.ctx.Fields { + if !account.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if aq.path != nil { + prev, err := aq.path(ctx) + if err != nil { + return err + } + aq.sql = prev + } + return nil +} + +func (aq *AccountQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Account, error) { + var ( + nodes = []*Account{} + withFKs = aq.withFKs + _spec = aq.querySpec() + loadedTypes = [1]bool{ + aq.withOwner != nil, + } + ) + if aq.withOwner != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, account.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Account).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Account{config: aq.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, aq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := aq.withOwner; query != nil { + if err := aq.loadOwner(ctx, query, nodes, nil, + func(n *Account, e *User) { n.Edges.Owner = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (aq *AccountQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Account, init func(*Account), assign func(*Account, *User)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Account) + for i := range nodes { + if nodes[i].user_accounts == nil { + continue + } + fk := *nodes[i].user_accounts + 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_accounts" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (aq *AccountQuery) sqlCount(ctx context.Context) (int, error) { + _spec := aq.querySpec() + _spec.Node.Columns = aq.ctx.Fields + if len(aq.ctx.Fields) > 0 { + _spec.Unique = aq.ctx.Unique != nil && *aq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, aq.driver, _spec) +} + +func (aq *AccountQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt)) + _spec.From = aq.sql + if unique := aq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if aq.path != nil { + _spec.Unique = true + } + if fields := aq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, account.FieldID) + for i := range fields { + if fields[i] != account.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := aq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := aq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := aq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := aq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (aq *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(aq.driver.Dialect()) + t1 := builder.Table(account.Table) + columns := aq.ctx.Fields + if len(columns) == 0 { + columns = account.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if aq.sql != nil { + selector = aq.sql + selector.Select(selector.Columns(columns...)...) + } + if aq.ctx.Unique != nil && *aq.ctx.Unique { + selector.Distinct() + } + for _, p := range aq.predicates { + p(selector) + } + for _, p := range aq.order { + p(selector) + } + if offset := aq.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 := aq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// AccountGroupBy is the group-by builder for Account entities. +type AccountGroupBy struct { + selector + build *AccountQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (agb *AccountGroupBy) Aggregate(fns ...AggregateFunc) *AccountGroupBy { + agb.fns = append(agb.fns, fns...) + return agb +} + +// Scan applies the selector query and scans the result into the given value. +func (agb *AccountGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, agb.build.ctx, "GroupBy") + if err := agb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AccountQuery, *AccountGroupBy](ctx, agb.build, agb, agb.build.inters, v) +} + +func (agb *AccountGroupBy) sqlScan(ctx context.Context, root *AccountQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(agb.fns)) + for _, fn := range agb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*agb.flds)+len(agb.fns)) + for _, f := range *agb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*agb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := agb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// AccountSelect is the builder for selecting fields of Account entities. +type AccountSelect struct { + *AccountQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (as *AccountSelect) Aggregate(fns ...AggregateFunc) *AccountSelect { + as.fns = append(as.fns, fns...) + return as +} + +// Scan applies the selector query and scans the result into the given value. +func (as *AccountSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, as.ctx, "Select") + if err := as.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AccountQuery, *AccountSelect](ctx, as.AccountQuery, as, as.inters, v) +} + +func (as *AccountSelect) sqlScan(ctx context.Context, root *AccountQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(as.fns)) + for _, fn := range as.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*as.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 := as.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/entproto/internal/altdir/ent/account_update.go b/entproto/internal/altdir/ent/account_update.go new file mode 100644 index 000000000..1c6d6ad4c --- /dev/null +++ b/entproto/internal/altdir/ent/account_update.go @@ -0,0 +1,175 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/contrib/entproto/internal/altdir/ent/account" + "entgo.io/contrib/entproto/internal/altdir/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountUpdate is the builder for updating Account entities. +type AccountUpdate struct { + config + hooks []Hook + mutation *AccountMutation +} + +// Where appends a list predicates to the AccountUpdate builder. +func (au *AccountUpdate) Where(ps ...predicate.Account) *AccountUpdate { + au.mutation.Where(ps...) + return au +} + +// Mutation returns the AccountMutation object of the builder. +func (au *AccountUpdate) Mutation() *AccountMutation { + return au.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (au *AccountUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, au.sqlSave, au.mutation, au.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (au *AccountUpdate) SaveX(ctx context.Context) int { + affected, err := au.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (au *AccountUpdate) Exec(ctx context.Context) error { + _, err := au.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (au *AccountUpdate) ExecX(ctx context.Context) { + if err := au.Exec(ctx); err != nil { + panic(err) + } +} + +func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt)) + if ps := au.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{account.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + au.mutation.done = true + return n, nil +} + +// AccountUpdateOne is the builder for updating a single Account entity. +type AccountUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AccountMutation +} + +// Mutation returns the AccountMutation object of the builder. +func (auo *AccountUpdateOne) Mutation() *AccountMutation { + return auo.mutation +} + +// Where appends a list predicates to the AccountUpdate builder. +func (auo *AccountUpdateOne) Where(ps ...predicate.Account) *AccountUpdateOne { + auo.mutation.Where(ps...) + return auo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (auo *AccountUpdateOne) Select(field string, fields ...string) *AccountUpdateOne { + auo.fields = append([]string{field}, fields...) + return auo +} + +// Save executes the query and returns the updated Account entity. +func (auo *AccountUpdateOne) Save(ctx context.Context) (*Account, error) { + return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (auo *AccountUpdateOne) SaveX(ctx context.Context) *Account { + node, err := auo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (auo *AccountUpdateOne) Exec(ctx context.Context) error { + _, err := auo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (auo *AccountUpdateOne) ExecX(ctx context.Context) { + if err := auo.Exec(ctx); err != nil { + panic(err) + } +} + +func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) { + _spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt)) + id, ok := auo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := auo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, account.FieldID) + for _, f := range fields { + if !account.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != account.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := auo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + _node = &Account{config: auo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{account.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + auo.mutation.done = true + return _node, nil +} diff --git a/entproto/internal/altdir/ent/client.go b/entproto/internal/altdir/ent/client.go index 984a65b19..c6ab1ca45 100644 --- a/entproto/internal/altdir/ent/client.go +++ b/entproto/internal/altdir/ent/client.go @@ -12,9 +12,11 @@ import ( "entgo.io/contrib/entproto/internal/altdir/ent/migrate" "entgo.io/ent" + "entgo.io/contrib/entproto/internal/altdir/ent/account" "entgo.io/contrib/entproto/internal/altdir/ent/user" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" ) // Client is the client that holds all ent builders. @@ -22,6 +24,8 @@ type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema + // Account is the client for interacting with the Account builders. + Account *AccountClient // User is the client for interacting with the User builders. User *UserClient } @@ -37,6 +41,7 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) + c.Account = NewAccountClient(c.config) c.User = NewUserClient(c.config) } @@ -121,9 +126,10 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - User: NewUserClient(cfg), + ctx: ctx, + config: cfg, + Account: NewAccountClient(cfg), + User: NewUserClient(cfg), }, nil } @@ -141,16 +147,17 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - User: NewUserClient(cfg), + ctx: ctx, + config: cfg, + Account: NewAccountClient(cfg), + User: NewUserClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). -// User. +// Account. // Query(). // Count(ctx) func (c *Client) Debug() *Client { @@ -172,18 +179,22 @@ func (c *Client) Close() error { // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { + c.Account.Use(hooks...) c.User.Use(hooks...) } // Intercept adds the query interceptors to all the entity clients. // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { + c.Account.Intercept(interceptors...) c.User.Intercept(interceptors...) } // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { + case *AccountMutation: + return c.Account.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) default: @@ -191,6 +202,155 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { } } +// AccountClient is a client for the Account schema. +type AccountClient struct { + config +} + +// NewAccountClient returns a client for the Account from the given config. +func NewAccountClient(c config) *AccountClient { + return &AccountClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `account.Hooks(f(g(h())))`. +func (c *AccountClient) Use(hooks ...Hook) { + c.hooks.Account = append(c.hooks.Account, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `account.Intercept(f(g(h())))`. +func (c *AccountClient) Intercept(interceptors ...Interceptor) { + c.inters.Account = append(c.inters.Account, interceptors...) +} + +// Create returns a builder for creating a Account entity. +func (c *AccountClient) Create() *AccountCreate { + mutation := newAccountMutation(c.config, OpCreate) + return &AccountCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Account entities. +func (c *AccountClient) CreateBulk(builders ...*AccountCreate) *AccountCreateBulk { + return &AccountCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AccountClient) MapCreateBulk(slice any, setFunc func(*AccountCreate, int)) *AccountCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AccountCreateBulk{err: fmt.Errorf("calling to AccountClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AccountCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AccountCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Account. +func (c *AccountClient) Update() *AccountUpdate { + mutation := newAccountMutation(c.config, OpUpdate) + return &AccountUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AccountClient) UpdateOne(a *Account) *AccountUpdateOne { + mutation := newAccountMutation(c.config, OpUpdateOne, withAccount(a)) + return &AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AccountClient) UpdateOneID(id int) *AccountUpdateOne { + mutation := newAccountMutation(c.config, OpUpdateOne, withAccountID(id)) + return &AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Account. +func (c *AccountClient) Delete() *AccountDelete { + mutation := newAccountMutation(c.config, OpDelete) + return &AccountDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *AccountClient) DeleteOne(a *Account) *AccountDeleteOne { + return c.DeleteOneID(a.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *AccountClient) DeleteOneID(id int) *AccountDeleteOne { + builder := c.Delete().Where(account.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AccountDeleteOne{builder} +} + +// Query returns a query builder for Account. +func (c *AccountClient) Query() *AccountQuery { + return &AccountQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeAccount}, + inters: c.Interceptors(), + } +} + +// Get returns a Account entity by its id. +func (c *AccountClient) Get(ctx context.Context, id int) (*Account, error) { + return c.Query().Where(account.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AccountClient) GetX(ctx context.Context, id int) *Account { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryOwner queries the owner edge of a Account. +func (c *AccountClient) QueryOwner(a *Account) *UserQuery { + query := (&UserClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := a.ID + step := sqlgraph.NewStep( + sqlgraph.From(account.Table, account.FieldID, id), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, account.OwnerTable, account.OwnerColumn), + ) + fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *AccountClient) Hooks() []Hook { + return c.hooks.Account +} + +// Interceptors returns the client interceptors. +func (c *AccountClient) Interceptors() []Interceptor { + return c.inters.Account +} + +func (c *AccountClient) mutate(ctx context.Context, m *AccountMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AccountCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AccountUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AccountDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Account mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -299,6 +459,22 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { return obj } +// QueryAccounts queries the accounts edge of a User. +func (c *UserClient) QueryAccounts(u *User) *AccountQuery { + query := (&AccountClient{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(account.Table, account.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.AccountsTable, user.AccountsColumn), + ) + 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 @@ -327,9 +503,9 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) // hooks and interceptors per client, for fast access. type ( hooks struct { - User []ent.Hook + Account, User []ent.Hook } inters struct { - User []ent.Interceptor + Account, User []ent.Interceptor } ) diff --git a/entproto/internal/altdir/ent/ent.go b/entproto/internal/altdir/ent/ent.go index 4a33fb986..14729128c 100644 --- a/entproto/internal/altdir/ent/ent.go +++ b/entproto/internal/altdir/ent/ent.go @@ -9,6 +9,7 @@ import ( "reflect" "sync" + "entgo.io/contrib/entproto/internal/altdir/ent/account" "entgo.io/contrib/entproto/internal/altdir/ent/user" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -73,7 +74,8 @@ var ( func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - user.Table: user.ValidColumn, + account.Table: account.ValidColumn, + user.Table: user.ValidColumn, }) }) return columnCheck(table, column) diff --git a/entproto/internal/altdir/ent/hook/hook.go b/entproto/internal/altdir/ent/hook/hook.go index 1dc8d81a9..4807a7742 100644 --- a/entproto/internal/altdir/ent/hook/hook.go +++ b/entproto/internal/altdir/ent/hook/hook.go @@ -9,6 +9,18 @@ import ( "entgo.io/contrib/entproto/internal/altdir/ent" ) +// The AccountFunc type is an adapter to allow the use of ordinary +// function as Account mutator. +type AccountFunc func(context.Context, *ent.AccountMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f AccountFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.AccountMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AccountMutation", m) +} + // The UserFunc type is an adapter to allow the use of ordinary // function as User mutator. type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) diff --git a/entproto/internal/altdir/ent/migrate/schema.go b/entproto/internal/altdir/ent/migrate/schema.go index 2a9393904..eb8d4cda4 100644 --- a/entproto/internal/altdir/ent/migrate/schema.go +++ b/entproto/internal/altdir/ent/migrate/schema.go @@ -8,6 +8,25 @@ import ( ) var ( + // AccountsColumns holds the columns for the "accounts" table. + AccountsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "user_accounts", Type: field.TypeInt, Nullable: true}, + } + // AccountsTable holds the schema information for the "accounts" table. + AccountsTable = &schema.Table{ + Name: "accounts", + Columns: AccountsColumns, + PrimaryKey: []*schema.Column{AccountsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "accounts_users_accounts", + Columns: []*schema.Column{AccountsColumns[1]}, + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -21,9 +40,11 @@ var ( } // Tables holds all the tables in the schema. Tables = []*schema.Table{ + AccountsTable, UsersTable, } ) func init() { + AccountsTable.ForeignKeys[0].RefTable = UsersTable } diff --git a/entproto/internal/altdir/ent/mutation.go b/entproto/internal/altdir/ent/mutation.go index 1a078f612..50e25918c 100644 --- a/entproto/internal/altdir/ent/mutation.go +++ b/entproto/internal/altdir/ent/mutation.go @@ -8,6 +8,7 @@ import ( "fmt" "sync" + "entgo.io/contrib/entproto/internal/altdir/ent/account" "entgo.io/contrib/entproto/internal/altdir/ent/predicate" "entgo.io/contrib/entproto/internal/altdir/ent/user" "entgo.io/ent" @@ -23,20 +24,355 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeUser = "User" + TypeAccount = "Account" + TypeUser = "User" ) -// UserMutation represents an operation that mutates the User nodes in the graph. -type UserMutation struct { +// AccountMutation represents an operation that mutates the Account nodes in the graph. +type AccountMutation struct { config op Op typ string id *int - name *string clearedFields map[string]struct{} + owner *int + clearedowner bool done bool - oldValue func(context.Context) (*User, error) - predicates []predicate.User + oldValue func(context.Context) (*Account, error) + predicates []predicate.Account +} + +var _ ent.Mutation = (*AccountMutation)(nil) + +// accountOption allows management of the mutation configuration using functional options. +type accountOption func(*AccountMutation) + +// newAccountMutation creates new mutation for the Account entity. +func newAccountMutation(c config, op Op, opts ...accountOption) *AccountMutation { + m := &AccountMutation{ + config: c, + op: op, + typ: TypeAccount, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withAccountID sets the ID field of the mutation. +func withAccountID(id int) accountOption { + return func(m *AccountMutation) { + var ( + err error + once sync.Once + value *Account + ) + m.oldValue = func(ctx context.Context) (*Account, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Account.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withAccount sets the old Account of the mutation. +func withAccount(node *Account) accountOption { + return func(m *AccountMutation) { + m.oldValue = func(context.Context) (*Account, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m AccountMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m AccountMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *AccountMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *AccountMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Account.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetOwnerID sets the "owner" edge to the User entity by id. +func (m *AccountMutation) SetOwnerID(id int) { + m.owner = &id +} + +// ClearOwner clears the "owner" edge to the User entity. +func (m *AccountMutation) ClearOwner() { + m.clearedowner = true +} + +// OwnerCleared reports if the "owner" edge to the User entity was cleared. +func (m *AccountMutation) OwnerCleared() bool { + return m.clearedowner +} + +// OwnerID returns the "owner" edge ID in the mutation. +func (m *AccountMutation) OwnerID() (id int, exists bool) { + if m.owner != nil { + return *m.owner, true + } + return +} + +// OwnerIDs returns the "owner" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// OwnerID instead. It exists only for internal usage by the builders. +func (m *AccountMutation) OwnerIDs() (ids []int) { + if id := m.owner; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetOwner resets all changes to the "owner" edge. +func (m *AccountMutation) ResetOwner() { + m.owner = nil + m.clearedowner = false +} + +// Where appends a list predicates to the AccountMutation builder. +func (m *AccountMutation) Where(ps ...predicate.Account) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the AccountMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AccountMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Account, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *AccountMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *AccountMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Account). +func (m *AccountMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *AccountMutation) Fields() []string { + fields := make([]string, 0, 0) + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *AccountMutation) Field(name string) (ent.Value, bool) { + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *AccountMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + return nil, fmt.Errorf("unknown Account field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AccountMutation) SetField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Account field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *AccountMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *AccountMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AccountMutation) AddField(name string, value ent.Value) error { + return fmt.Errorf("unknown Account numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *AccountMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *AccountMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *AccountMutation) ClearField(name string) error { + return fmt.Errorf("unknown Account nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *AccountMutation) ResetField(name string) error { + return fmt.Errorf("unknown Account field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *AccountMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.owner != nil { + edges = append(edges, account.EdgeOwner) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *AccountMutation) AddedIDs(name string) []ent.Value { + switch name { + case account.EdgeOwner: + if id := m.owner; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *AccountMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *AccountMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *AccountMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedowner { + edges = append(edges, account.EdgeOwner) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *AccountMutation) EdgeCleared(name string) bool { + switch name { + case account.EdgeOwner: + return m.clearedowner + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *AccountMutation) ClearEdge(name string) error { + switch name { + case account.EdgeOwner: + m.ClearOwner() + return nil + } + return fmt.Errorf("unknown Account unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *AccountMutation) ResetEdge(name string) error { + switch name { + case account.EdgeOwner: + m.ResetOwner() + return nil + } + return fmt.Errorf("unknown Account edge %s", name) +} + +// UserMutation represents an operation that mutates the User nodes in the graph. +type UserMutation struct { + config + op Op + typ string + id *int + name *string + clearedFields map[string]struct{} + accounts map[int]struct{} + removedaccounts map[int]struct{} + clearedaccounts bool + done bool + oldValue func(context.Context) (*User, error) + predicates []predicate.User } var _ ent.Mutation = (*UserMutation)(nil) @@ -173,6 +509,60 @@ func (m *UserMutation) ResetName() { m.name = nil } +// AddAccountIDs adds the "accounts" edge to the Account entity by ids. +func (m *UserMutation) AddAccountIDs(ids ...int) { + if m.accounts == nil { + m.accounts = make(map[int]struct{}) + } + for i := range ids { + m.accounts[ids[i]] = struct{}{} + } +} + +// ClearAccounts clears the "accounts" edge to the Account entity. +func (m *UserMutation) ClearAccounts() { + m.clearedaccounts = true +} + +// AccountsCleared reports if the "accounts" edge to the Account entity was cleared. +func (m *UserMutation) AccountsCleared() bool { + return m.clearedaccounts +} + +// RemoveAccountIDs removes the "accounts" edge to the Account entity by IDs. +func (m *UserMutation) RemoveAccountIDs(ids ...int) { + if m.removedaccounts == nil { + m.removedaccounts = make(map[int]struct{}) + } + for i := range ids { + delete(m.accounts, ids[i]) + m.removedaccounts[ids[i]] = struct{}{} + } +} + +// RemovedAccounts returns the removed IDs of the "accounts" edge to the Account entity. +func (m *UserMutation) RemovedAccountsIDs() (ids []int) { + for id := range m.removedaccounts { + ids = append(ids, id) + } + return +} + +// AccountsIDs returns the "accounts" edge IDs in the mutation. +func (m *UserMutation) AccountsIDs() (ids []int) { + for id := range m.accounts { + ids = append(ids, id) + } + return +} + +// ResetAccounts resets all changes to the "accounts" edge. +func (m *UserMutation) ResetAccounts() { + m.accounts = nil + m.clearedaccounts = false + m.removedaccounts = nil +} + // Where appends a list predicates to the UserMutation builder. func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) @@ -306,48 +696,84 @@ func (m *UserMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMutation) AddedEdges() []string { - edges := make([]string, 0, 0) + edges := make([]string, 0, 1) + if m.accounts != nil { + edges = append(edges, user.EdgeAccounts) + } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserMutation) AddedIDs(name string) []ent.Value { + switch name { + case user.EdgeAccounts: + ids := make([]ent.Value, 0, len(m.accounts)) + for id := range m.accounts { + ids = append(ids, id) + } + return ids + } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) + edges := make([]string, 0, 1) + if m.removedaccounts != nil { + edges = append(edges, user.EdgeAccounts) + } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *UserMutation) RemovedIDs(name string) []ent.Value { + switch name { + case user.EdgeAccounts: + ids := make([]ent.Value, 0, len(m.removedaccounts)) + for id := range m.removedaccounts { + ids = append(ids, id) + } + return ids + } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) + edges := make([]string, 0, 1) + if m.clearedaccounts { + edges = append(edges, user.EdgeAccounts) + } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserMutation) EdgeCleared(name string) bool { + switch name { + case user.EdgeAccounts: + return m.clearedaccounts + } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *UserMutation) ClearEdge(name string) error { + switch name { + } return fmt.Errorf("unknown User unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *UserMutation) ResetEdge(name string) error { + switch name { + case user.EdgeAccounts: + m.ResetAccounts() + return nil + } return fmt.Errorf("unknown User edge %s", name) } diff --git a/entproto/internal/altdir/ent/predicate/predicate.go b/entproto/internal/altdir/ent/predicate/predicate.go index af21dfe34..d495bda86 100644 --- a/entproto/internal/altdir/ent/predicate/predicate.go +++ b/entproto/internal/altdir/ent/predicate/predicate.go @@ -6,5 +6,8 @@ import ( "entgo.io/ent/dialect/sql" ) +// Account is the predicate function for account builders. +type Account func(*sql.Selector) + // User is the predicate function for user builders. type User func(*sql.Selector) diff --git a/entproto/internal/altdir/ent/schema/account.go b/entproto/internal/altdir/ent/schema/account.go new file mode 100644 index 000000000..a1a2f0cb0 --- /dev/null +++ b/entproto/internal/altdir/ent/schema/account.go @@ -0,0 +1,47 @@ +// Copyright 2019-present Facebook +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package schema + +import ( + "entgo.io/contrib/entproto" + "entgo.io/ent" + "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" +) + +type Account struct { + ent.Schema +} + +func (Account) Fields() []ent.Field { + return []ent.Field{} +} + +func (Account) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("owner", User.Type). + Ref("accounts"). + Immutable(). + Unique(). + Annotations(entproto.Field(2)), + } +} + +func (Account) Annotations() []schema.Annotation { + return []schema.Annotation{ + entproto.Message(), + entproto.Service(), + } +} diff --git a/entproto/internal/altdir/ent/schema/user.go b/entproto/internal/altdir/ent/schema/user.go index f2e2b09ad..264237c4b 100644 --- a/entproto/internal/altdir/ent/schema/user.go +++ b/entproto/internal/altdir/ent/schema/user.go @@ -18,6 +18,7 @@ import ( "entgo.io/contrib/entproto" "entgo.io/ent" "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" ) @@ -38,7 +39,12 @@ func (User) Fields() []ent.Field { // Edges of the User. func (User) Edges() []ent.Edge { - return nil + return []ent.Edge{ + edge.To("accounts", Account.Type). + Annotations( + entproto.Skip(), + ), + } } func (User) Annotations() []schema.Annotation { diff --git a/entproto/internal/altdir/ent/tx.go b/entproto/internal/altdir/ent/tx.go index 8bbe7fa76..c24ebe2ef 100644 --- a/entproto/internal/altdir/ent/tx.go +++ b/entproto/internal/altdir/ent/tx.go @@ -12,6 +12,8 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config + // Account is the client for interacting with the Account builders. + Account *AccountClient // User is the client for interacting with the User builders. User *UserClient @@ -145,6 +147,7 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { + tx.Account = NewAccountClient(tx.config) tx.User = NewUserClient(tx.config) } @@ -155,7 +158,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: User.QueryXXX(), the query will be executed +// applies a query, for example: Account.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe. diff --git a/entproto/internal/altdir/ent/user.go b/entproto/internal/altdir/ent/user.go index 6d25ed1e4..2d249deea 100644 --- a/entproto/internal/altdir/ent/user.go +++ b/entproto/internal/altdir/ent/user.go @@ -17,10 +17,31 @@ type User struct { // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` + Name string `json:"name,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the UserQuery when eager-loading is set. + Edges UserEdges `json:"edges"` selectValues sql.SelectValues } +// UserEdges holds the relations/edges for other nodes in the graph. +type UserEdges struct { + // Accounts holds the value of the accounts edge. + Accounts []*Account `json:"accounts,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// AccountsOrErr returns the Accounts value or an error if the edge +// was not loaded in eager-loading. +func (e UserEdges) AccountsOrErr() ([]*Account, error) { + if e.loadedTypes[0] { + return e.Accounts, nil + } + return nil, &NotLoadedError{edge: "accounts"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -70,6 +91,11 @@ func (u *User) Value(name string) (ent.Value, error) { return u.selectValues.Get(name) } +// QueryAccounts queries the "accounts" edge of the User entity. +func (u *User) QueryAccounts() *AccountQuery { + return NewUserClient(u.config).QueryAccounts(u) +} + // Update returns a builder for updating this User. // Note that you need to call User.Unwrap() before calling this method if this User // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/entproto/internal/altdir/ent/user/user.go b/entproto/internal/altdir/ent/user/user.go index 8f9088fed..068ea80c8 100644 --- a/entproto/internal/altdir/ent/user/user.go +++ b/entproto/internal/altdir/ent/user/user.go @@ -4,6 +4,7 @@ package user import ( "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" ) const ( @@ -13,8 +14,17 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" + // EdgeAccounts holds the string denoting the accounts edge name in mutations. + EdgeAccounts = "accounts" // Table holds the table name of the user in the database. Table = "users" + // AccountsTable is the table that holds the accounts relation/edge. + AccountsTable = "accounts" + // AccountsInverseTable is the table name for the Account entity. + // It exists in this package in order to avoid circular dependency with the "account" package. + AccountsInverseTable = "accounts" + // AccountsColumn is the table column denoting the accounts relation/edge. + AccountsColumn = "user_accounts" ) // Columns holds all SQL columns for user fields. @@ -45,3 +55,24 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { func ByName(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldName, opts...).ToFunc() } + +// ByAccountsCount orders the results by accounts count. +func ByAccountsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newAccountsStep(), opts...) + } +} + +// ByAccounts orders the results by accounts terms. +func ByAccounts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newAccountsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newAccountsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AccountsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, AccountsTable, AccountsColumn), + ) +} diff --git a/entproto/internal/altdir/ent/user/where.go b/entproto/internal/altdir/ent/user/where.go index c3e1cb08c..0ca6834df 100644 --- a/entproto/internal/altdir/ent/user/where.go +++ b/entproto/internal/altdir/ent/user/where.go @@ -5,6 +5,7 @@ package user import ( "entgo.io/contrib/entproto/internal/altdir/ent/predicate" "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" ) // ID filters vertices based on their ID field. @@ -122,6 +123,29 @@ func NameContainsFold(v string) predicate.User { return predicate.User(sql.FieldContainsFold(FieldName, v)) } +// HasAccounts applies the HasEdge predicate on the "accounts" edge. +func HasAccounts() predicate.User { + return predicate.User(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, AccountsTable, AccountsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAccountsWith applies the HasEdge predicate on the "accounts" edge with a given conditions (other predicates). +func HasAccountsWith(preds ...predicate.Account) predicate.User { + return predicate.User(func(s *sql.Selector) { + step := newAccountsStep() + 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(sql.AndPredicates(predicates...)) diff --git a/entproto/internal/altdir/ent/user_create.go b/entproto/internal/altdir/ent/user_create.go index a208a6d1d..415ba344e 100644 --- a/entproto/internal/altdir/ent/user_create.go +++ b/entproto/internal/altdir/ent/user_create.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" + "entgo.io/contrib/entproto/internal/altdir/ent/account" "entgo.io/contrib/entproto/internal/altdir/ent/user" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -25,6 +26,21 @@ func (uc *UserCreate) SetName(s string) *UserCreate { return uc } +// AddAccountIDs adds the "accounts" edge to the Account entity by IDs. +func (uc *UserCreate) AddAccountIDs(ids ...int) *UserCreate { + uc.mutation.AddAccountIDs(ids...) + return uc +} + +// AddAccounts adds the "accounts" edges to the Account entity. +func (uc *UserCreate) AddAccounts(a ...*Account) *UserCreate { + ids := make([]int, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return uc.AddAccountIDs(ids...) +} + // Mutation returns the UserMutation object of the builder. func (uc *UserCreate) Mutation() *UserMutation { return uc.mutation @@ -92,6 +108,22 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { _spec.SetField(user.FieldName, field.TypeString, value) _node.Name = value } + if nodes := uc.mutation.AccountsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/entproto/internal/altdir/ent/user_query.go b/entproto/internal/altdir/ent/user_query.go index 92e1b0ac4..7d7b08dd5 100644 --- a/entproto/internal/altdir/ent/user_query.go +++ b/entproto/internal/altdir/ent/user_query.go @@ -4,9 +4,11 @@ package ent import ( "context" + "database/sql/driver" "fmt" "math" + "entgo.io/contrib/entproto/internal/altdir/ent/account" "entgo.io/contrib/entproto/internal/altdir/ent/predicate" "entgo.io/contrib/entproto/internal/altdir/ent/user" "entgo.io/ent/dialect/sql" @@ -17,10 +19,11 @@ import ( // UserQuery is the builder for querying User entities. type UserQuery struct { config - ctx *QueryContext - order []user.OrderOption - inters []Interceptor - predicates []predicate.User + ctx *QueryContext + order []user.OrderOption + inters []Interceptor + predicates []predicate.User + withAccounts *AccountQuery // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -57,6 +60,28 @@ func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery { return uq } +// QueryAccounts chains the current query on the "accounts" edge. +func (uq *UserQuery) QueryAccounts() *AccountQuery { + query := (&AccountClient{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(account.Table, account.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.AccountsTable, user.AccountsColumn), + ) + 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) { @@ -244,17 +269,29 @@ func (uq *UserQuery) Clone() *UserQuery { return nil } return &UserQuery{ - config: uq.config, - ctx: uq.ctx.Clone(), - order: append([]user.OrderOption{}, uq.order...), - inters: append([]Interceptor{}, uq.inters...), - predicates: append([]predicate.User{}, uq.predicates...), + config: uq.config, + ctx: uq.ctx.Clone(), + order: append([]user.OrderOption{}, uq.order...), + inters: append([]Interceptor{}, uq.inters...), + predicates: append([]predicate.User{}, uq.predicates...), + withAccounts: uq.withAccounts.Clone(), // clone intermediate query. sql: uq.sql.Clone(), path: uq.path, } } +// WithAccounts tells the query-builder to eager-load the nodes that are connected to +// the "accounts" edge. The optional arguments are used to configure the query builder of the edge. +func (uq *UserQuery) WithAccounts(opts ...func(*AccountQuery)) *UserQuery { + query := (&AccountClient{config: uq.config}).Query() + for _, opt := range opts { + opt(query) + } + uq.withAccounts = 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. // @@ -331,8 +368,11 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error { func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) { var ( - nodes = []*User{} - _spec = uq.querySpec() + nodes = []*User{} + _spec = uq.querySpec() + loadedTypes = [1]bool{ + uq.withAccounts != nil, + } ) _spec.ScanValues = func(columns []string) ([]any, error) { return (*User).scanValues(nil, columns) @@ -340,6 +380,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e _spec.Assign = func(columns []string, values []any) error { node := &User{config: uq.config} nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } for i := range hooks { @@ -351,9 +392,48 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e if len(nodes) == 0 { return nodes, nil } + if query := uq.withAccounts; query != nil { + if err := uq.loadAccounts(ctx, query, nodes, + func(n *User) { n.Edges.Accounts = []*Account{} }, + func(n *User, e *Account) { n.Edges.Accounts = append(n.Edges.Accounts, e) }); err != nil { + return nil, err + } + } return nodes, nil } +func (uq *UserQuery) loadAccounts(ctx context.Context, query *AccountQuery, nodes []*User, init func(*User), assign func(*User, *Account)) 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.Account(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(user.AccountsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.user_accounts + if fk == nil { + return fmt.Errorf(`foreign-key "user_accounts" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "user_accounts" 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() _spec.Node.Columns = uq.ctx.Fields diff --git a/entproto/internal/altdir/ent/user_update.go b/entproto/internal/altdir/ent/user_update.go index 4d5849a75..200c53c38 100644 --- a/entproto/internal/altdir/ent/user_update.go +++ b/entproto/internal/altdir/ent/user_update.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" + "entgo.io/contrib/entproto/internal/altdir/ent/account" "entgo.io/contrib/entproto/internal/altdir/ent/predicate" "entgo.io/contrib/entproto/internal/altdir/ent/user" "entgo.io/ent/dialect/sql" @@ -41,11 +42,47 @@ func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { return uu } +// AddAccountIDs adds the "accounts" edge to the Account entity by IDs. +func (uu *UserUpdate) AddAccountIDs(ids ...int) *UserUpdate { + uu.mutation.AddAccountIDs(ids...) + return uu +} + +// AddAccounts adds the "accounts" edges to the Account entity. +func (uu *UserUpdate) AddAccounts(a ...*Account) *UserUpdate { + ids := make([]int, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return uu.AddAccountIDs(ids...) +} + // Mutation returns the UserMutation object of the builder. func (uu *UserUpdate) Mutation() *UserMutation { return uu.mutation } +// ClearAccounts clears all "accounts" edges to the Account entity. +func (uu *UserUpdate) ClearAccounts() *UserUpdate { + uu.mutation.ClearAccounts() + return uu +} + +// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs. +func (uu *UserUpdate) RemoveAccountIDs(ids ...int) *UserUpdate { + uu.mutation.RemoveAccountIDs(ids...) + return uu +} + +// RemoveAccounts removes "accounts" edges to Account entities. +func (uu *UserUpdate) RemoveAccounts(a ...*Account) *UserUpdate { + ids := make([]int, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return uu.RemoveAccountIDs(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(ctx, uu.sqlSave, uu.mutation, uu.hooks) @@ -85,6 +122,51 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := uu.mutation.Name(); ok { _spec.SetField(user.FieldName, field.TypeString, value) } + if uu.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uu.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !uu.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.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.AccountsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.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} @@ -119,11 +201,47 @@ func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { return uuo } +// AddAccountIDs adds the "accounts" edge to the Account entity by IDs. +func (uuo *UserUpdateOne) AddAccountIDs(ids ...int) *UserUpdateOne { + uuo.mutation.AddAccountIDs(ids...) + return uuo +} + +// AddAccounts adds the "accounts" edges to the Account entity. +func (uuo *UserUpdateOne) AddAccounts(a ...*Account) *UserUpdateOne { + ids := make([]int, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return uuo.AddAccountIDs(ids...) +} + // Mutation returns the UserMutation object of the builder. func (uuo *UserUpdateOne) Mutation() *UserMutation { return uuo.mutation } +// ClearAccounts clears all "accounts" edges to the Account entity. +func (uuo *UserUpdateOne) ClearAccounts() *UserUpdateOne { + uuo.mutation.ClearAccounts() + return uuo +} + +// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs. +func (uuo *UserUpdateOne) RemoveAccountIDs(ids ...int) *UserUpdateOne { + uuo.mutation.RemoveAccountIDs(ids...) + return uuo +} + +// RemoveAccounts removes "accounts" edges to Account entities. +func (uuo *UserUpdateOne) RemoveAccounts(a ...*Account) *UserUpdateOne { + ids := make([]int, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return uuo.RemoveAccountIDs(ids...) +} + // Where appends a list predicates to the UserUpdate builder. func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne { uuo.mutation.Where(ps...) @@ -193,6 +311,51 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) if value, ok := uuo.mutation.Name(); ok { _spec.SetField(user.FieldName, field.TypeString, value) } + if uuo.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uuo.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !uuo.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.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.AccountsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.AccountsTable, + Columns: []string{user.AccountsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &User{config: uuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/entproto/internal/altdir/ent/v1/api/entpb/entpb.pb.go b/entproto/internal/altdir/ent/v1/api/entpb/entpb.pb.go index 8097aedba..53eacb16f 100644 --- a/entproto/internal/altdir/ent/v1/api/entpb/entpb.pb.go +++ b/entproto/internal/altdir/ent/v1/api/entpb/entpb.pb.go @@ -23,6 +23,104 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type GetAccountRequest_View int32 + +const ( + GetAccountRequest_VIEW_UNSPECIFIED GetAccountRequest_View = 0 + GetAccountRequest_BASIC GetAccountRequest_View = 1 + GetAccountRequest_WITH_EDGE_IDS GetAccountRequest_View = 2 +) + +// Enum value maps for GetAccountRequest_View. +var ( + GetAccountRequest_View_name = map[int32]string{ + 0: "VIEW_UNSPECIFIED", + 1: "BASIC", + 2: "WITH_EDGE_IDS", + } + GetAccountRequest_View_value = map[string]int32{ + "VIEW_UNSPECIFIED": 0, + "BASIC": 1, + "WITH_EDGE_IDS": 2, + } +) + +func (x GetAccountRequest_View) Enum() *GetAccountRequest_View { + p := new(GetAccountRequest_View) + *p = x + return p +} + +func (x GetAccountRequest_View) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (GetAccountRequest_View) Descriptor() protoreflect.EnumDescriptor { + return file_entpb_entpb_proto_enumTypes[0].Descriptor() +} + +func (GetAccountRequest_View) Type() protoreflect.EnumType { + return &file_entpb_entpb_proto_enumTypes[0] +} + +func (x GetAccountRequest_View) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use GetAccountRequest_View.Descriptor instead. +func (GetAccountRequest_View) EnumDescriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{2, 0} +} + +type ListAccountRequest_View int32 + +const ( + ListAccountRequest_VIEW_UNSPECIFIED ListAccountRequest_View = 0 + ListAccountRequest_BASIC ListAccountRequest_View = 1 + ListAccountRequest_WITH_EDGE_IDS ListAccountRequest_View = 2 +) + +// Enum value maps for ListAccountRequest_View. +var ( + ListAccountRequest_View_name = map[int32]string{ + 0: "VIEW_UNSPECIFIED", + 1: "BASIC", + 2: "WITH_EDGE_IDS", + } + ListAccountRequest_View_value = map[string]int32{ + "VIEW_UNSPECIFIED": 0, + "BASIC": 1, + "WITH_EDGE_IDS": 2, + } +) + +func (x ListAccountRequest_View) Enum() *ListAccountRequest_View { + p := new(ListAccountRequest_View) + *p = x + return p +} + +func (x ListAccountRequest_View) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ListAccountRequest_View) Descriptor() protoreflect.EnumDescriptor { + return file_entpb_entpb_proto_enumTypes[1].Descriptor() +} + +func (ListAccountRequest_View) Type() protoreflect.EnumType { + return &file_entpb_entpb_proto_enumTypes[1] +} + +func (x ListAccountRequest_View) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ListAccountRequest_View.Descriptor instead. +func (ListAccountRequest_View) EnumDescriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{5, 0} +} + type GetUserRequest_View int32 const ( @@ -45,80 +143,543 @@ var ( } ) -func (x GetUserRequest_View) Enum() *GetUserRequest_View { - p := new(GetUserRequest_View) - *p = x - return p +func (x GetUserRequest_View) Enum() *GetUserRequest_View { + p := new(GetUserRequest_View) + *p = x + return p +} + +func (x GetUserRequest_View) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (GetUserRequest_View) Descriptor() protoreflect.EnumDescriptor { + return file_entpb_entpb_proto_enumTypes[2].Descriptor() +} + +func (GetUserRequest_View) Type() protoreflect.EnumType { + return &file_entpb_entpb_proto_enumTypes[2] +} + +func (x GetUserRequest_View) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use GetUserRequest_View.Descriptor instead. +func (GetUserRequest_View) EnumDescriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{11, 0} +} + +type ListUserRequest_View int32 + +const ( + ListUserRequest_VIEW_UNSPECIFIED ListUserRequest_View = 0 + ListUserRequest_BASIC ListUserRequest_View = 1 + ListUserRequest_WITH_EDGE_IDS ListUserRequest_View = 2 +) + +// Enum value maps for ListUserRequest_View. +var ( + ListUserRequest_View_name = map[int32]string{ + 0: "VIEW_UNSPECIFIED", + 1: "BASIC", + 2: "WITH_EDGE_IDS", + } + ListUserRequest_View_value = map[string]int32{ + "VIEW_UNSPECIFIED": 0, + "BASIC": 1, + "WITH_EDGE_IDS": 2, + } +) + +func (x ListUserRequest_View) Enum() *ListUserRequest_View { + p := new(ListUserRequest_View) + *p = x + return p +} + +func (x ListUserRequest_View) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ListUserRequest_View) Descriptor() protoreflect.EnumDescriptor { + return file_entpb_entpb_proto_enumTypes[3].Descriptor() +} + +func (ListUserRequest_View) Type() protoreflect.EnumType { + return &file_entpb_entpb_proto_enumTypes[3] +} + +func (x ListUserRequest_View) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ListUserRequest_View.Descriptor instead. +func (ListUserRequest_View) EnumDescriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{14, 0} +} + +type Account struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Owner *User `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"` +} + +func (x *Account) Reset() { + *x = Account{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Account) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Account) ProtoMessage() {} + +func (x *Account) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Account.ProtoReflect.Descriptor instead. +func (*Account) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{0} +} + +func (x *Account) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *Account) GetOwner() *User { + if x != nil { + return x.Owner + } + return nil +} + +type CreateAccountRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` +} + +func (x *CreateAccountRequest) Reset() { + *x = CreateAccountRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateAccountRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateAccountRequest) ProtoMessage() {} + +func (x *CreateAccountRequest) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateAccountRequest.ProtoReflect.Descriptor instead. +func (*CreateAccountRequest) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateAccountRequest) GetAccount() *Account { + if x != nil { + return x.Account + } + return nil +} + +type GetAccountRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + View GetAccountRequest_View `protobuf:"varint,2,opt,name=view,proto3,enum=entpb.GetAccountRequest_View" json:"view,omitempty"` +} + +func (x *GetAccountRequest) Reset() { + *x = GetAccountRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetAccountRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetAccountRequest) ProtoMessage() {} + +func (x *GetAccountRequest) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetAccountRequest.ProtoReflect.Descriptor instead. +func (*GetAccountRequest) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{2} +} + +func (x *GetAccountRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *GetAccountRequest) GetView() GetAccountRequest_View { + if x != nil { + return x.View + } + return GetAccountRequest_VIEW_UNSPECIFIED +} + +type UpdateAccountRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` +} + +func (x *UpdateAccountRequest) Reset() { + *x = UpdateAccountRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateAccountRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateAccountRequest) ProtoMessage() {} + +func (x *UpdateAccountRequest) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateAccountRequest.ProtoReflect.Descriptor instead. +func (*UpdateAccountRequest) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{3} +} + +func (x *UpdateAccountRequest) GetAccount() *Account { + if x != nil { + return x.Account + } + return nil +} + +type DeleteAccountRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *DeleteAccountRequest) Reset() { + *x = DeleteAccountRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteAccountRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteAccountRequest) ProtoMessage() {} + +func (x *DeleteAccountRequest) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteAccountRequest.ProtoReflect.Descriptor instead. +func (*DeleteAccountRequest) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{4} +} + +func (x *DeleteAccountRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type ListAccountRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int32 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` + PageToken string `protobuf:"bytes,2,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"` + View ListAccountRequest_View `protobuf:"varint,3,opt,name=view,proto3,enum=entpb.ListAccountRequest_View" json:"view,omitempty"` +} + +func (x *ListAccountRequest) Reset() { + *x = ListAccountRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListAccountRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListAccountRequest) ProtoMessage() {} + +func (x *ListAccountRequest) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListAccountRequest.ProtoReflect.Descriptor instead. +func (*ListAccountRequest) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{5} +} + +func (x *ListAccountRequest) GetPageSize() int32 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *ListAccountRequest) GetPageToken() string { + if x != nil { + return x.PageToken + } + return "" +} + +func (x *ListAccountRequest) GetView() ListAccountRequest_View { + if x != nil { + return x.View + } + return ListAccountRequest_VIEW_UNSPECIFIED +} + +type ListAccountResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + AccountList []*Account `protobuf:"bytes,1,rep,name=account_list,json=accountList,proto3" json:"account_list,omitempty"` + NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"` +} + +func (x *ListAccountResponse) Reset() { + *x = ListAccountResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListAccountResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListAccountResponse) ProtoMessage() {} + +func (x *ListAccountResponse) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (x GetUserRequest_View) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +// Deprecated: Use ListAccountResponse.ProtoReflect.Descriptor instead. +func (*ListAccountResponse) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{6} } -func (GetUserRequest_View) Descriptor() protoreflect.EnumDescriptor { - return file_entpb_entpb_proto_enumTypes[0].Descriptor() +func (x *ListAccountResponse) GetAccountList() []*Account { + if x != nil { + return x.AccountList + } + return nil } -func (GetUserRequest_View) Type() protoreflect.EnumType { - return &file_entpb_entpb_proto_enumTypes[0] +func (x *ListAccountResponse) GetNextPageToken() string { + if x != nil { + return x.NextPageToken + } + return "" } -func (x GetUserRequest_View) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) +type BatchCreateAccountsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Requests []*CreateAccountRequest `protobuf:"bytes,1,rep,name=requests,proto3" json:"requests,omitempty"` } -// Deprecated: Use GetUserRequest_View.Descriptor instead. -func (GetUserRequest_View) EnumDescriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{2, 0} +func (x *BatchCreateAccountsRequest) Reset() { + *x = BatchCreateAccountsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -type ListUserRequest_View int32 +func (x *BatchCreateAccountsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} -const ( - ListUserRequest_VIEW_UNSPECIFIED ListUserRequest_View = 0 - ListUserRequest_BASIC ListUserRequest_View = 1 - ListUserRequest_WITH_EDGE_IDS ListUserRequest_View = 2 -) +func (*BatchCreateAccountsRequest) ProtoMessage() {} -// Enum value maps for ListUserRequest_View. -var ( - ListUserRequest_View_name = map[int32]string{ - 0: "VIEW_UNSPECIFIED", - 1: "BASIC", - 2: "WITH_EDGE_IDS", +func (x *BatchCreateAccountsRequest) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms } - ListUserRequest_View_value = map[string]int32{ - "VIEW_UNSPECIFIED": 0, - "BASIC": 1, - "WITH_EDGE_IDS": 2, + return mi.MessageOf(x) +} + +// Deprecated: Use BatchCreateAccountsRequest.ProtoReflect.Descriptor instead. +func (*BatchCreateAccountsRequest) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{7} +} + +func (x *BatchCreateAccountsRequest) GetRequests() []*CreateAccountRequest { + if x != nil { + return x.Requests } -) + return nil +} -func (x ListUserRequest_View) Enum() *ListUserRequest_View { - p := new(ListUserRequest_View) - *p = x - return p +type BatchCreateAccountsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` } -func (x ListUserRequest_View) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +func (x *BatchCreateAccountsResponse) Reset() { + *x = BatchCreateAccountsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_entpb_entpb_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (ListUserRequest_View) Descriptor() protoreflect.EnumDescriptor { - return file_entpb_entpb_proto_enumTypes[1].Descriptor() +func (x *BatchCreateAccountsResponse) String() string { + return protoimpl.X.MessageStringOf(x) } -func (ListUserRequest_View) Type() protoreflect.EnumType { - return &file_entpb_entpb_proto_enumTypes[1] +func (*BatchCreateAccountsResponse) ProtoMessage() {} + +func (x *BatchCreateAccountsResponse) ProtoReflect() protoreflect.Message { + mi := &file_entpb_entpb_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (x ListUserRequest_View) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) +// Deprecated: Use BatchCreateAccountsResponse.ProtoReflect.Descriptor instead. +func (*BatchCreateAccountsResponse) Descriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{8} } -// Deprecated: Use ListUserRequest_View.Descriptor instead. -func (ListUserRequest_View) EnumDescriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{5, 0} +func (x *BatchCreateAccountsResponse) GetAccounts() []*Account { + if x != nil { + return x.Accounts + } + return nil } type User struct { @@ -133,7 +694,7 @@ type User struct { func (x *User) Reset() { *x = User{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[0] + mi := &file_entpb_entpb_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -146,7 +707,7 @@ func (x *User) String() string { func (*User) ProtoMessage() {} func (x *User) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[0] + mi := &file_entpb_entpb_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -159,7 +720,7 @@ func (x *User) ProtoReflect() protoreflect.Message { // Deprecated: Use User.ProtoReflect.Descriptor instead. func (*User) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{0} + return file_entpb_entpb_proto_rawDescGZIP(), []int{9} } func (x *User) GetId() int64 { @@ -187,7 +748,7 @@ type CreateUserRequest struct { func (x *CreateUserRequest) Reset() { *x = CreateUserRequest{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[1] + mi := &file_entpb_entpb_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -200,7 +761,7 @@ func (x *CreateUserRequest) String() string { func (*CreateUserRequest) ProtoMessage() {} func (x *CreateUserRequest) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[1] + mi := &file_entpb_entpb_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -213,7 +774,7 @@ func (x *CreateUserRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateUserRequest.ProtoReflect.Descriptor instead. func (*CreateUserRequest) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{1} + return file_entpb_entpb_proto_rawDescGZIP(), []int{10} } func (x *CreateUserRequest) GetUser() *User { @@ -235,7 +796,7 @@ type GetUserRequest struct { func (x *GetUserRequest) Reset() { *x = GetUserRequest{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[2] + mi := &file_entpb_entpb_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -248,7 +809,7 @@ func (x *GetUserRequest) String() string { func (*GetUserRequest) ProtoMessage() {} func (x *GetUserRequest) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[2] + mi := &file_entpb_entpb_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -261,7 +822,7 @@ func (x *GetUserRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetUserRequest.ProtoReflect.Descriptor instead. func (*GetUserRequest) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{2} + return file_entpb_entpb_proto_rawDescGZIP(), []int{11} } func (x *GetUserRequest) GetId() int64 { @@ -289,7 +850,7 @@ type UpdateUserRequest struct { func (x *UpdateUserRequest) Reset() { *x = UpdateUserRequest{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[3] + mi := &file_entpb_entpb_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -302,7 +863,7 @@ func (x *UpdateUserRequest) String() string { func (*UpdateUserRequest) ProtoMessage() {} func (x *UpdateUserRequest) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[3] + mi := &file_entpb_entpb_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -315,7 +876,7 @@ func (x *UpdateUserRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateUserRequest.ProtoReflect.Descriptor instead. func (*UpdateUserRequest) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{3} + return file_entpb_entpb_proto_rawDescGZIP(), []int{12} } func (x *UpdateUserRequest) GetUser() *User { @@ -336,7 +897,7 @@ type DeleteUserRequest struct { func (x *DeleteUserRequest) Reset() { *x = DeleteUserRequest{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[4] + mi := &file_entpb_entpb_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -349,7 +910,7 @@ func (x *DeleteUserRequest) String() string { func (*DeleteUserRequest) ProtoMessage() {} func (x *DeleteUserRequest) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[4] + mi := &file_entpb_entpb_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -362,7 +923,7 @@ func (x *DeleteUserRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteUserRequest.ProtoReflect.Descriptor instead. func (*DeleteUserRequest) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{4} + return file_entpb_entpb_proto_rawDescGZIP(), []int{13} } func (x *DeleteUserRequest) GetId() int64 { @@ -385,7 +946,7 @@ type ListUserRequest struct { func (x *ListUserRequest) Reset() { *x = ListUserRequest{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[5] + mi := &file_entpb_entpb_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -398,7 +959,7 @@ func (x *ListUserRequest) String() string { func (*ListUserRequest) ProtoMessage() {} func (x *ListUserRequest) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[5] + mi := &file_entpb_entpb_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -411,7 +972,7 @@ func (x *ListUserRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListUserRequest.ProtoReflect.Descriptor instead. func (*ListUserRequest) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{5} + return file_entpb_entpb_proto_rawDescGZIP(), []int{14} } func (x *ListUserRequest) GetPageSize() int32 { @@ -447,7 +1008,7 @@ type ListUserResponse struct { func (x *ListUserResponse) Reset() { *x = ListUserResponse{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[6] + mi := &file_entpb_entpb_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -460,7 +1021,7 @@ func (x *ListUserResponse) String() string { func (*ListUserResponse) ProtoMessage() {} func (x *ListUserResponse) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[6] + mi := &file_entpb_entpb_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -473,7 +1034,7 @@ func (x *ListUserResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListUserResponse.ProtoReflect.Descriptor instead. func (*ListUserResponse) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{6} + return file_entpb_entpb_proto_rawDescGZIP(), []int{15} } func (x *ListUserResponse) GetUserList() []*User { @@ -501,7 +1062,7 @@ type BatchCreateUsersRequest struct { func (x *BatchCreateUsersRequest) Reset() { *x = BatchCreateUsersRequest{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[7] + mi := &file_entpb_entpb_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -514,7 +1075,7 @@ func (x *BatchCreateUsersRequest) String() string { func (*BatchCreateUsersRequest) ProtoMessage() {} func (x *BatchCreateUsersRequest) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[7] + mi := &file_entpb_entpb_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -527,7 +1088,7 @@ func (x *BatchCreateUsersRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BatchCreateUsersRequest.ProtoReflect.Descriptor instead. func (*BatchCreateUsersRequest) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{7} + return file_entpb_entpb_proto_rawDescGZIP(), []int{16} } func (x *BatchCreateUsersRequest) GetRequests() []*CreateUserRequest { @@ -548,7 +1109,7 @@ type BatchCreateUsersResponse struct { func (x *BatchCreateUsersResponse) Reset() { *x = BatchCreateUsersResponse{} if protoimpl.UnsafeEnabled { - mi := &file_entpb_entpb_proto_msgTypes[8] + mi := &file_entpb_entpb_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -561,7 +1122,7 @@ func (x *BatchCreateUsersResponse) String() string { func (*BatchCreateUsersResponse) ProtoMessage() {} func (x *BatchCreateUsersResponse) ProtoReflect() protoreflect.Message { - mi := &file_entpb_entpb_proto_msgTypes[8] + mi := &file_entpb_entpb_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -574,7 +1135,7 @@ func (x *BatchCreateUsersResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use BatchCreateUsersResponse.ProtoReflect.Descriptor instead. func (*BatchCreateUsersResponse) Descriptor() ([]byte, []int) { - return file_entpb_entpb_proto_rawDescGZIP(), []int{8} + return file_entpb_entpb_proto_rawDescGZIP(), []int{17} } func (x *BatchCreateUsersResponse) GetUsers() []*User { @@ -590,81 +1151,159 @@ var file_entpb_entpb_proto_rawDesc = []byte{ 0x0a, 0x11, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2f, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2a, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x22, 0x34, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, - 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, - 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x8c, 0x01, 0x0a, 0x0e, 0x47, 0x65, - 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x2e, 0x0a, 0x04, - 0x76, 0x69, 0x65, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1a, 0x2e, 0x65, 0x6e, 0x74, - 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x22, 0x3a, 0x0a, 0x04, - 0x56, 0x69, 0x65, 0x77, 0x12, 0x14, 0x0a, 0x10, 0x56, 0x49, 0x45, 0x57, 0x5f, 0x55, 0x4e, 0x53, - 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x42, 0x41, - 0x53, 0x49, 0x43, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x57, 0x49, 0x54, 0x48, 0x5f, 0x45, 0x44, - 0x47, 0x45, 0x5f, 0x49, 0x44, 0x53, 0x10, 0x02, 0x22, 0x34, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, - 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, - 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x23, - 0x0a, 0x11, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x02, 0x69, 0x64, 0x22, 0xba, 0x01, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, - 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, - 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x54, 0x6f, - 0x6b, 0x65, 0x6e, 0x12, 0x2f, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x1b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, - 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, - 0x76, 0x69, 0x65, 0x77, 0x22, 0x3a, 0x0a, 0x04, 0x56, 0x69, 0x65, 0x77, 0x12, 0x14, 0x0a, 0x10, - 0x56, 0x49, 0x45, 0x57, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, - 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x42, 0x41, 0x53, 0x49, 0x43, 0x10, 0x01, 0x12, 0x11, 0x0a, - 0x0d, 0x57, 0x49, 0x54, 0x48, 0x5f, 0x45, 0x44, 0x47, 0x45, 0x5f, 0x49, 0x44, 0x53, 0x10, 0x02, - 0x22, 0x64, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6c, 0x69, 0x73, - 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, - 0x55, 0x73, 0x65, 0x72, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, - 0x0a, 0x0f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x65, 0x78, 0x74, 0x50, 0x61, 0x67, - 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x4f, 0x0a, 0x17, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x34, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x08, 0x72, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x22, 0x3d, 0x0a, 0x18, 0x42, 0x61, 0x74, 0x63, 0x68, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, - 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x32, 0xdf, 0x02, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x12, 0x18, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, - 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x65, 0x6e, 0x74, - 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x29, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x15, - 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, - 0x65, 0x72, 0x12, 0x2f, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x65, - 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, - 0x73, 0x65, 0x72, 0x12, 0x3a, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x18, 0x2e, - 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, - 0x37, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, - 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x17, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4e, 0x0a, 0x0b, 0x42, 0x61, 0x74, 0x63, - 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x1e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, - 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, + 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3c, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x21, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, + 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x40, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, + 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, + 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x07, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x92, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x31, 0x0a, + 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1d, 0x2e, 0x65, 0x6e, + 0x74, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, + 0x22, 0x3a, 0x0a, 0x04, 0x56, 0x69, 0x65, 0x77, 0x12, 0x14, 0x0a, 0x10, 0x56, 0x49, 0x45, 0x57, + 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, + 0x0a, 0x05, 0x42, 0x41, 0x53, 0x49, 0x43, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x57, 0x49, 0x54, + 0x48, 0x5f, 0x45, 0x44, 0x47, 0x45, 0x5f, 0x49, 0x44, 0x53, 0x10, 0x02, 0x22, 0x40, 0x0a, 0x14, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x26, + 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0xc0, 0x01, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, + 0x67, 0x65, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x70, 0x61, 0x67, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x32, 0x0a, 0x04, 0x76, 0x69, 0x65, + 0x77, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x22, 0x3a, 0x0a, + 0x04, 0x56, 0x69, 0x65, 0x77, 0x12, 0x14, 0x0a, 0x10, 0x56, 0x49, 0x45, 0x57, 0x5f, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x42, + 0x41, 0x53, 0x49, 0x43, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x57, 0x49, 0x54, 0x48, 0x5f, 0x45, + 0x44, 0x47, 0x45, 0x5f, 0x49, 0x44, 0x53, 0x10, 0x02, 0x22, 0x70, 0x0a, 0x13, 0x4c, 0x69, 0x73, + 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x31, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6c, 0x69, 0x73, 0x74, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4c, + 0x69, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x70, 0x61, 0x67, 0x65, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x65, + 0x78, 0x74, 0x50, 0x61, 0x67, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x55, 0x0a, 0x1a, 0x42, + 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x37, 0x0a, 0x08, 0x72, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x65, 0x6e, + 0x74, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x73, 0x22, 0x49, 0x0a, 0x1b, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x2a, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x2a, 0x0a, + 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x34, 0x0a, 0x11, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, + 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, + 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, + 0x8c, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x2e, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x1a, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, + 0x65, 0x77, 0x22, 0x3a, 0x0a, 0x04, 0x56, 0x69, 0x65, 0x77, 0x12, 0x14, 0x0a, 0x10, 0x56, 0x49, + 0x45, 0x57, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, + 0x12, 0x09, 0x0a, 0x05, 0x42, 0x41, 0x53, 0x49, 0x43, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x57, + 0x49, 0x54, 0x48, 0x5f, 0x45, 0x44, 0x47, 0x45, 0x5f, 0x49, 0x44, 0x53, 0x10, 0x02, 0x22, 0x34, + 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, + 0x75, 0x73, 0x65, 0x72, 0x22, 0x23, 0x0a, 0x11, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0xba, 0x01, 0x0a, 0x0f, 0x4c, 0x69, + 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, + 0x67, 0x65, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x70, 0x61, 0x67, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x2f, 0x0a, 0x04, 0x76, 0x69, 0x65, + 0x77, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, + 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x22, 0x3a, 0x0a, 0x04, 0x56, 0x69, + 0x65, 0x77, 0x12, 0x14, 0x0a, 0x10, 0x56, 0x49, 0x45, 0x57, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, + 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x42, 0x41, 0x53, 0x49, + 0x43, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x57, 0x49, 0x54, 0x48, 0x5f, 0x45, 0x44, 0x47, 0x45, + 0x5f, 0x49, 0x44, 0x53, 0x10, 0x02, 0x22, 0x64, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, + 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x09, 0x75, 0x73, + 0x65, 0x72, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, + 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, + 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x70, 0x61, 0x67, + 0x65, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, + 0x65, 0x78, 0x74, 0x50, 0x61, 0x67, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x4f, 0x0a, 0x17, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3b, 0x5a, 0x39, 0x65, 0x6e, 0x74, 0x67, - 0x6f, 0x2e, 0x69, 0x6f, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x2f, 0x65, 0x6e, 0x74, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x61, - 0x6c, 0x74, 0x64, 0x69, 0x72, 0x2f, 0x65, 0x6e, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x65, 0x6e, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x34, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x65, 0x6e, 0x74, 0x70, + 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x22, 0x3d, 0x0a, + 0x18, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, + 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x32, 0x83, 0x03, 0x0a, + 0x0e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x65, 0x6e, 0x74, 0x70, + 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x18, 0x2e, + 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x35, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x12, 0x1b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, + 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x3d, + 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, + 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3d, 0x0a, + 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x19, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x4c, 0x69, + 0x73, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1a, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x0b, + 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x21, 0x2e, 0x65, 0x6e, + 0x74, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, + 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x32, 0xdf, 0x02, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x65, + 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, + 0x73, 0x65, 0x72, 0x12, 0x29, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x15, 0x2e, 0x65, 0x6e, 0x74, + 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x2f, + 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, + 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x12, + 0x3a, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x65, 0x6e, 0x74, 0x70, + 0x62, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x37, 0x0a, 0x04, 0x4c, + 0x69, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x65, 0x6e, + 0x74, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4e, 0x0a, 0x0b, 0x42, 0x61, 0x74, 0x63, 0x68, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x12, 0x1e, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x74, 0x63, + 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x74, 0x63, + 0x68, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3b, 0x5a, 0x39, 0x65, 0x6e, 0x74, 0x67, 0x6f, 0x2e, 0x69, 0x6f, + 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x2f, 0x65, 0x6e, 0x74, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x61, 0x6c, 0x74, 0x64, 0x69, + 0x72, 0x2f, 0x65, 0x6e, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x6e, 0x74, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -679,47 +1318,78 @@ func file_entpb_entpb_proto_rawDescGZIP() []byte { return file_entpb_entpb_proto_rawDescData } -var file_entpb_entpb_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_entpb_entpb_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_entpb_entpb_proto_enumTypes = make([]protoimpl.EnumInfo, 4) +var file_entpb_entpb_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_entpb_entpb_proto_goTypes = []interface{}{ - (GetUserRequest_View)(0), // 0: entpb.GetUserRequest.View - (ListUserRequest_View)(0), // 1: entpb.ListUserRequest.View - (*User)(nil), // 2: entpb.User - (*CreateUserRequest)(nil), // 3: entpb.CreateUserRequest - (*GetUserRequest)(nil), // 4: entpb.GetUserRequest - (*UpdateUserRequest)(nil), // 5: entpb.UpdateUserRequest - (*DeleteUserRequest)(nil), // 6: entpb.DeleteUserRequest - (*ListUserRequest)(nil), // 7: entpb.ListUserRequest - (*ListUserResponse)(nil), // 8: entpb.ListUserResponse - (*BatchCreateUsersRequest)(nil), // 9: entpb.BatchCreateUsersRequest - (*BatchCreateUsersResponse)(nil), // 10: entpb.BatchCreateUsersResponse - (*emptypb.Empty)(nil), // 11: google.protobuf.Empty + (GetAccountRequest_View)(0), // 0: entpb.GetAccountRequest.View + (ListAccountRequest_View)(0), // 1: entpb.ListAccountRequest.View + (GetUserRequest_View)(0), // 2: entpb.GetUserRequest.View + (ListUserRequest_View)(0), // 3: entpb.ListUserRequest.View + (*Account)(nil), // 4: entpb.Account + (*CreateAccountRequest)(nil), // 5: entpb.CreateAccountRequest + (*GetAccountRequest)(nil), // 6: entpb.GetAccountRequest + (*UpdateAccountRequest)(nil), // 7: entpb.UpdateAccountRequest + (*DeleteAccountRequest)(nil), // 8: entpb.DeleteAccountRequest + (*ListAccountRequest)(nil), // 9: entpb.ListAccountRequest + (*ListAccountResponse)(nil), // 10: entpb.ListAccountResponse + (*BatchCreateAccountsRequest)(nil), // 11: entpb.BatchCreateAccountsRequest + (*BatchCreateAccountsResponse)(nil), // 12: entpb.BatchCreateAccountsResponse + (*User)(nil), // 13: entpb.User + (*CreateUserRequest)(nil), // 14: entpb.CreateUserRequest + (*GetUserRequest)(nil), // 15: entpb.GetUserRequest + (*UpdateUserRequest)(nil), // 16: entpb.UpdateUserRequest + (*DeleteUserRequest)(nil), // 17: entpb.DeleteUserRequest + (*ListUserRequest)(nil), // 18: entpb.ListUserRequest + (*ListUserResponse)(nil), // 19: entpb.ListUserResponse + (*BatchCreateUsersRequest)(nil), // 20: entpb.BatchCreateUsersRequest + (*BatchCreateUsersResponse)(nil), // 21: entpb.BatchCreateUsersResponse + (*emptypb.Empty)(nil), // 22: google.protobuf.Empty } var file_entpb_entpb_proto_depIdxs = []int32{ - 2, // 0: entpb.CreateUserRequest.user:type_name -> entpb.User - 0, // 1: entpb.GetUserRequest.view:type_name -> entpb.GetUserRequest.View - 2, // 2: entpb.UpdateUserRequest.user:type_name -> entpb.User - 1, // 3: entpb.ListUserRequest.view:type_name -> entpb.ListUserRequest.View - 2, // 4: entpb.ListUserResponse.user_list:type_name -> entpb.User - 3, // 5: entpb.BatchCreateUsersRequest.requests:type_name -> entpb.CreateUserRequest - 2, // 6: entpb.BatchCreateUsersResponse.users:type_name -> entpb.User - 3, // 7: entpb.UserService.Create:input_type -> entpb.CreateUserRequest - 4, // 8: entpb.UserService.Get:input_type -> entpb.GetUserRequest - 5, // 9: entpb.UserService.Update:input_type -> entpb.UpdateUserRequest - 6, // 10: entpb.UserService.Delete:input_type -> entpb.DeleteUserRequest - 7, // 11: entpb.UserService.List:input_type -> entpb.ListUserRequest - 9, // 12: entpb.UserService.BatchCreate:input_type -> entpb.BatchCreateUsersRequest - 2, // 13: entpb.UserService.Create:output_type -> entpb.User - 2, // 14: entpb.UserService.Get:output_type -> entpb.User - 2, // 15: entpb.UserService.Update:output_type -> entpb.User - 11, // 16: entpb.UserService.Delete:output_type -> google.protobuf.Empty - 8, // 17: entpb.UserService.List:output_type -> entpb.ListUserResponse - 10, // 18: entpb.UserService.BatchCreate:output_type -> entpb.BatchCreateUsersResponse - 13, // [13:19] is the sub-list for method output_type - 7, // [7:13] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 13, // 0: entpb.Account.owner:type_name -> entpb.User + 4, // 1: entpb.CreateAccountRequest.account:type_name -> entpb.Account + 0, // 2: entpb.GetAccountRequest.view:type_name -> entpb.GetAccountRequest.View + 4, // 3: entpb.UpdateAccountRequest.account:type_name -> entpb.Account + 1, // 4: entpb.ListAccountRequest.view:type_name -> entpb.ListAccountRequest.View + 4, // 5: entpb.ListAccountResponse.account_list:type_name -> entpb.Account + 5, // 6: entpb.BatchCreateAccountsRequest.requests:type_name -> entpb.CreateAccountRequest + 4, // 7: entpb.BatchCreateAccountsResponse.accounts:type_name -> entpb.Account + 13, // 8: entpb.CreateUserRequest.user:type_name -> entpb.User + 2, // 9: entpb.GetUserRequest.view:type_name -> entpb.GetUserRequest.View + 13, // 10: entpb.UpdateUserRequest.user:type_name -> entpb.User + 3, // 11: entpb.ListUserRequest.view:type_name -> entpb.ListUserRequest.View + 13, // 12: entpb.ListUserResponse.user_list:type_name -> entpb.User + 14, // 13: entpb.BatchCreateUsersRequest.requests:type_name -> entpb.CreateUserRequest + 13, // 14: entpb.BatchCreateUsersResponse.users:type_name -> entpb.User + 5, // 15: entpb.AccountService.Create:input_type -> entpb.CreateAccountRequest + 6, // 16: entpb.AccountService.Get:input_type -> entpb.GetAccountRequest + 7, // 17: entpb.AccountService.Update:input_type -> entpb.UpdateAccountRequest + 8, // 18: entpb.AccountService.Delete:input_type -> entpb.DeleteAccountRequest + 9, // 19: entpb.AccountService.List:input_type -> entpb.ListAccountRequest + 11, // 20: entpb.AccountService.BatchCreate:input_type -> entpb.BatchCreateAccountsRequest + 14, // 21: entpb.UserService.Create:input_type -> entpb.CreateUserRequest + 15, // 22: entpb.UserService.Get:input_type -> entpb.GetUserRequest + 16, // 23: entpb.UserService.Update:input_type -> entpb.UpdateUserRequest + 17, // 24: entpb.UserService.Delete:input_type -> entpb.DeleteUserRequest + 18, // 25: entpb.UserService.List:input_type -> entpb.ListUserRequest + 20, // 26: entpb.UserService.BatchCreate:input_type -> entpb.BatchCreateUsersRequest + 4, // 27: entpb.AccountService.Create:output_type -> entpb.Account + 4, // 28: entpb.AccountService.Get:output_type -> entpb.Account + 4, // 29: entpb.AccountService.Update:output_type -> entpb.Account + 22, // 30: entpb.AccountService.Delete:output_type -> google.protobuf.Empty + 10, // 31: entpb.AccountService.List:output_type -> entpb.ListAccountResponse + 12, // 32: entpb.AccountService.BatchCreate:output_type -> entpb.BatchCreateAccountsResponse + 13, // 33: entpb.UserService.Create:output_type -> entpb.User + 13, // 34: entpb.UserService.Get:output_type -> entpb.User + 13, // 35: entpb.UserService.Update:output_type -> entpb.User + 22, // 36: entpb.UserService.Delete:output_type -> google.protobuf.Empty + 19, // 37: entpb.UserService.List:output_type -> entpb.ListUserResponse + 21, // 38: entpb.UserService.BatchCreate:output_type -> entpb.BatchCreateUsersResponse + 27, // [27:39] is the sub-list for method output_type + 15, // [15:27] is the sub-list for method input_type + 15, // [15:15] is the sub-list for extension type_name + 15, // [15:15] is the sub-list for extension extendee + 0, // [0:15] is the sub-list for field type_name } func init() { file_entpb_entpb_proto_init() } @@ -729,7 +1399,7 @@ func file_entpb_entpb_proto_init() { } if !protoimpl.UnsafeEnabled { file_entpb_entpb_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*User); i { + switch v := v.(*Account); i { case 0: return &v.state case 1: @@ -741,7 +1411,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateUserRequest); i { + switch v := v.(*CreateAccountRequest); i { case 0: return &v.state case 1: @@ -753,7 +1423,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetUserRequest); i { + switch v := v.(*GetAccountRequest); i { case 0: return &v.state case 1: @@ -765,7 +1435,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UpdateUserRequest); i { + switch v := v.(*UpdateAccountRequest); i { case 0: return &v.state case 1: @@ -777,7 +1447,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteUserRequest); i { + switch v := v.(*DeleteAccountRequest); i { case 0: return &v.state case 1: @@ -789,7 +1459,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListUserRequest); i { + switch v := v.(*ListAccountRequest); i { case 0: return &v.state case 1: @@ -801,7 +1471,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListUserResponse); i { + switch v := v.(*ListAccountResponse); i { case 0: return &v.state case 1: @@ -813,7 +1483,7 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*BatchCreateUsersRequest); i { + switch v := v.(*BatchCreateAccountsRequest); i { case 0: return &v.state case 1: @@ -825,6 +1495,114 @@ func file_entpb_entpb_proto_init() { } } file_entpb_entpb_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchCreateAccountsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*User); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListUserResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchCreateUsersRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_entpb_entpb_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BatchCreateUsersResponse); i { case 0: return &v.state @@ -842,10 +1620,10 @@ func file_entpb_entpb_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_entpb_entpb_proto_rawDesc, - NumEnums: 2, - NumMessages: 9, + NumEnums: 4, + NumMessages: 18, NumExtensions: 0, - NumServices: 1, + NumServices: 2, }, GoTypes: file_entpb_entpb_proto_goTypes, DependencyIndexes: file_entpb_entpb_proto_depIdxs, diff --git a/entproto/internal/altdir/ent/v1/api/entpb/entpb.proto b/entproto/internal/altdir/ent/v1/api/entpb/entpb.proto index abd8cf337..e7b234ced 100644 --- a/entproto/internal/altdir/ent/v1/api/entpb/entpb.proto +++ b/entproto/internal/altdir/ent/v1/api/entpb/entpb.proto @@ -7,6 +7,68 @@ import "google/protobuf/empty.proto"; option go_package = "entgo.io/contrib/entproto/internal/altdir/ent/proto/entpb"; +message Account { + int64 id = 1; + + User owner = 2; +} + +message CreateAccountRequest { + Account account = 1; +} + +message GetAccountRequest { + int64 id = 1; + + View view = 2; + + enum View { + VIEW_UNSPECIFIED = 0; + + BASIC = 1; + + WITH_EDGE_IDS = 2; + } +} + +message UpdateAccountRequest { + Account account = 1; +} + +message DeleteAccountRequest { + int64 id = 1; +} + +message ListAccountRequest { + int32 page_size = 1; + + string page_token = 2; + + View view = 3; + + enum View { + VIEW_UNSPECIFIED = 0; + + BASIC = 1; + + WITH_EDGE_IDS = 2; + } +} + +message ListAccountResponse { + repeated Account account_list = 1; + + string next_page_token = 2; +} + +message BatchCreateAccountsRequest { + repeated CreateAccountRequest requests = 1; +} + +message BatchCreateAccountsResponse { + repeated Account accounts = 1; +} + message User { int64 id = 1; @@ -69,6 +131,20 @@ message BatchCreateUsersResponse { repeated User users = 1; } +service AccountService { + rpc Create ( CreateAccountRequest ) returns ( Account ); + + rpc Get ( GetAccountRequest ) returns ( Account ); + + rpc Update ( UpdateAccountRequest ) returns ( Account ); + + rpc Delete ( DeleteAccountRequest ) returns ( google.protobuf.Empty ); + + rpc List ( ListAccountRequest ) returns ( ListAccountResponse ); + + rpc BatchCreate ( BatchCreateAccountsRequest ) returns ( BatchCreateAccountsResponse ); +} + service UserService { rpc Create ( CreateUserRequest ) returns ( User ); diff --git a/entproto/internal/altdir/ent/v1/api/entpb/entpb_account_service.go b/entproto/internal/altdir/ent/v1/api/entpb/entpb_account_service.go new file mode 100644 index 000000000..5184e9ecc --- /dev/null +++ b/entproto/internal/altdir/ent/v1/api/entpb/entpb_account_service.go @@ -0,0 +1,259 @@ +// Code generated by protoc-gen-entgrpc. DO NOT EDIT. +package entpb + +import ( + context "context" + base64 "encoding/base64" + entproto "entgo.io/contrib/entproto" + ent "entgo.io/contrib/entproto/internal/altdir/ent" + account "entgo.io/contrib/entproto/internal/altdir/ent/account" + user "entgo.io/contrib/entproto/internal/altdir/ent/user" + sqlgraph "entgo.io/ent/dialect/sql/sqlgraph" + fmt "fmt" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" + strconv "strconv" +) + +// AccountService implements AccountServiceServer +type AccountService struct { + client *ent.Client + UnimplementedAccountServiceServer +} + +// NewAccountService returns a new AccountService +func NewAccountService(client *ent.Client) *AccountService { + return &AccountService{ + client: client, + } +} + +// toProtoAccount transforms the ent type to the pb type +func toProtoAccount(e *ent.Account) (*Account, error) { + v := &Account{} + id := int64(e.ID) + v.Id = id + if edg := e.Edges.Owner; edg != nil { + id := int64(edg.ID) + v.Owner = &User{ + Id: id, + } + } + return v, nil +} + +// toProtoAccountList transforms a list of ent type to a list of pb type +func toProtoAccountList(e []*ent.Account) ([]*Account, error) { + var pbList []*Account + for _, entEntity := range e { + pbEntity, err := toProtoAccount(entEntity) + if err != nil { + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + pbList = append(pbList, pbEntity) + } + return pbList, nil +} + +// Create implements AccountServiceServer.Create +func (svc *AccountService) Create(ctx context.Context, req *CreateAccountRequest) (*Account, error) { + account := req.GetAccount() + m, err := svc.createBuilder(account) + if err != nil { + return nil, err + } + res, err := m.Save(ctx) + switch { + case err == nil: + proto, err := toProtoAccount(res) + if err != nil { + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + return proto, nil + case sqlgraph.IsUniqueConstraintError(err): + return nil, status.Errorf(codes.AlreadyExists, "already exists: %s", err) + case ent.IsConstraintError(err): + return nil, status.Errorf(codes.InvalidArgument, "invalid argument: %s", err) + default: + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + +} + +// Get implements AccountServiceServer.Get +func (svc *AccountService) Get(ctx context.Context, req *GetAccountRequest) (*Account, error) { + var ( + err error + get *ent.Account + ) + id := int(req.GetId()) + switch req.GetView() { + case GetAccountRequest_VIEW_UNSPECIFIED, GetAccountRequest_BASIC: + get, err = svc.client.Account.Get(ctx, id) + case GetAccountRequest_WITH_EDGE_IDS: + get, err = svc.client.Account.Query(). + Where(account.ID(id)). + WithOwner(func(query *ent.UserQuery) { + query.Select(user.FieldID) + }). + Only(ctx) + default: + return nil, status.Error(codes.InvalidArgument, "invalid argument: unknown view") + } + switch { + case err == nil: + return toProtoAccount(get) + case ent.IsNotFound(err): + return nil, status.Errorf(codes.NotFound, "not found: %s", err) + default: + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + +} + +// Update implements AccountServiceServer.Update +func (svc *AccountService) Update(ctx context.Context, req *UpdateAccountRequest) (*Account, error) { + account := req.GetAccount() + accountID := int(account.GetId()) + m := svc.client.Account.UpdateOneID(accountID) + + res, err := m.Save(ctx) + switch { + case err == nil: + proto, err := toProtoAccount(res) + if err != nil { + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + return proto, nil + case sqlgraph.IsUniqueConstraintError(err): + return nil, status.Errorf(codes.AlreadyExists, "already exists: %s", err) + case ent.IsConstraintError(err): + return nil, status.Errorf(codes.InvalidArgument, "invalid argument: %s", err) + default: + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + +} + +// Delete implements AccountServiceServer.Delete +func (svc *AccountService) Delete(ctx context.Context, req *DeleteAccountRequest) (*emptypb.Empty, error) { + var err error + id := int(req.GetId()) + err = svc.client.Account.DeleteOneID(id).Exec(ctx) + switch { + case err == nil: + return &emptypb.Empty{}, nil + case ent.IsNotFound(err): + return nil, status.Errorf(codes.NotFound, "not found: %s", err) + default: + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + +} + +// List implements AccountServiceServer.List +func (svc *AccountService) List(ctx context.Context, req *ListAccountRequest) (*ListAccountResponse, error) { + var ( + err error + entList []*ent.Account + pageSize int + ) + pageSize = int(req.GetPageSize()) + switch { + case pageSize < 0: + return nil, status.Errorf(codes.InvalidArgument, "page size cannot be less than zero") + case pageSize == 0 || pageSize > entproto.MaxPageSize: + pageSize = entproto.MaxPageSize + } + listQuery := svc.client.Account.Query(). + Order(ent.Desc(account.FieldID)). + Limit(pageSize + 1) + if req.GetPageToken() != "" { + bytes, err := base64.StdEncoding.DecodeString(req.PageToken) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "page token is invalid") + } + token, err := strconv.ParseInt(string(bytes), 10, 32) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "page token is invalid") + } + pageToken := int(token) + listQuery = listQuery. + Where(account.IDLTE(pageToken)) + } + switch req.GetView() { + case ListAccountRequest_VIEW_UNSPECIFIED, ListAccountRequest_BASIC: + entList, err = listQuery.All(ctx) + case ListAccountRequest_WITH_EDGE_IDS: + entList, err = listQuery. + WithOwner(func(query *ent.UserQuery) { + query.Select(user.FieldID) + }). + All(ctx) + } + switch { + case err == nil: + var nextPageToken string + if len(entList) == pageSize+1 { + nextPageToken = base64.StdEncoding.EncodeToString( + []byte(fmt.Sprintf("%v", entList[len(entList)-1].ID))) + entList = entList[:len(entList)-1] + } + protoList, err := toProtoAccountList(entList) + if err != nil { + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + return &ListAccountResponse{ + AccountList: protoList, + NextPageToken: nextPageToken, + }, nil + default: + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + +} + +// BatchCreate implements AccountServiceServer.BatchCreate +func (svc *AccountService) BatchCreate(ctx context.Context, req *BatchCreateAccountsRequest) (*BatchCreateAccountsResponse, error) { + requests := req.GetRequests() + if len(requests) > entproto.MaxBatchCreateSize { + return nil, status.Errorf(codes.InvalidArgument, "batch size cannot be greater than %d", entproto.MaxBatchCreateSize) + } + bulk := make([]*ent.AccountCreate, len(requests)) + for i, req := range requests { + account := req.GetAccount() + var err error + bulk[i], err = svc.createBuilder(account) + if err != nil { + return nil, err + } + } + res, err := svc.client.Account.CreateBulk(bulk...).Save(ctx) + switch { + case err == nil: + protoList, err := toProtoAccountList(res) + if err != nil { + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + return &BatchCreateAccountsResponse{ + Accounts: protoList, + }, nil + case sqlgraph.IsUniqueConstraintError(err): + return nil, status.Errorf(codes.AlreadyExists, "already exists: %s", err) + case ent.IsConstraintError(err): + return nil, status.Errorf(codes.InvalidArgument, "invalid argument: %s", err) + default: + return nil, status.Errorf(codes.Internal, "internal error: %s", err) + } + +} + +func (svc *AccountService) createBuilder(account *Account) (*ent.AccountCreate, error) { + m := svc.client.Account.Create() + if account.GetOwner() != nil { + accountOwner := int(account.GetOwner().GetId()) + m.SetOwnerID(accountOwner) + } + return m, nil +} diff --git a/entproto/internal/altdir/ent/v1/api/entpb/entpb_grpc.pb.go b/entproto/internal/altdir/ent/v1/api/entpb/entpb_grpc.pb.go index 43eecae03..4fba99338 100644 --- a/entproto/internal/altdir/ent/v1/api/entpb/entpb_grpc.pb.go +++ b/entproto/internal/altdir/ent/v1/api/entpb/entpb_grpc.pb.go @@ -19,6 +19,272 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +// AccountServiceClient is the client API for AccountService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type AccountServiceClient interface { + Create(ctx context.Context, in *CreateAccountRequest, opts ...grpc.CallOption) (*Account, error) + Get(ctx context.Context, in *GetAccountRequest, opts ...grpc.CallOption) (*Account, error) + Update(ctx context.Context, in *UpdateAccountRequest, opts ...grpc.CallOption) (*Account, error) + Delete(ctx context.Context, in *DeleteAccountRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + List(ctx context.Context, in *ListAccountRequest, opts ...grpc.CallOption) (*ListAccountResponse, error) + BatchCreate(ctx context.Context, in *BatchCreateAccountsRequest, opts ...grpc.CallOption) (*BatchCreateAccountsResponse, error) +} + +type accountServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewAccountServiceClient(cc grpc.ClientConnInterface) AccountServiceClient { + return &accountServiceClient{cc} +} + +func (c *accountServiceClient) Create(ctx context.Context, in *CreateAccountRequest, opts ...grpc.CallOption) (*Account, error) { + out := new(Account) + err := c.cc.Invoke(ctx, "/entpb.AccountService/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountServiceClient) Get(ctx context.Context, in *GetAccountRequest, opts ...grpc.CallOption) (*Account, error) { + out := new(Account) + err := c.cc.Invoke(ctx, "/entpb.AccountService/Get", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountServiceClient) Update(ctx context.Context, in *UpdateAccountRequest, opts ...grpc.CallOption) (*Account, error) { + out := new(Account) + err := c.cc.Invoke(ctx, "/entpb.AccountService/Update", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountServiceClient) Delete(ctx context.Context, in *DeleteAccountRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, "/entpb.AccountService/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountServiceClient) List(ctx context.Context, in *ListAccountRequest, opts ...grpc.CallOption) (*ListAccountResponse, error) { + out := new(ListAccountResponse) + err := c.cc.Invoke(ctx, "/entpb.AccountService/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *accountServiceClient) BatchCreate(ctx context.Context, in *BatchCreateAccountsRequest, opts ...grpc.CallOption) (*BatchCreateAccountsResponse, error) { + out := new(BatchCreateAccountsResponse) + err := c.cc.Invoke(ctx, "/entpb.AccountService/BatchCreate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AccountServiceServer is the server API for AccountService service. +// All implementations must embed UnimplementedAccountServiceServer +// for forward compatibility +type AccountServiceServer interface { + Create(context.Context, *CreateAccountRequest) (*Account, error) + Get(context.Context, *GetAccountRequest) (*Account, error) + Update(context.Context, *UpdateAccountRequest) (*Account, error) + Delete(context.Context, *DeleteAccountRequest) (*emptypb.Empty, error) + List(context.Context, *ListAccountRequest) (*ListAccountResponse, error) + BatchCreate(context.Context, *BatchCreateAccountsRequest) (*BatchCreateAccountsResponse, error) + mustEmbedUnimplementedAccountServiceServer() +} + +// UnimplementedAccountServiceServer must be embedded to have forward compatible implementations. +type UnimplementedAccountServiceServer struct { +} + +func (UnimplementedAccountServiceServer) Create(context.Context, *CreateAccountRequest) (*Account, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (UnimplementedAccountServiceServer) Get(context.Context, *GetAccountRequest) (*Account, error) { + return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") +} +func (UnimplementedAccountServiceServer) Update(context.Context, *UpdateAccountRequest) (*Account, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (UnimplementedAccountServiceServer) Delete(context.Context, *DeleteAccountRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (UnimplementedAccountServiceServer) List(context.Context, *ListAccountRequest) (*ListAccountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (UnimplementedAccountServiceServer) BatchCreate(context.Context, *BatchCreateAccountsRequest) (*BatchCreateAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BatchCreate not implemented") +} +func (UnimplementedAccountServiceServer) mustEmbedUnimplementedAccountServiceServer() {} + +// UnsafeAccountServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AccountServiceServer will +// result in compilation errors. +type UnsafeAccountServiceServer interface { + mustEmbedUnimplementedAccountServiceServer() +} + +func RegisterAccountServiceServer(s grpc.ServiceRegistrar, srv AccountServiceServer) { + s.RegisterService(&AccountService_ServiceDesc, srv) +} + +func _AccountService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServiceServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/entpb.AccountService/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServiceServer).Create(ctx, req.(*CreateAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AccountService_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServiceServer).Get(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/entpb.AccountService/Get", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServiceServer).Get(ctx, req.(*GetAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AccountService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServiceServer).Update(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/entpb.AccountService/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServiceServer).Update(ctx, req.(*UpdateAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AccountService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServiceServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/entpb.AccountService/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServiceServer).Delete(ctx, req.(*DeleteAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AccountService_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServiceServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/entpb.AccountService/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServiceServer).List(ctx, req.(*ListAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AccountService_BatchCreate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BatchCreateAccountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountServiceServer).BatchCreate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/entpb.AccountService/BatchCreate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountServiceServer).BatchCreate(ctx, req.(*BatchCreateAccountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// AccountService_ServiceDesc is the grpc.ServiceDesc for AccountService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var AccountService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "entpb.AccountService", + HandlerType: (*AccountServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _AccountService_Create_Handler, + }, + { + MethodName: "Get", + Handler: _AccountService_Get_Handler, + }, + { + MethodName: "Update", + Handler: _AccountService_Update_Handler, + }, + { + MethodName: "Delete", + Handler: _AccountService_Delete_Handler, + }, + { + MethodName: "List", + Handler: _AccountService_List_Handler, + }, + { + MethodName: "BatchCreate", + Handler: _AccountService_BatchCreate_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "entpb/entpb.proto", +} + // UserServiceClient is the client API for UserService service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. diff --git a/entproto/internal/altdir/svc_test.go b/entproto/internal/altdir/svc_test.go index 921e77040..9e8356aff 100644 --- a/entproto/internal/altdir/svc_test.go +++ b/entproto/internal/altdir/svc_test.go @@ -25,16 +25,50 @@ import ( ) func TestService(t *testing.T) { + require := require.New(t) + client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer client.Close() - svc := entpb.NewUserService(client) + + userSvc := entpb.NewUserService(client) + accountSvc := entpb.NewAccountService(client) ctx := context.Background() - _, err := svc.Create(ctx, &entpb.CreateUserRequest{ + + owner, err := userSvc.Create(ctx, &entpb.CreateUserRequest{ User: &entpb.User{ Name: "a8m", }, }) - require.NoError(t, err) + require.NoError(err) uc := client.User.Query().CountX(ctx) - require.Equal(t, 1, uc) + require.Equal(1, uc) + + other, err := userSvc.Create(ctx, &entpb.CreateUserRequest{ + User: &entpb.User{ + Name: "Anton Chigurh", + }, + }) + require.NoError(err) + + account, err := accountSvc.Create(ctx, &entpb.CreateAccountRequest{ + Account: &entpb.Account{ + Owner: owner, + }, + }) + require.NoError(err) + + _, err = accountSvc.Update(ctx, &entpb.UpdateAccountRequest{ + Account: &entpb.Account{ + Id: account.Id, + Owner: other, + }, + }) + require.NoError(err) + + account, err = accountSvc.Get(ctx, &entpb.GetAccountRequest{ + Id: account.Id, + View: entpb.GetAccountRequest_WITH_EDGE_IDS, + }) + require.NoError(err) + require.Equal(owner.Id, account.Owner.Id) }