1
0
This commit is contained in:
syui 2023-04-13 16:50:11 +09:00
parent ab66b9efc0
commit d72f710aaa
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
20 changed files with 526 additions and 63 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ t
#*.zsh #*.zsh
tmp/card_limit.zsh tmp/card_limit.zsh
tmp/card_day.zsh tmp/card_day.zsh
tmp/card_delete.zsh
memo.md

View File

@ -55,11 +55,12 @@ var (
// UsersColumns holds the columns for the "users" table. // UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{ UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "username", Type: field.TypeString, Unique: true, Size: 30}, {Name: "username", Type: field.TypeString, Unique: true, Size: 100},
{Name: "did", 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: "20230410"}, {Name: "next", Type: field.TypeString, Nullable: true, Default: "20230414"},
{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.
@ -70,7 +71,7 @@ var (
ForeignKeys: []*schema.ForeignKey{ ForeignKeys: []*schema.ForeignKey{
{ {
Symbol: "users_groups_users", Symbol: "users_groups_users",
Columns: []*schema.Column{UsersColumns[6]}, Columns: []*schema.Column{UsersColumns[7]},
RefColumns: []*schema.Column{GroupsColumns[0]}, RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull, OnDelete: schema.SetNull,
}, },

View File

@ -1343,6 +1343,7 @@ type UserMutation struct {
typ string typ string
id *int id *int
username *string username *string
did *string
password *string password *string
created_at *time.Time created_at *time.Time
updated_at *time.Time updated_at *time.Time
@ -1490,6 +1491,55 @@ func (m *UserMutation) ResetUsername() {
m.username = nil m.username = nil
} }
// SetDid sets the "did" field.
func (m *UserMutation) SetDid(s string) {
m.did = &s
}
// Did returns the value of the "did" field in the mutation.
func (m *UserMutation) Did() (r string, exists bool) {
v := m.did
if v == nil {
return
}
return *v, true
}
// OldDid returns the old "did" field's value of the 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) OldDid(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDid is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDid requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDid: %w", err)
}
return oldValue.Did, nil
}
// ClearDid clears the value of the "did" field.
func (m *UserMutation) ClearDid() {
m.did = nil
m.clearedFields[user.FieldDid] = struct{}{}
}
// DidCleared returns if the "did" field was cleared in this mutation.
func (m *UserMutation) DidCleared() bool {
_, ok := m.clearedFields[user.FieldDid]
return ok
}
// ResetDid resets all changes to the "did" field.
func (m *UserMutation) ResetDid() {
m.did = nil
delete(m.clearedFields, user.FieldDid)
}
// 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
@ -1761,10 +1811,13 @@ 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, 5) fields := make([]string, 0, 6)
if m.username != nil { if m.username != nil {
fields = append(fields, user.FieldUsername) fields = append(fields, user.FieldUsername)
} }
if m.did != nil {
fields = append(fields, user.FieldDid)
}
if m.password != nil { if m.password != nil {
fields = append(fields, user.FieldPassword) fields = append(fields, user.FieldPassword)
} }
@ -1787,6 +1840,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case user.FieldUsername: case user.FieldUsername:
return m.Username() return m.Username()
case user.FieldDid:
return m.Did()
case user.FieldPassword: case user.FieldPassword:
return m.Password() return m.Password()
case user.FieldCreatedAt: case user.FieldCreatedAt:
@ -1806,6 +1861,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
switch name { switch name {
case user.FieldUsername: case user.FieldUsername:
return m.OldUsername(ctx) return m.OldUsername(ctx)
case user.FieldDid:
return m.OldDid(ctx)
case user.FieldPassword: case user.FieldPassword:
return m.OldPassword(ctx) return m.OldPassword(ctx)
case user.FieldCreatedAt: case user.FieldCreatedAt:
@ -1830,6 +1887,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
} }
m.SetUsername(v) m.SetUsername(v)
return nil return nil
case user.FieldDid:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDid(v)
return nil
case user.FieldPassword: case user.FieldPassword:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@ -1888,6 +1952,9 @@ func (m *UserMutation) AddField(name string, value ent.Value) error {
// mutation. // mutation.
func (m *UserMutation) ClearedFields() []string { func (m *UserMutation) ClearedFields() []string {
var fields []string var fields []string
if m.FieldCleared(user.FieldDid) {
fields = append(fields, user.FieldDid)
}
if m.FieldCleared(user.FieldCreatedAt) { if m.FieldCleared(user.FieldCreatedAt) {
fields = append(fields, user.FieldCreatedAt) fields = append(fields, user.FieldCreatedAt)
} }
@ -1911,6 +1978,9 @@ func (m *UserMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema. // error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error { func (m *UserMutation) ClearField(name string) error {
switch name { switch name {
case user.FieldDid:
m.ClearDid()
return nil
case user.FieldCreatedAt: case user.FieldCreatedAt:
m.ClearCreatedAt() m.ClearCreatedAt()
return nil return nil
@ -1931,6 +2001,9 @@ func (m *UserMutation) ResetField(name string) error {
case user.FieldUsername: case user.FieldUsername:
m.ResetUsername() m.ResetUsername()
return nil return nil
case user.FieldDid:
m.ResetDid()
return nil
case user.FieldPassword: case user.FieldPassword:
m.ResetPassword() m.ResetPassword()
return nil return nil

View File

@ -397,6 +397,12 @@ func (s *CardOwnerRead) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
if s.CreatedAt.Set { if s.CreatedAt.Set {
e.FieldStart("created_at") e.FieldStart("created_at")
@ -417,12 +423,13 @@ func (s *CardOwnerRead) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfCardOwnerRead = [5]string{ var jsonFieldsNameOfCardOwnerRead = [6]string{
0: "id", 0: "id",
1: "username", 1: "username",
2: "created_at", 2: "did",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "next",
} }
// Decode decodes CardOwnerRead from json. // Decode decodes CardOwnerRead from json.
@ -458,6 +465,16 @@ func (s *CardOwnerRead) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "created_at": case "created_at":
if err := func() error { if err := func() error {
s.CreatedAt.Reset() s.CreatedAt.Reset()
@ -1267,6 +1284,12 @@ func (s *CreateUserReq) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
e.FieldStart("password") e.FieldStart("password")
@ -1302,13 +1325,14 @@ func (s *CreateUserReq) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfCreateUserReq = [6]string{ var jsonFieldsNameOfCreateUserReq = [7]string{
0: "username", 0: "username",
1: "password", 1: "did",
2: "created_at", 2: "password",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "card", 5: "next",
6: "card",
} }
// Decode decodes CreateUserReq from json. // Decode decodes CreateUserReq from json.
@ -1332,8 +1356,18 @@ func (s *CreateUserReq) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "password": case "password":
requiredBitSet[0] |= 1 << 1 requiredBitSet[0] |= 1 << 2
if err := func() error { if err := func() error {
v, err := d.Str() v, err := d.Str()
s.Password = string(v) s.Password = string(v)
@ -1403,7 +1437,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{
0b00000011, 0b00000101,
} { } {
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.
@ -1928,6 +1962,12 @@ func (s *GroupUsersList) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
if s.CreatedAt.Set { if s.CreatedAt.Set {
e.FieldStart("created_at") e.FieldStart("created_at")
@ -1948,12 +1988,13 @@ func (s *GroupUsersList) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfGroupUsersList = [5]string{ var jsonFieldsNameOfGroupUsersList = [6]string{
0: "id", 0: "id",
1: "username", 1: "username",
2: "created_at", 2: "did",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "next",
} }
// Decode decodes GroupUsersList from json. // Decode decodes GroupUsersList from json.
@ -1989,6 +2030,16 @@ func (s *GroupUsersList) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "created_at": case "created_at":
if err := func() error { if err := func() error {
s.CreatedAt.Reset() s.CreatedAt.Reset()
@ -3433,6 +3484,12 @@ func (s *UserCreate) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
if s.CreatedAt.Set { if s.CreatedAt.Set {
e.FieldStart("created_at") e.FieldStart("created_at")
@ -3453,12 +3510,13 @@ func (s *UserCreate) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfUserCreate = [5]string{ var jsonFieldsNameOfUserCreate = [6]string{
0: "id", 0: "id",
1: "username", 1: "username",
2: "created_at", 2: "did",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "next",
} }
// Decode decodes UserCreate from json. // Decode decodes UserCreate from json.
@ -3494,6 +3552,16 @@ func (s *UserCreate) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "created_at": case "created_at":
if err := func() error { if err := func() error {
s.CreatedAt.Reset() s.CreatedAt.Reset()
@ -3599,6 +3667,12 @@ func (s *UserList) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
if s.CreatedAt.Set { if s.CreatedAt.Set {
e.FieldStart("created_at") e.FieldStart("created_at")
@ -3619,12 +3693,13 @@ func (s *UserList) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfUserList = [5]string{ var jsonFieldsNameOfUserList = [6]string{
0: "id", 0: "id",
1: "username", 1: "username",
2: "created_at", 2: "did",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "next",
} }
// Decode decodes UserList from json. // Decode decodes UserList from json.
@ -3660,6 +3735,16 @@ func (s *UserList) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "created_at": case "created_at":
if err := func() error { if err := func() error {
s.CreatedAt.Reset() s.CreatedAt.Reset()
@ -3765,6 +3850,12 @@ func (s *UserRead) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
if s.CreatedAt.Set { if s.CreatedAt.Set {
e.FieldStart("created_at") e.FieldStart("created_at")
@ -3785,12 +3876,13 @@ func (s *UserRead) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfUserRead = [5]string{ var jsonFieldsNameOfUserRead = [6]string{
0: "id", 0: "id",
1: "username", 1: "username",
2: "created_at", 2: "did",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "next",
} }
// Decode decodes UserRead from json. // Decode decodes UserRead from json.
@ -3826,6 +3918,16 @@ func (s *UserRead) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "created_at": case "created_at":
if err := func() error { if err := func() error {
s.CreatedAt.Reset() s.CreatedAt.Reset()
@ -3931,6 +4033,12 @@ func (s *UserUpdate) encodeFields(e *jx.Encoder) {
e.FieldStart("username") e.FieldStart("username")
e.Str(s.Username) e.Str(s.Username)
} }
{
if s.Did.Set {
e.FieldStart("did")
s.Did.Encode(e)
}
}
{ {
if s.CreatedAt.Set { if s.CreatedAt.Set {
e.FieldStart("created_at") e.FieldStart("created_at")
@ -3951,12 +4059,13 @@ func (s *UserUpdate) encodeFields(e *jx.Encoder) {
} }
} }
var jsonFieldsNameOfUserUpdate = [5]string{ var jsonFieldsNameOfUserUpdate = [6]string{
0: "id", 0: "id",
1: "username", 1: "username",
2: "created_at", 2: "did",
3: "updated_at", 3: "created_at",
4: "next", 4: "updated_at",
5: "next",
} }
// Decode decodes UserUpdate from json. // Decode decodes UserUpdate from json.
@ -3992,6 +4101,16 @@ func (s *UserUpdate) Decode(d *jx.Decoder) error {
}(); err != nil { }(); err != nil {
return errors.Wrap(err, "decode field \"username\"") return errors.Wrap(err, "decode field \"username\"")
} }
case "did":
if err := func() error {
s.Did.Reset()
if err := s.Did.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"did\"")
}
case "created_at": case "created_at":
if err := func() error { if err := func() error {
s.CreatedAt.Reset() s.CreatedAt.Reset()

View File

@ -154,6 +154,7 @@ func (s *CardList) SetCreatedAt(val OptDateTime) {
type CardOwnerRead struct { type CardOwnerRead struct {
ID int `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
@ -169,6 +170,11 @@ func (s *CardOwnerRead) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *CardOwnerRead) GetDid() OptString {
return s.Did
}
// GetCreatedAt returns the value of CreatedAt. // GetCreatedAt returns the value of CreatedAt.
func (s *CardOwnerRead) GetCreatedAt() OptDateTime { func (s *CardOwnerRead) GetCreatedAt() OptDateTime {
return s.CreatedAt return s.CreatedAt
@ -194,6 +200,11 @@ func (s *CardOwnerRead) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *CardOwnerRead) SetDid(val OptString) {
s.Did = val
}
// SetCreatedAt sets the value of CreatedAt. // SetCreatedAt sets the value of CreatedAt.
func (s *CardOwnerRead) SetCreatedAt(val OptDateTime) { func (s *CardOwnerRead) SetCreatedAt(val OptDateTime) {
s.CreatedAt = val s.CreatedAt = val
@ -473,6 +484,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"`
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"`
@ -485,6 +497,11 @@ func (s *CreateUserReq) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *CreateUserReq) GetDid() OptString {
return s.Did
}
// 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
@ -515,6 +532,11 @@ func (s *CreateUserReq) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *CreateUserReq) SetDid(val OptString) {
s.Did = 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
@ -675,6 +697,7 @@ func (*GroupUpdate) updateGroupRes() {}
type GroupUsersList struct { type GroupUsersList struct {
ID int `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
@ -690,6 +713,11 @@ func (s *GroupUsersList) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *GroupUsersList) GetDid() OptString {
return s.Did
}
// GetCreatedAt returns the value of CreatedAt. // GetCreatedAt returns the value of CreatedAt.
func (s *GroupUsersList) GetCreatedAt() OptDateTime { func (s *GroupUsersList) GetCreatedAt() OptDateTime {
return s.CreatedAt return s.CreatedAt
@ -715,6 +743,11 @@ func (s *GroupUsersList) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *GroupUsersList) SetDid(val OptString) {
s.Did = val
}
// SetCreatedAt sets the value of CreatedAt. // SetCreatedAt sets the value of CreatedAt.
func (s *GroupUsersList) SetCreatedAt(val OptDateTime) { func (s *GroupUsersList) SetCreatedAt(val OptDateTime) {
s.CreatedAt = val s.CreatedAt = val
@ -1254,6 +1287,7 @@ func (s *UserCardList) SetCreatedAt(val OptDateTime) {
type UserCreate struct { type UserCreate struct {
ID int `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
@ -1269,6 +1303,11 @@ func (s *UserCreate) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *UserCreate) GetDid() OptString {
return s.Did
}
// GetCreatedAt returns the value of CreatedAt. // GetCreatedAt returns the value of CreatedAt.
func (s *UserCreate) GetCreatedAt() OptDateTime { func (s *UserCreate) GetCreatedAt() OptDateTime {
return s.CreatedAt return s.CreatedAt
@ -1294,6 +1333,11 @@ func (s *UserCreate) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *UserCreate) SetDid(val OptString) {
s.Did = val
}
// SetCreatedAt sets the value of CreatedAt. // SetCreatedAt sets the value of CreatedAt.
func (s *UserCreate) SetCreatedAt(val OptDateTime) { func (s *UserCreate) SetCreatedAt(val OptDateTime) {
s.CreatedAt = val s.CreatedAt = val
@ -1315,6 +1359,7 @@ func (*UserCreate) createUserRes() {}
type UserList struct { type UserList struct {
ID int `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
@ -1330,6 +1375,11 @@ func (s *UserList) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *UserList) GetDid() OptString {
return s.Did
}
// GetCreatedAt returns the value of CreatedAt. // GetCreatedAt returns the value of CreatedAt.
func (s *UserList) GetCreatedAt() OptDateTime { func (s *UserList) GetCreatedAt() OptDateTime {
return s.CreatedAt return s.CreatedAt
@ -1355,6 +1405,11 @@ func (s *UserList) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *UserList) SetDid(val OptString) {
s.Did = val
}
// SetCreatedAt sets the value of CreatedAt. // SetCreatedAt sets the value of CreatedAt.
func (s *UserList) SetCreatedAt(val OptDateTime) { func (s *UserList) SetCreatedAt(val OptDateTime) {
s.CreatedAt = val s.CreatedAt = val
@ -1374,6 +1429,7 @@ func (s *UserList) SetNext(val OptString) {
type UserRead struct { type UserRead struct {
ID int `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
@ -1389,6 +1445,11 @@ func (s *UserRead) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *UserRead) GetDid() OptString {
return s.Did
}
// GetCreatedAt returns the value of CreatedAt. // GetCreatedAt returns the value of CreatedAt.
func (s *UserRead) GetCreatedAt() OptDateTime { func (s *UserRead) GetCreatedAt() OptDateTime {
return s.CreatedAt return s.CreatedAt
@ -1414,6 +1475,11 @@ func (s *UserRead) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *UserRead) SetDid(val OptString) {
s.Did = val
}
// SetCreatedAt sets the value of CreatedAt. // SetCreatedAt sets the value of CreatedAt.
func (s *UserRead) SetCreatedAt(val OptDateTime) { func (s *UserRead) SetCreatedAt(val OptDateTime) {
s.CreatedAt = val s.CreatedAt = val
@ -1435,6 +1501,7 @@ func (*UserRead) readUserRes() {}
type UserUpdate struct { type UserUpdate struct {
ID int `json:"id"` ID int `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Did OptString `json:"did"`
CreatedAt OptDateTime `json:"created_at"` CreatedAt OptDateTime `json:"created_at"`
UpdatedAt OptDateTime `json:"updated_at"` UpdatedAt OptDateTime `json:"updated_at"`
Next OptString `json:"next"` Next OptString `json:"next"`
@ -1450,6 +1517,11 @@ func (s *UserUpdate) GetUsername() string {
return s.Username return s.Username
} }
// GetDid returns the value of Did.
func (s *UserUpdate) GetDid() OptString {
return s.Did
}
// GetCreatedAt returns the value of CreatedAt. // GetCreatedAt returns the value of CreatedAt.
func (s *UserUpdate) GetCreatedAt() OptDateTime { func (s *UserUpdate) GetCreatedAt() OptDateTime {
return s.CreatedAt return s.CreatedAt
@ -1475,6 +1547,11 @@ func (s *UserUpdate) SetUsername(val string) {
s.Username = val s.Username = val
} }
// SetDid sets the value of Did.
func (s *UserUpdate) SetDid(val OptString) {
s.Did = val
}
// SetCreatedAt sets the value of CreatedAt. // SetCreatedAt sets the value of CreatedAt.
func (s *UserUpdate) SetCreatedAt(val OptDateTime) { func (s *UserUpdate) SetCreatedAt(val OptDateTime) {
s.CreatedAt = val s.CreatedAt = val

View File

@ -459,7 +459,11 @@ func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (Crea
} else { } else {
b.SetUsername("") b.SetUsername("")
} }
b.SetPassword(req.Password) b.SetPassword(req.Password)
if v, ok := req.Did.Get(); ok {
b.SetDid(v)
}
if v, ok := req.CreatedAt.Get(); ok { if v, ok := req.CreatedAt.Get(); ok {
b.SetCreatedAt(v) b.SetCreatedAt(v)
} }

View File

@ -139,6 +139,7 @@ func NewCardOwnerRead(e *ent.User) *CardOwnerRead {
var ret CardOwnerRead var ret CardOwnerRead
ret.ID = e.ID ret.ID = e.ID
ret.Username = e.Username ret.Username = e.Username
ret.Did = NewOptString(e.Did)
ret.CreatedAt = NewOptDateTime(e.CreatedAt) ret.CreatedAt = NewOptDateTime(e.CreatedAt)
ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) ret.UpdatedAt = NewOptDateTime(e.UpdatedAt)
ret.Next = NewOptString(e.Next) ret.Next = NewOptString(e.Next)
@ -282,6 +283,7 @@ func NewGroupUsersList(e *ent.User) *GroupUsersList {
var ret GroupUsersList var ret GroupUsersList
ret.ID = e.ID ret.ID = e.ID
ret.Username = e.Username ret.Username = e.Username
ret.Did = NewOptString(e.Did)
ret.CreatedAt = NewOptDateTime(e.CreatedAt) ret.CreatedAt = NewOptDateTime(e.CreatedAt)
ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) ret.UpdatedAt = NewOptDateTime(e.UpdatedAt)
ret.Next = NewOptString(e.Next) ret.Next = NewOptString(e.Next)
@ -313,6 +315,7 @@ func NewUserCreate(e *ent.User) *UserCreate {
var ret UserCreate var ret UserCreate
ret.ID = e.ID ret.ID = e.ID
ret.Username = e.Username ret.Username = e.Username
ret.Did = NewOptString(e.Did)
ret.CreatedAt = NewOptDateTime(e.CreatedAt) ret.CreatedAt = NewOptDateTime(e.CreatedAt)
ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) ret.UpdatedAt = NewOptDateTime(e.UpdatedAt)
ret.Next = NewOptString(e.Next) ret.Next = NewOptString(e.Next)
@ -344,6 +347,7 @@ func NewUserList(e *ent.User) *UserList {
var ret UserList var ret UserList
ret.ID = e.ID ret.ID = e.ID
ret.Username = e.Username ret.Username = e.Username
ret.Did = NewOptString(e.Did)
ret.CreatedAt = NewOptDateTime(e.CreatedAt) ret.CreatedAt = NewOptDateTime(e.CreatedAt)
ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) ret.UpdatedAt = NewOptDateTime(e.UpdatedAt)
ret.Next = NewOptString(e.Next) ret.Next = NewOptString(e.Next)
@ -375,6 +379,7 @@ func NewUserRead(e *ent.User) *UserRead {
var ret UserRead var ret UserRead
ret.ID = e.ID ret.ID = e.ID
ret.Username = e.Username ret.Username = e.Username
ret.Did = NewOptString(e.Did)
ret.CreatedAt = NewOptDateTime(e.CreatedAt) ret.CreatedAt = NewOptDateTime(e.CreatedAt)
ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) ret.UpdatedAt = NewOptDateTime(e.UpdatedAt)
ret.Next = NewOptString(e.Next) ret.Next = NewOptString(e.Next)
@ -406,6 +411,7 @@ func NewUserUpdate(e *ent.User) *UserUpdate {
var ret UserUpdate var ret UserUpdate
ret.ID = e.ID ret.ID = e.ID
ret.Username = e.Username ret.Username = e.Username
ret.Did = NewOptString(e.Did)
ret.CreatedAt = NewOptDateTime(e.CreatedAt) ret.CreatedAt = NewOptDateTime(e.CreatedAt)
ret.UpdatedAt = NewOptDateTime(e.UpdatedAt) ret.UpdatedAt = NewOptDateTime(e.UpdatedAt)
ret.Next = NewOptString(e.Next) ret.Next = NewOptString(e.Next)

View File

@ -742,6 +742,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"password": { "password": {
"type": "string" "type": "string"
}, },
@ -1189,6 +1192,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"created_at": { "created_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"
@ -1300,6 +1306,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"created_at": { "created_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"
@ -1326,6 +1335,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"password": { "password": {
"type": "string" "type": "string"
}, },
@ -1362,6 +1374,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"created_at": { "created_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"
@ -1388,6 +1403,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"created_at": { "created_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"
@ -1414,6 +1432,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"created_at": { "created_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"
@ -1440,6 +1461,9 @@
"username": { "username": {
"type": "string" "type": "string"
}, },
"did": {
"type": "string"
},
"created_at": { "created_at": {
"type": "string", "type": "string",
"format": "date-time" "format": "date-time"

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[1].Descriptor() userDescPassword := userFields[2].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[2].Descriptor() userDescCreatedAt := userFields[3].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[3].Descriptor() userDescUpdatedAt := userFields[4].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[4].Descriptor() userDescNext := userFields[5].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

@ -45,6 +45,11 @@ func (Card) Fields() []ent.Field {
if card == 15 { if card == 15 {
card = 1 card = 1
} }
// 2023/04/13 premium card id:16
if card == 16 {
card = 1
}
return card return card
}). }).
Optional(), Optional(),

View File

@ -31,19 +31,19 @@ func (User) Fields() []ent.Field {
field.String("username"). field.String("username").
NotEmpty(). NotEmpty().
Immutable(). Immutable().
MaxLen(30). MaxLen(100).
//Match(regexp.MustCompile("[a-z]+$")). //Match(regexp.MustCompile("[a-z]+$")).
Unique(), Unique(),
field.String("did").
Optional().
Immutable(),
field.String("password"). field.String("password").
NotEmpty(). NotEmpty().
Immutable(). Immutable().
Sensitive(), Sensitive(),
//field.Bool("limit").
//Optional().
//Default(false),
field.Time("created_at"). field.Time("created_at").
Immutable(). Immutable().
Optional(). Optional().

View File

@ -18,6 +18,8 @@ type User struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// Username holds the value of the "username" field. // Username holds the value of the "username" field.
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
// Did holds the value of the "did" field.
Did string `json:"did,omitempty"`
// 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.
@ -57,7 +59,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.FieldPassword, user.FieldNext: case user.FieldUsername, user.FieldDid, 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)
@ -90,6 +92,12 @@ func (u *User) assignValues(columns []string, values []any) error {
} else if value.Valid { } else if value.Valid {
u.Username = value.String u.Username = value.String
} }
case user.FieldDid:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field did", values[i])
} else if value.Valid {
u.Did = 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])
@ -157,6 +165,9 @@ func (u *User) String() string {
builder.WriteString("username=") builder.WriteString("username=")
builder.WriteString(u.Username) builder.WriteString(u.Username)
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("did=")
builder.WriteString(u.Did)
builder.WriteString(", ")
builder.WriteString("password=<sensitive>") builder.WriteString("password=<sensitive>")
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")

View File

@ -13,6 +13,8 @@ const (
FieldID = "id" FieldID = "id"
// FieldUsername holds the string denoting the username field in the database. // FieldUsername holds the string denoting the username field in the database.
FieldUsername = "username" FieldUsername = "username"
// FieldDid holds the string denoting the did field in the database.
FieldDid = "did"
// 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.
@ -38,6 +40,7 @@ const (
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldUsername, FieldUsername,
FieldDid,
FieldPassword, FieldPassword,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,

View File

@ -60,6 +60,11 @@ func Username(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldUsername, v)) return predicate.User(sql.FieldEQ(FieldUsername, v))
} }
// Did applies equality check predicate on the "did" field. It's identical to DidEQ.
func Did(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldDid, 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))
@ -145,6 +150,81 @@ func UsernameContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldUsername, v)) return predicate.User(sql.FieldContainsFold(FieldUsername, v))
} }
// DidEQ applies the EQ predicate on the "did" field.
func DidEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldDid, v))
}
// DidNEQ applies the NEQ predicate on the "did" field.
func DidNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldDid, v))
}
// DidIn applies the In predicate on the "did" field.
func DidIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldDid, vs...))
}
// DidNotIn applies the NotIn predicate on the "did" field.
func DidNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldDid, vs...))
}
// DidGT applies the GT predicate on the "did" field.
func DidGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldDid, v))
}
// DidGTE applies the GTE predicate on the "did" field.
func DidGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldDid, v))
}
// DidLT applies the LT predicate on the "did" field.
func DidLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldDid, v))
}
// DidLTE applies the LTE predicate on the "did" field.
func DidLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldDid, v))
}
// DidContains applies the Contains predicate on the "did" field.
func DidContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldDid, v))
}
// DidHasPrefix applies the HasPrefix predicate on the "did" field.
func DidHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldDid, v))
}
// DidHasSuffix applies the HasSuffix predicate on the "did" field.
func DidHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldDid, v))
}
// DidIsNil applies the IsNil predicate on the "did" field.
func DidIsNil() predicate.User {
return predicate.User(sql.FieldIsNull(FieldDid))
}
// DidNotNil applies the NotNil predicate on the "did" field.
func DidNotNil() predicate.User {
return predicate.User(sql.FieldNotNull(FieldDid))
}
// DidEqualFold applies the EqualFold predicate on the "did" field.
func DidEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldDid, v))
}
// DidContainsFold applies the ContainsFold predicate on the "did" field.
func DidContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldDid, 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

@ -27,6 +27,20 @@ func (uc *UserCreate) SetUsername(s string) *UserCreate {
return uc return uc
} }
// SetDid sets the "did" field.
func (uc *UserCreate) SetDid(s string) *UserCreate {
uc.mutation.SetDid(s)
return uc
}
// SetNillableDid sets the "did" field if the given value is not nil.
func (uc *UserCreate) SetNillableDid(s *string) *UserCreate {
if s != nil {
uc.SetDid(*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)
@ -187,6 +201,10 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec.SetField(user.FieldUsername, field.TypeString, value) _spec.SetField(user.FieldUsername, field.TypeString, value)
_node.Username = value _node.Username = value
} }
if value, ok := uc.mutation.Did(); ok {
_spec.SetField(user.FieldDid, field.TypeString, value)
_node.Did = 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

@ -146,6 +146,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
} }
} }
} }
if uu.mutation.DidCleared() {
_spec.ClearField(user.FieldDid, field.TypeString)
}
if uu.mutation.CreatedAtCleared() { if uu.mutation.CreatedAtCleared() {
_spec.ClearField(user.FieldCreatedAt, field.TypeTime) _spec.ClearField(user.FieldCreatedAt, field.TypeTime)
} }
@ -373,6 +376,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
} }
} }
} }
if uuo.mutation.DidCleared() {
_spec.ClearField(user.FieldDid, field.TypeString)
}
if uuo.mutation.CreatedAtCleared() { if uuo.mutation.CreatedAtCleared() {
_spec.ClearField(user.FieldCreatedAt, field.TypeTime) _spec.ClearField(user.FieldCreatedAt, field.TypeTime)
} }

View File

@ -52,8 +52,7 @@ func (h handler) DrawDone(ctx context.Context, params ogent.DrawDoneParams) erro
func main() { func main() {
// Create ent client. // Create ent client.
client, err := ent.Open(dialect.SQLite, "file:/data/new.sqlite?_fk=1") client, err := ent.Open(dialect.SQLite, "file:/data/new.sqlite?_fk=1")
//client, err := ent.Open(dialect.SQLite, "file:data/ent.sqlite?_fk=1") //client, err := ent.Open(dialect.SQLite, "file:data/new.sqlite?_fk=1")
//client, err := ent.Open(dialect.SQLite, "file:/data/ent.sqlite?_fk=1")
//client, err := ent.Open(dialect.SQLite, "file:data?mode=memory&cache=shared&_fk=1") //client, err := ent.Open(dialect.SQLite, "file:data?mode=memory&cache=shared&_fk=1")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

3
run.zsh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/zsh
d=${0:a:h}
PASS=`cat token.json|jq -r .password` go run -mod=mod main.go

View File

@ -7,15 +7,32 @@ host_users="$host/users?itemsPerPage=255"
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`
host_at=bsky.social
if [ -f $d/user.json ] && [ "$1" = "-s" ];then
rm $d/user.json
fi
function did() {
unset did
url="https://$host_at/xrpc/com.atproto.repo.listRecords?repo=${name}.${host_at}&collection=app.bsky.actor.profile"
if [ "`curl -sL $url| jq -r .error`" = "null" ];then
t=`curl -sL $url | jq -r ".records|.[]|.uri"|cut -d / -f 3`
did=$t
else
#did=`curl -sL "search.bsky.social/search/posts?q=$name" | jq -r ".[0].user.did"`
did="null"
fi
echo "{\"name\":\"$name\",\"did\":\"$did\"}," >> $d/user.json
}
function l_users() { function l_users() {
curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"$name\",\"password\":\"$pass\"}" $api/users curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"$name\",\"password\":\"$pass\",\"did\":\"$did\"}" $api/users
sleep 1 #sleep 1
} }
function l_cards() { function l_cards() {
curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id,\"card\":$card,\"status\":\"$s\",\"cp\":$cp,\"password\":\"$pass\"}" $api/cards curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id,\"card\":$card,\"status\":\"$s\",\"cp\":$cp,\"password\":\"$pass\"}" $api/cards
sleep 1 #sleep 1
} }
data=`curl -sL "$host_users"|jq .` data=`curl -sL "$host_users"|jq .`
@ -26,7 +43,17 @@ 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`
echo "{\"username\":\"$name\"} localhost:8080/users" if [ "$1" = "-s" ];then
did
else
did=`cat $d/user.json|jq -r ".[]|select(.name == \"$name\")|.did"`
fi
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
@ -35,15 +62,16 @@ do
nn=`echo $data_card|jq length` nn=`echo $data_card|jq length`
nn=$((nn - 1)) nn=$((nn - 1))
for ((ii=0;ii<=$nn;ii++)) if [ "$1" != "-s" ];then
do for ((ii=0;ii<=$nn;ii++))
card=`echo $data_card|jq -r ".[$ii].card"` do
s=`echo $data_card|jq -r ".[$ii].status"` card=`echo $data_card|jq -r ".[$ii].card"`
cp=`echo $data_card|jq -r ".[$ii].cp"` s=`echo $data_card|jq -r ".[$ii].status"`
echo "{\"owner\":$id,\"card\":\"$card\",\"status\":\"$s\",\"cp\":\"$cp\"} localhost:8080/cards" cp=`echo $data_card|jq -r ".[$ii].cp"`
if [ "$1" = "-a" ];then echo "{\"owner\":$id,\"card\":\"$card\",\"status\":\"$s\",\"cp\":\"$cp\", \"password\":\"$pass\"} localhost:8080/cards"
l_cards if [ "$1" = "-a" ];then
fi l_cards
done fi
done
fi
done done

View File

@ -459,7 +459,11 @@ func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (Crea
} else { } else {
b.SetUsername("") b.SetUsername("")
} }
b.SetPassword(req.Password) b.SetPassword(req.Password)
if v, ok := req.Did.Get(); ok {
b.SetDid(v)
}
if v, ok := req.CreatedAt.Get(); ok { if v, ok := req.CreatedAt.Get(); ok {
b.SetCreatedAt(v) b.SetCreatedAt(v)
} }