1
0

test token

This commit is contained in:
syui 2023-04-18 21:18:38 +09:00
parent c892ba3d8f
commit 41b6201a10
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
18 changed files with 380 additions and 64 deletions

View File

@ -57,10 +57,11 @@ var (
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "username", Type: field.TypeString, Unique: true, Size: 100}, {Name: "username", Type: field.TypeString, Unique: true, Size: 100},
{Name: "did", Type: field.TypeString, Nullable: true}, {Name: "did", Type: field.TypeString, Nullable: true},
{Name: "token", Type: field.TypeString, Nullable: true},
{Name: "password", Type: field.TypeString}, {Name: "password", Type: field.TypeString},
{Name: "created_at", Type: field.TypeTime, Nullable: true}, {Name: "created_at", Type: field.TypeTime, Nullable: true},
{Name: "updated_at", Type: field.TypeTime, Nullable: true}, {Name: "updated_at", Type: field.TypeTime, Nullable: true},
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20230414"}, {Name: "next", Type: field.TypeString, Nullable: true, Default: "20230418"},
{Name: "group_users", Type: field.TypeInt, Nullable: true}, {Name: "group_users", Type: field.TypeInt, Nullable: true},
} }
// UsersTable holds the schema information for the "users" table. // UsersTable holds the schema information for the "users" table.
@ -71,7 +72,7 @@ var (
ForeignKeys: []*schema.ForeignKey{ ForeignKeys: []*schema.ForeignKey{
{ {
Symbol: "users_groups_users", Symbol: "users_groups_users",
Columns: []*schema.Column{UsersColumns[7]}, Columns: []*schema.Column{UsersColumns[8]},
RefColumns: []*schema.Column{GroupsColumns[0]}, RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull, OnDelete: schema.SetNull,
}, },

View File

@ -1344,6 +1344,7 @@ type UserMutation struct {
id *int id *int
username *string username *string
did *string did *string
token *string
password *string password *string
created_at *time.Time created_at *time.Time
updated_at *time.Time updated_at *time.Time
@ -1540,6 +1541,55 @@ func (m *UserMutation) ResetDid() {
delete(m.clearedFields, user.FieldDid) delete(m.clearedFields, user.FieldDid)
} }
// SetToken sets the "token" field.
func (m *UserMutation) SetToken(s string) {
m.token = &s
}
// Token returns the value of the "token" field in the mutation.
func (m *UserMutation) Token() (r string, exists bool) {
v := m.token
if v == nil {
return
}
return *v, true
}
// OldToken returns the old "token" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldToken(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldToken is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldToken requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldToken: %w", err)
}
return oldValue.Token, nil
}
// ClearToken clears the value of the "token" field.
func (m *UserMutation) ClearToken() {
m.token = nil
m.clearedFields[user.FieldToken] = struct{}{}
}
// TokenCleared returns if the "token" field was cleared in this mutation.
func (m *UserMutation) TokenCleared() bool {
_, ok := m.clearedFields[user.FieldToken]
return ok
}
// ResetToken resets all changes to the "token" field.
func (m *UserMutation) ResetToken() {
m.token = nil
delete(m.clearedFields, user.FieldToken)
}
// SetPassword sets the "password" field. // SetPassword sets the "password" field.
func (m *UserMutation) SetPassword(s string) { func (m *UserMutation) SetPassword(s string) {
m.password = &s m.password = &s
@ -1811,13 +1861,16 @@ func (m *UserMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *UserMutation) Fields() []string { func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 6) fields := make([]string, 0, 7)
if m.username != nil { if m.username != nil {
fields = append(fields, user.FieldUsername) fields = append(fields, user.FieldUsername)
} }
if m.did != nil { if m.did != nil {
fields = append(fields, user.FieldDid) fields = append(fields, user.FieldDid)
} }
if m.token != nil {
fields = append(fields, user.FieldToken)
}
if m.password != nil { if m.password != nil {
fields = append(fields, user.FieldPassword) fields = append(fields, user.FieldPassword)
} }
@ -1842,6 +1895,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
return m.Username() return m.Username()
case user.FieldDid: case user.FieldDid:
return m.Did() return m.Did()
case user.FieldToken:
return m.Token()
case user.FieldPassword: case user.FieldPassword:
return m.Password() return m.Password()
case user.FieldCreatedAt: case user.FieldCreatedAt:
@ -1863,6 +1918,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldUsername(ctx) return m.OldUsername(ctx)
case user.FieldDid: case user.FieldDid:
return m.OldDid(ctx) return m.OldDid(ctx)
case user.FieldToken:
return m.OldToken(ctx)
case user.FieldPassword: case user.FieldPassword:
return m.OldPassword(ctx) return m.OldPassword(ctx)
case user.FieldCreatedAt: case user.FieldCreatedAt:
@ -1894,6 +1951,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
} }
m.SetDid(v) m.SetDid(v)
return nil return nil
case user.FieldToken:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetToken(v)
return nil
case user.FieldPassword: case user.FieldPassword:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@ -1955,6 +2019,9 @@ func (m *UserMutation) ClearedFields() []string {
if m.FieldCleared(user.FieldDid) { if m.FieldCleared(user.FieldDid) {
fields = append(fields, user.FieldDid) fields = append(fields, user.FieldDid)
} }
if m.FieldCleared(user.FieldToken) {
fields = append(fields, user.FieldToken)
}
if m.FieldCleared(user.FieldCreatedAt) { if m.FieldCleared(user.FieldCreatedAt) {
fields = append(fields, user.FieldCreatedAt) fields = append(fields, user.FieldCreatedAt)
} }
@ -1981,6 +2048,9 @@ func (m *UserMutation) ClearField(name string) error {
case user.FieldDid: case user.FieldDid:
m.ClearDid() m.ClearDid()
return nil return nil
case user.FieldToken:
m.ClearToken()
return nil
case user.FieldCreatedAt: case user.FieldCreatedAt:
m.ClearCreatedAt() m.ClearCreatedAt()
return nil return nil
@ -2004,6 +2074,9 @@ func (m *UserMutation) ResetField(name string) error {
case user.FieldDid: case user.FieldDid:
m.ResetDid() m.ResetDid()
return nil return nil
case user.FieldToken:
m.ResetToken()
return nil
case user.FieldPassword: case user.FieldPassword:
m.ResetPassword() m.ResetPassword()
return nil return nil

View File

@ -1290,6 +1290,12 @@ func (s *CreateUserReq) encodeFields(e *jx.Encoder) {
s.Did.Encode(e) s.Did.Encode(e)
} }
} }
{
if s.Token.Set {
e.FieldStart("token")
s.Token.Encode(e)
}
}
{ {
e.FieldStart("password") e.FieldStart("password")
@ -1325,14 +1331,15 @@ func (s *CreateUserReq) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfCreateUserReq = [7]string{ var jsonFieldsNameOfCreateUserReq = [8]string{
0: "username", 0: "username",
1: "did", 1: "did",
2: "password", 2: "token",
3: "created_at", 3: "password",
4: "updated_at", 4: "created_at",
5: "next", 5: "updated_at",
6: "card", 6: "next",
7: "card",
} }
// Decode decodes CreateUserReq from json. // Decode decodes CreateUserReq from json.
@ -1366,8 +1373,18 @@ func (s *CreateUserReq) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"did\"") return errors.Wrap(err, "decode field \"did\"")
} }
case "token":
if err := func() error {
s.Token.Reset()
if err := s.Token.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"token\"")
}
case "password": case "password":
requiredBitSet[0] |= 1 << 2 requiredBitSet[0] |= 1 << 3
if err := func() error { if err := func() error {
v, err := d.Str() v, err := d.Str()
s.Password = string(v) s.Password = string(v)
@ -1437,7 +1454,7 @@ func (s *CreateUserReq) Decode(d *jx.Decoder) error {
// Validate required fields. // Validate required fields.
var failures []validate.FieldError var failures []validate.FieldError
for i, mask := range [1]uint8{ for i, mask := range [1]uint8{
0b00000101, 0b00001001,
} { } {
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
// Mask only required fields and check equality to mask using XOR. // Mask only required fields and check equality to mask using XOR.
@ -3182,6 +3199,12 @@ func (s *UpdateUserReq) Encode(e *jx.Encoder) {
// encodeFields encodes fields. // encodeFields encodes fields.
func (s *UpdateUserReq) encodeFields(e *jx.Encoder) { func (s *UpdateUserReq) encodeFields(e *jx.Encoder) {
{
if s.Token.Set {
e.FieldStart("token")
s.Token.Encode(e)
}
}
{ {
if s.UpdatedAt.Set { if s.UpdatedAt.Set {
e.FieldStart("updated_at") e.FieldStart("updated_at")
@ -3206,10 +3229,11 @@ func (s *UpdateUserReq) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfUpdateUserReq = [3]string{ var jsonFieldsNameOfUpdateUserReq = [4]string{
0: "updated_at", 0: "token",
1: "next", 1: "updated_at",
2: "card", 2: "next",
3: "card",
} }
// Decode decodes UpdateUserReq from json. // Decode decodes UpdateUserReq from json.
@ -3220,6 +3244,16 @@ func (s *UpdateUserReq) Decode(d *jx.Decoder) error {
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) { switch string(k) {
case "token":
if err := func() error {
s.Token.Reset()
if err := s.Token.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"token\"")
}
case "updated_at": case "updated_at":
if err := func() error { if err := func() error {
s.UpdatedAt.Reset() s.UpdatedAt.Reset()

View File

@ -459,7 +459,7 @@ func decodeListCardParams(args [0]string, r *http.Request) (params ListCardParam
MinSet: true, MinSet: true,
Min: 1, Min: 1,
MaxSet: true, MaxSet: true,
Max: 25500, Max: 3000,
MinExclusive: false, MinExclusive: false,
MaxExclusive: false, MaxExclusive: false,
MultipleOfSet: false, MultipleOfSet: false,
@ -624,7 +624,7 @@ func decodeListGroupParams(args [0]string, r *http.Request) (params ListGroupPar
MinSet: true, MinSet: true,
Min: 1, Min: 1,
MaxSet: true, MaxSet: true,
Max: 2550, Max: 3000,
MinExclusive: false, MinExclusive: false,
MaxExclusive: false, MaxExclusive: false,
MultipleOfSet: false, MultipleOfSet: false,
@ -956,7 +956,7 @@ func decodeListUserParams(args [0]string, r *http.Request) (params ListUserParam
MinSet: true, MinSet: true,
Min: 1, Min: 1,
MaxSet: true, MaxSet: true,
Max: 2550, Max: 3000,
MinExclusive: false, MinExclusive: false,
MaxExclusive: false, MaxExclusive: false,
MultipleOfSet: false, MultipleOfSet: false,

View File

@ -485,6 +485,7 @@ func (s *CreateGroupReq) SetUsers(val []int) {
type CreateUserReq struct { type CreateUserReq struct {
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"` Did OptString `json:"did"`
Token OptString `json:"token"`
Password string `json:"password"` Password string `json:"password"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
@ -502,6 +503,11 @@ func (s *CreateUserReq) GetDid() OptString {
return s.Did return s.Did
} }
// GetToken returns the value of Token.
func (s *CreateUserReq) GetToken() OptString {
return s.Token
}
// GetPassword returns the value of Password. // GetPassword returns the value of Password.
func (s *CreateUserReq) GetPassword() string { func (s *CreateUserReq) GetPassword() string {
return s.Password return s.Password
@ -537,6 +543,11 @@ func (s *CreateUserReq) SetDid(val OptString) {
s.Did = val s.Did = val
} }
// SetToken sets the value of Token.
func (s *CreateUserReq) SetToken(val OptString) {
s.Token = val
}
// SetPassword sets the value of Password. // SetPassword sets the value of Password.
func (s *CreateUserReq) SetPassword(val string) { func (s *CreateUserReq) SetPassword(val string) {
s.Password = val s.Password = val
@ -1178,11 +1189,17 @@ func (s *UpdateGroupReq) SetUsers(val []int) {
} }
type UpdateUserReq struct { type UpdateUserReq struct {
Token OptString `json:"token"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
Card []int `json:"card"` Card []int `json:"card"`
} }
// GetToken returns the value of Token.
func (s *UpdateUserReq) GetToken() OptString {
return s.Token
}
// GetUpdatedAt returns the value of UpdatedAt. // GetUpdatedAt returns the value of UpdatedAt.
func (s *UpdateUserReq) GetUpdatedAt() OptDateTime { func (s *UpdateUserReq) GetUpdatedAt() OptDateTime {
return s.UpdatedAt return s.UpdatedAt
@ -1198,6 +1215,11 @@ func (s *UpdateUserReq) GetCard() []int {
return s.Card return s.Card
} }
// SetToken sets the value of Token.
func (s *UpdateUserReq) SetToken(val OptString) {
s.Token = val
}
// SetUpdatedAt sets the value of UpdatedAt. // SetUpdatedAt sets the value of UpdatedAt.
func (s *UpdateUserReq) SetUpdatedAt(val OptDateTime) { func (s *UpdateUserReq) SetUpdatedAt(val OptDateTime) {
s.UpdatedAt = val s.UpdatedAt = val

View File

@ -16,6 +16,8 @@ import (
) )
var password = os.Getenv("PASS") var password = os.Getenv("PASS")
var token = os.Getenv("TOKEN")
var zero = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" var zero = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
// OgentHandler implements the ogen generated Handler interface and uses Ent as data layer. // OgentHandler implements the ogen generated Handler interface and uses Ent as data layer.
type OgentHandler struct { type OgentHandler struct {
@ -536,19 +538,26 @@ func (h *OgentHandler) ReadUser(ctx context.Context, params ReadUserParams) (Rea
// UpdateUser handles PATCH /users/{id} requests. // UpdateUser handles PATCH /users/{id} requests.
func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, params UpdateUserParams) (UpdateUserRes, error) { func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, params UpdateUserParams) (UpdateUserRes, error) {
b := h.client.User.UpdateOneID(params.ID) b := h.client.User.UpdateOneID(params.ID)
// Add all fields.
if v, ok := req.UpdatedAt.Get(); ok { if v, ok := req.Token.Get(); ok {
b.SetUpdatedAt(v) if v == token {
b.SetToken(v)
// Add all fields.
if v, ok := req.UpdatedAt.Get(); ok {
b.SetUpdatedAt(v)
}
if v, ok := req.Next.Get(); ok {
b.SetNext(v)
}
// Add all edges.
if req.Card != nil {
b.ClearCard().AddCardIDs(req.Card...)
}
// Persist to storage.
}
} }
if v, ok := req.Next.Get(); ok {
b.SetNext(v)
}
// Add all edges.
if req.Card != nil {
b.ClearCard().AddCardIDs(req.Card...)
}
// Persist to storage.
e, err := b.Save(ctx) e, err := b.Save(ctx)
if err != nil { if err != nil {
switch { switch {
case ent.IsNotFound(err): case ent.IsNotFound(err):

View File

@ -30,7 +30,7 @@
"description": "item count to render per page", "description": "item count to render per page",
"schema": { "schema": {
"type": "integer", "type": "integer",
"maximum": 25500, "maximum": 3000,
"minimum": 1 "minimum": 1
} }
} }
@ -366,7 +366,7 @@
"description": "item count to render per page", "description": "item count to render per page",
"schema": { "schema": {
"type": "integer", "type": "integer",
"maximum": 2550, "maximum": 3000,
"minimum": 1 "minimum": 1
} }
} }
@ -692,7 +692,7 @@
"description": "item count to render per page", "description": "item count to render per page",
"schema": { "schema": {
"type": "integer", "type": "integer",
"maximum": 2550, "maximum": 3000,
"minimum": 1 "minimum": 1
} }
} }
@ -745,6 +745,9 @@
"did": { "did": {
"type": "string" "type": "string"
}, },
"token": {
"type": "string"
},
"password": { "password": {
"type": "string" "type": "string"
}, },
@ -903,6 +906,9 @@
"schema": { "schema": {
"type": "object", "type": "object",
"properties": { "properties": {
"token": {
"type": "string"
},
"updated_at": { "updated_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"
@ -1338,6 +1344,9 @@
"did": { "did": {
"type": "string" "type": "string"
}, },
"token": {
"type": "string"
},
"password": { "password": {
"type": "string" "type": "string"
}, },

View File

@ -67,19 +67,19 @@ func init() {
} }
}() }()
// userDescPassword is the schema descriptor for password field. // userDescPassword is the schema descriptor for password field.
userDescPassword := userFields[2].Descriptor() userDescPassword := userFields[3].Descriptor()
// user.PasswordValidator is a validator for the "password" field. It is called by the builders before save. // user.PasswordValidator is a validator for the "password" field. It is called by the builders before save.
user.PasswordValidator = userDescPassword.Validators[0].(func(string) error) user.PasswordValidator = userDescPassword.Validators[0].(func(string) error)
// userDescCreatedAt is the schema descriptor for created_at field. // userDescCreatedAt is the schema descriptor for created_at field.
userDescCreatedAt := userFields[3].Descriptor() userDescCreatedAt := userFields[4].Descriptor()
// user.DefaultCreatedAt holds the default value on creation for the created_at field. // user.DefaultCreatedAt holds the default value on creation for the created_at field.
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time) user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
// userDescUpdatedAt is the schema descriptor for updated_at field. // userDescUpdatedAt is the schema descriptor for updated_at field.
userDescUpdatedAt := userFields[4].Descriptor() userDescUpdatedAt := userFields[5].Descriptor()
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field. // user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time) user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
// userDescNext is the schema descriptor for next field. // userDescNext is the schema descriptor for next field.
userDescNext := userFields[5].Descriptor() userDescNext := userFields[6].Descriptor()
// user.DefaultNext holds the default value on creation for the next field. // user.DefaultNext holds the default value on creation for the next field.
user.DefaultNext = userDescNext.Default.(string) user.DefaultNext = userDescNext.Default.(string)
} }

View File

@ -39,6 +39,10 @@ func (User) Fields() []ent.Field {
Optional(). Optional().
Immutable(), Immutable(),
field.String("token").
Optional().
Sensitive(),
field.String("password"). field.String("password").
NotEmpty(). NotEmpty().
Immutable(). Immutable().

View File

@ -20,6 +20,8 @@ type User struct {
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
// Did holds the value of the "did" field. // Did holds the value of the "did" field.
Did string `json:"did,omitempty"` Did string `json:"did,omitempty"`
// Token holds the value of the "token" field.
Token string `json:"-"`
// Password holds the value of the "password" field. // Password holds the value of the "password" field.
Password string `json:"-"` Password string `json:"-"`
// CreatedAt holds the value of the "created_at" field. // CreatedAt holds the value of the "created_at" field.
@ -59,7 +61,7 @@ func (*User) scanValues(columns []string) ([]any, error) {
switch columns[i] { switch columns[i] {
case user.FieldID: case user.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case user.FieldUsername, user.FieldDid, user.FieldPassword, user.FieldNext: case user.FieldUsername, user.FieldDid, user.FieldToken, user.FieldPassword, user.FieldNext:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
case user.FieldCreatedAt, user.FieldUpdatedAt: case user.FieldCreatedAt, user.FieldUpdatedAt:
values[i] = new(sql.NullTime) values[i] = new(sql.NullTime)
@ -98,6 +100,12 @@ func (u *User) assignValues(columns []string, values []any) error {
} else if value.Valid { } else if value.Valid {
u.Did = value.String u.Did = value.String
} }
case user.FieldToken:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field token", values[i])
} else if value.Valid {
u.Token = value.String
}
case user.FieldPassword: case user.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i]) return fmt.Errorf("unexpected type %T for field password", values[i])
@ -168,6 +176,8 @@ func (u *User) String() string {
builder.WriteString("did=") builder.WriteString("did=")
builder.WriteString(u.Did) builder.WriteString(u.Did)
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("token=<sensitive>")
builder.WriteString(", ")
builder.WriteString("password=<sensitive>") builder.WriteString("password=<sensitive>")
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")

View File

@ -15,6 +15,8 @@ const (
FieldUsername = "username" FieldUsername = "username"
// FieldDid holds the string denoting the did field in the database. // FieldDid holds the string denoting the did field in the database.
FieldDid = "did" FieldDid = "did"
// FieldToken holds the string denoting the token field in the database.
FieldToken = "token"
// FieldPassword holds the string denoting the password field in the database. // FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password" FieldPassword = "password"
// FieldCreatedAt holds the string denoting the created_at field in the database. // FieldCreatedAt holds the string denoting the created_at field in the database.
@ -41,6 +43,7 @@ var Columns = []string{
FieldID, FieldID,
FieldUsername, FieldUsername,
FieldDid, FieldDid,
FieldToken,
FieldPassword, FieldPassword,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,

View File

@ -65,6 +65,11 @@ func Did(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldDid, v)) return predicate.User(sql.FieldEQ(FieldDid, v))
} }
// Token applies equality check predicate on the "token" field. It's identical to TokenEQ.
func Token(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldToken, v))
}
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. // Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
func Password(v string) predicate.User { func Password(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldPassword, v)) return predicate.User(sql.FieldEQ(FieldPassword, v))
@ -225,6 +230,81 @@ func DidContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldDid, v)) return predicate.User(sql.FieldContainsFold(FieldDid, v))
} }
// TokenEQ applies the EQ predicate on the "token" field.
func TokenEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldToken, v))
}
// TokenNEQ applies the NEQ predicate on the "token" field.
func TokenNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldToken, v))
}
// TokenIn applies the In predicate on the "token" field.
func TokenIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldToken, vs...))
}
// TokenNotIn applies the NotIn predicate on the "token" field.
func TokenNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldToken, vs...))
}
// TokenGT applies the GT predicate on the "token" field.
func TokenGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldToken, v))
}
// TokenGTE applies the GTE predicate on the "token" field.
func TokenGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldToken, v))
}
// TokenLT applies the LT predicate on the "token" field.
func TokenLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldToken, v))
}
// TokenLTE applies the LTE predicate on the "token" field.
func TokenLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldToken, v))
}
// TokenContains applies the Contains predicate on the "token" field.
func TokenContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldToken, v))
}
// TokenHasPrefix applies the HasPrefix predicate on the "token" field.
func TokenHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldToken, v))
}
// TokenHasSuffix applies the HasSuffix predicate on the "token" field.
func TokenHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldToken, v))
}
// TokenIsNil applies the IsNil predicate on the "token" field.
func TokenIsNil() predicate.User {
return predicate.User(sql.FieldIsNull(FieldToken))
}
// TokenNotNil applies the NotNil predicate on the "token" field.
func TokenNotNil() predicate.User {
return predicate.User(sql.FieldNotNull(FieldToken))
}
// TokenEqualFold applies the EqualFold predicate on the "token" field.
func TokenEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldToken, v))
}
// TokenContainsFold applies the ContainsFold predicate on the "token" field.
func TokenContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldToken, v))
}
// PasswordEQ applies the EQ predicate on the "password" field. // PasswordEQ applies the EQ predicate on the "password" field.
func PasswordEQ(v string) predicate.User { func PasswordEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldPassword, v)) return predicate.User(sql.FieldEQ(FieldPassword, v))

View File

@ -41,6 +41,20 @@ func (uc *UserCreate) SetNillableDid(s *string) *UserCreate {
return uc return uc
} }
// SetToken sets the "token" field.
func (uc *UserCreate) SetToken(s string) *UserCreate {
uc.mutation.SetToken(s)
return uc
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (uc *UserCreate) SetNillableToken(s *string) *UserCreate {
if s != nil {
uc.SetToken(*s)
}
return uc
}
// SetPassword sets the "password" field. // SetPassword sets the "password" field.
func (uc *UserCreate) SetPassword(s string) *UserCreate { func (uc *UserCreate) SetPassword(s string) *UserCreate {
uc.mutation.SetPassword(s) uc.mutation.SetPassword(s)
@ -205,6 +219,10 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec.SetField(user.FieldDid, field.TypeString, value) _spec.SetField(user.FieldDid, field.TypeString, value)
_node.Did = value _node.Did = value
} }
if value, ok := uc.mutation.Token(); ok {
_spec.SetField(user.FieldToken, field.TypeString, value)
_node.Token = value
}
if value, ok := uc.mutation.Password(); ok { if value, ok := uc.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value) _spec.SetField(user.FieldPassword, field.TypeString, value)
_node.Password = value _node.Password = value

View File

@ -29,6 +29,26 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
return uu return uu
} }
// SetToken sets the "token" field.
func (uu *UserUpdate) SetToken(s string) *UserUpdate {
uu.mutation.SetToken(s)
return uu
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (uu *UserUpdate) SetNillableToken(s *string) *UserUpdate {
if s != nil {
uu.SetToken(*s)
}
return uu
}
// ClearToken clears the value of the "token" field.
func (uu *UserUpdate) ClearToken() *UserUpdate {
uu.mutation.ClearToken()
return uu
}
// SetUpdatedAt sets the "updated_at" field. // SetUpdatedAt sets the "updated_at" field.
func (uu *UserUpdate) SetUpdatedAt(t time.Time) *UserUpdate { func (uu *UserUpdate) SetUpdatedAt(t time.Time) *UserUpdate {
uu.mutation.SetUpdatedAt(t) uu.mutation.SetUpdatedAt(t)
@ -149,6 +169,12 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
if uu.mutation.DidCleared() { if uu.mutation.DidCleared() {
_spec.ClearField(user.FieldDid, field.TypeString) _spec.ClearField(user.FieldDid, field.TypeString)
} }
if value, ok := uu.mutation.Token(); ok {
_spec.SetField(user.FieldToken, field.TypeString, value)
}
if uu.mutation.TokenCleared() {
_spec.ClearField(user.FieldToken, field.TypeString)
}
if uu.mutation.CreatedAtCleared() { if uu.mutation.CreatedAtCleared() {
_spec.ClearField(user.FieldCreatedAt, field.TypeTime) _spec.ClearField(user.FieldCreatedAt, field.TypeTime)
} }
@ -229,6 +255,26 @@ type UserUpdateOne struct {
mutation *UserMutation mutation *UserMutation
} }
// SetToken sets the "token" field.
func (uuo *UserUpdateOne) SetToken(s string) *UserUpdateOne {
uuo.mutation.SetToken(s)
return uuo
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableToken(s *string) *UserUpdateOne {
if s != nil {
uuo.SetToken(*s)
}
return uuo
}
// ClearToken clears the value of the "token" field.
func (uuo *UserUpdateOne) ClearToken() *UserUpdateOne {
uuo.mutation.ClearToken()
return uuo
}
// SetUpdatedAt sets the "updated_at" field. // SetUpdatedAt sets the "updated_at" field.
func (uuo *UserUpdateOne) SetUpdatedAt(t time.Time) *UserUpdateOne { func (uuo *UserUpdateOne) SetUpdatedAt(t time.Time) *UserUpdateOne {
uuo.mutation.SetUpdatedAt(t) uuo.mutation.SetUpdatedAt(t)
@ -379,6 +425,12 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
if uuo.mutation.DidCleared() { if uuo.mutation.DidCleared() {
_spec.ClearField(user.FieldDid, field.TypeString) _spec.ClearField(user.FieldDid, field.TypeString)
} }
if value, ok := uuo.mutation.Token(); ok {
_spec.SetField(user.FieldToken, field.TypeString, value)
}
if uuo.mutation.TokenCleared() {
_spec.ClearField(user.FieldToken, field.TypeString)
}
if uuo.mutation.CreatedAtCleared() { if uuo.mutation.CreatedAtCleared() {
_spec.ClearField(user.FieldCreatedAt, field.TypeTime) _spec.ClearField(user.FieldCreatedAt, field.TypeTime)
} }

View File

@ -8,7 +8,7 @@ $ go build
$ ./card $ ./card
$ go generate ./... $ go generate ./...
$ go run -mod=mod main.go $ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go
$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users $ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards $ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards $ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards

View File

@ -3,7 +3,7 @@
host=https://api.syui.ai host=https://api.syui.ai
api=localhost:8080 api=localhost:8080
host_users="$host/users?itemsPerPage=255" host_users="$host/users?itemsPerPage=2550"
d=${0:a:h} d=${0:a:h}
dd=${0:a:h:h} dd=${0:a:h:h}
pass=`cat $dd/token.json|jq -r .password` pass=`cat $dd/token.json|jq -r .password`
@ -43,22 +43,14 @@ do
name=`echo $data|jq ".[$i]"|jq -r .username` name=`echo $data|jq ".[$i]"|jq -r .username`
id=`echo $data|jq ".[$i]"|jq -r .id` id=`echo $data|jq ".[$i]"|jq -r .id`
if [ "$1" = "-s" ];then did=`echo $data|jq ".[$i]"|jq -r .did`
did
else
did=`cat $d/user.json|jq -r ".[]|select(.name == \"$name\")|.did"`
fi
echo "{\"username\":\"$name\", \"password\":\"$pass\",\"did\":\"$did\"} localhost:8080/users" echo "{\"username\":\"$name\", \"password\":\"$pass\",\"did\":\"$did\"} localhost:8080/users"
#if [ "$did" = "null" ];then
# echo "{\"username\":\"$name\", \"password\":\"$pass\",\"did\":\"$did\"} localhost:8080/users"
#else
# echo "{\"username\":\"$name\", \"password\":\"$pass\"} localhost:8080/users"
#fi
if [ "$1" = "-a" ];then if [ "$1" = "-a" ];then
l_users l_users
fi fi
data_card=`curl -sL "$host/users/$id/card?itemsPerPage=255"` data_card=`curl -sL "$host/users/$id/card?itemsPerPage=2550"`
nn=`echo $data_card|jq length` nn=`echo $data_card|jq length`
nn=$((nn - 1)) nn=$((nn - 1))

View File

@ -459,7 +459,7 @@ func decodeListCardParams(args [0]string, r *http.Request) (params ListCardParam
MinSet: true, MinSet: true,
Min: 1, Min: 1,
MaxSet: true, MaxSet: true,
Max: 25500, Max: 3000,
MinExclusive: false, MinExclusive: false,
MaxExclusive: false, MaxExclusive: false,
MultipleOfSet: false, MultipleOfSet: false,
@ -624,7 +624,7 @@ func decodeListGroupParams(args [0]string, r *http.Request) (params ListGroupPar
MinSet: true, MinSet: true,
Min: 1, Min: 1,
MaxSet: true, MaxSet: true,
Max: 2550, Max: 3000,
MinExclusive: false, MinExclusive: false,
MaxExclusive: false, MaxExclusive: false,
MultipleOfSet: false, MultipleOfSet: false,
@ -956,7 +956,7 @@ func decodeListUserParams(args [0]string, r *http.Request) (params ListUserParam
MinSet: true, MinSet: true,
Min: 1, Min: 1,
MaxSet: true, MaxSet: true,
Max: 2550, Max: 3000,
MinExclusive: false, MinExclusive: false,
MaxExclusive: false, MaxExclusive: false,
MultipleOfSet: false, MultipleOfSet: false,

View File

@ -16,6 +16,8 @@ import (
) )
var password = os.Getenv("PASS") var password = os.Getenv("PASS")
var token = os.Getenv("TOKEN")
var zero = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" var zero = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
// OgentHandler implements the ogen generated Handler interface and uses Ent as data layer. // OgentHandler implements the ogen generated Handler interface and uses Ent as data layer.
type OgentHandler struct { type OgentHandler struct {
@ -536,19 +538,26 @@ func (h *OgentHandler) ReadUser(ctx context.Context, params ReadUserParams) (Rea
// UpdateUser handles PATCH /users/{id} requests. // UpdateUser handles PATCH /users/{id} requests.
func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, params UpdateUserParams) (UpdateUserRes, error) { func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, params UpdateUserParams) (UpdateUserRes, error) {
b := h.client.User.UpdateOneID(params.ID) b := h.client.User.UpdateOneID(params.ID)
// Add all fields.
if v, ok := req.UpdatedAt.Get(); ok { if v, ok := req.Token.Get(); ok {
b.SetUpdatedAt(v) if v == token {
b.SetToken(v)
// Add all fields.
if v, ok := req.UpdatedAt.Get(); ok {
b.SetUpdatedAt(v)
}
if v, ok := req.Next.Get(); ok {
b.SetNext(v)
}
// Add all edges.
if req.Card != nil {
b.ClearCard().AddCardIDs(req.Card...)
}
// Persist to storage.
}
} }
if v, ok := req.Next.Get(); ok {
b.SetNext(v)
}
// Add all edges.
if req.Card != nil {
b.ClearCard().AddCardIDs(req.Card...)
}
// Persist to storage.
e, err := b.Save(ctx) e, err := b.Save(ctx)
if err != nil { if err != nil {
switch { switch {
case ent.IsNotFound(err): case ent.IsNotFound(err):