From a75c7d4fbd126b88e0accaac6af3df36724e5732 Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Fri, 22 Mar 2024 10:35:38 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20Schema=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/ent/migrate/schema.go | 11 +- .../domain/repository/ent/mutation.go | 437 +++--------------- .../domain/repository/ent/runtime.go | 62 +-- .../domain/repository/ent/schema/score.go | 4 +- .../domain/repository/ent/schema/user.go | 9 +- typing-server/domain/repository/ent/score.go | 40 +- .../domain/repository/ent/score/score.go | 28 +- .../domain/repository/ent/score/where.go | 144 ++---- .../domain/repository/ent/score_create.go | 42 +- .../domain/repository/ent/score_update.go | 120 +---- typing-server/domain/repository/ent/user.go | 49 +- .../domain/repository/ent/user/user.go | 69 +-- .../domain/repository/ent/user/where.go | 244 ++-------- .../domain/repository/ent/user_create.go | 76 +-- .../domain/repository/ent/user_query.go | 8 +- .../domain/repository/ent/user_update.go | 176 +------ 16 files changed, 243 insertions(+), 1276 deletions(-) diff --git a/typing-server/domain/repository/ent/migrate/schema.go b/typing-server/domain/repository/ent/migrate/schema.go index de61978..d0fa83f 100644 --- a/typing-server/domain/repository/ent/migrate/schema.go +++ b/typing-server/domain/repository/ent/migrate/schema.go @@ -13,9 +13,7 @@ var ( {Name: "id", Type: field.TypeUUID, Unique: true}, {Name: "keystrokes", Type: field.TypeInt}, {Name: "accuracy", Type: field.TypeFloat64}, - {Name: "score", Type: field.TypeFloat64}, - {Name: "started_at", Type: field.TypeTime}, - {Name: "ended_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, {Name: "user_scores", Type: field.TypeUUID, Nullable: true}, } // ScoresTable holds the schema information for the "scores" table. @@ -26,7 +24,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "scores_users_scores", - Columns: []*schema.Column{ScoresColumns[6]}, + Columns: []*schema.Column{ScoresColumns[4]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, @@ -35,11 +33,8 @@ var ( // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, - {Name: "mail_adress", Type: field.TypeString, Size: 255}, + {Name: "student_number", Type: field.TypeString, Unique: true}, {Name: "handle_name", Type: field.TypeString, Size: 36}, - {Name: "name", Type: field.TypeString, Size: 36}, - {Name: "hashed_password", Type: field.TypeString, Size: 255}, - {Name: "department", Type: field.TypeEnum, Enums: []string{"CS", "BI", "IA"}}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, } diff --git a/typing-server/domain/repository/ent/mutation.go b/typing-server/domain/repository/ent/mutation.go index ab90132..1f505a9 100644 --- a/typing-server/domain/repository/ent/mutation.go +++ b/typing-server/domain/repository/ent/mutation.go @@ -40,10 +40,7 @@ type ScoreMutation struct { addkeystrokes *int accuracy *float64 addaccuracy *float64 - score *float64 - addscore *float64 - startedAt *time.Time - endedAt *time.Time + createdAt *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Score, error) @@ -266,132 +263,40 @@ func (m *ScoreMutation) ResetAccuracy() { m.addaccuracy = nil } -// SetScore sets the "score" field. -func (m *ScoreMutation) SetScore(f float64) { - m.score = &f - m.addscore = nil +// SetCreatedAt sets the "createdAt" field. +func (m *ScoreMutation) SetCreatedAt(t time.Time) { + m.createdAt = &t } -// Score returns the value of the "score" field in the mutation. -func (m *ScoreMutation) Score() (r float64, exists bool) { - v := m.score +// CreatedAt returns the value of the "createdAt" field in the mutation. +func (m *ScoreMutation) CreatedAt() (r time.Time, exists bool) { + v := m.createdAt if v == nil { return } return *v, true } -// OldScore returns the old "score" field's value of the Score entity. +// OldCreatedAt returns the old "createdAt" field's value of the Score entity. // If the Score 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 *ScoreMutation) OldScore(ctx context.Context) (v float64, err error) { +func (m *ScoreMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldScore is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldScore requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldScore: %w", err) - } - return oldValue.Score, nil -} - -// AddScore adds f to the "score" field. -func (m *ScoreMutation) AddScore(f float64) { - if m.addscore != nil { - *m.addscore += f - } else { - m.addscore = &f - } -} - -// AddedScore returns the value that was added to the "score" field in this mutation. -func (m *ScoreMutation) AddedScore() (r float64, exists bool) { - v := m.addscore - if v == nil { - return - } - return *v, true -} - -// ResetScore resets all changes to the "score" field. -func (m *ScoreMutation) ResetScore() { - m.score = nil - m.addscore = nil -} - -// SetStartedAt sets the "startedAt" field. -func (m *ScoreMutation) SetStartedAt(t time.Time) { - m.startedAt = &t -} - -// StartedAt returns the value of the "startedAt" field in the mutation. -func (m *ScoreMutation) StartedAt() (r time.Time, exists bool) { - v := m.startedAt - if v == nil { - return - } - return *v, true -} - -// OldStartedAt returns the old "startedAt" field's value of the Score entity. -// If the Score 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 *ScoreMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStartedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStartedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldStartedAt: %w", err) - } - return oldValue.StartedAt, nil -} - -// ResetStartedAt resets all changes to the "startedAt" field. -func (m *ScoreMutation) ResetStartedAt() { - m.startedAt = nil -} - -// SetEndedAt sets the "endedAt" field. -func (m *ScoreMutation) SetEndedAt(t time.Time) { - m.endedAt = &t -} - -// EndedAt returns the value of the "endedAt" field in the mutation. -func (m *ScoreMutation) EndedAt() (r time.Time, exists bool) { - v := m.endedAt - if v == nil { - return - } - return *v, true -} - -// OldEndedAt returns the old "endedAt" field's value of the Score entity. -// If the Score 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 *ScoreMutation) OldEndedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldEndedAt is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldEndedAt requires an ID field in the mutation") + return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldEndedAt: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.EndedAt, nil + return oldValue.CreatedAt, nil } -// ResetEndedAt resets all changes to the "endedAt" field. -func (m *ScoreMutation) ResetEndedAt() { - m.endedAt = nil +// ResetCreatedAt resets all changes to the "createdAt" field. +func (m *ScoreMutation) ResetCreatedAt() { + m.createdAt = nil } // Where appends a list predicates to the ScoreMutation builder. @@ -428,21 +333,15 @@ func (m *ScoreMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ScoreMutation) Fields() []string { - fields := make([]string, 0, 5) + fields := make([]string, 0, 3) if m.keystrokes != nil { fields = append(fields, score.FieldKeystrokes) } if m.accuracy != nil { fields = append(fields, score.FieldAccuracy) } - if m.score != nil { - fields = append(fields, score.FieldScore) - } - if m.startedAt != nil { - fields = append(fields, score.FieldStartedAt) - } - if m.endedAt != nil { - fields = append(fields, score.FieldEndedAt) + if m.createdAt != nil { + fields = append(fields, score.FieldCreatedAt) } return fields } @@ -456,12 +355,8 @@ func (m *ScoreMutation) Field(name string) (ent.Value, bool) { return m.Keystrokes() case score.FieldAccuracy: return m.Accuracy() - case score.FieldScore: - return m.Score() - case score.FieldStartedAt: - return m.StartedAt() - case score.FieldEndedAt: - return m.EndedAt() + case score.FieldCreatedAt: + return m.CreatedAt() } return nil, false } @@ -475,12 +370,8 @@ func (m *ScoreMutation) OldField(ctx context.Context, name string) (ent.Value, e return m.OldKeystrokes(ctx) case score.FieldAccuracy: return m.OldAccuracy(ctx) - case score.FieldScore: - return m.OldScore(ctx) - case score.FieldStartedAt: - return m.OldStartedAt(ctx) - case score.FieldEndedAt: - return m.OldEndedAt(ctx) + case score.FieldCreatedAt: + return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown Score field %s", name) } @@ -504,26 +395,12 @@ func (m *ScoreMutation) SetField(name string, value ent.Value) error { } m.SetAccuracy(v) return nil - case score.FieldScore: - v, ok := value.(float64) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetScore(v) - return nil - case score.FieldStartedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetStartedAt(v) - return nil - case score.FieldEndedAt: + case score.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetEndedAt(v) + m.SetCreatedAt(v) return nil } return fmt.Errorf("unknown Score field %s", name) @@ -539,9 +416,6 @@ func (m *ScoreMutation) AddedFields() []string { if m.addaccuracy != nil { fields = append(fields, score.FieldAccuracy) } - if m.addscore != nil { - fields = append(fields, score.FieldScore) - } return fields } @@ -554,8 +428,6 @@ func (m *ScoreMutation) AddedField(name string) (ent.Value, bool) { return m.AddedKeystrokes() case score.FieldAccuracy: return m.AddedAccuracy() - case score.FieldScore: - return m.AddedScore() } return nil, false } @@ -579,13 +451,6 @@ func (m *ScoreMutation) AddField(name string, value ent.Value) error { } m.AddAccuracy(v) return nil - case score.FieldScore: - v, ok := value.(float64) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddScore(v) - return nil } return fmt.Errorf("unknown Score numeric field %s", name) } @@ -619,14 +484,8 @@ func (m *ScoreMutation) ResetField(name string) error { case score.FieldAccuracy: m.ResetAccuracy() return nil - case score.FieldScore: - m.ResetScore() - return nil - case score.FieldStartedAt: - m.ResetStartedAt() - return nil - case score.FieldEndedAt: - m.ResetEndedAt() + case score.FieldCreatedAt: + m.ResetCreatedAt() return nil } return fmt.Errorf("unknown Score field %s", name) @@ -683,23 +542,20 @@ func (m *ScoreMutation) ResetEdge(name string) error { // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config - op Op - typ string - id *uuid.UUID - _MailAdress *string - _HandleName *string - _Name *string - _HashedPassword *string - _Department *user.Department - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - scores map[uuid.UUID]struct{} - removedscores map[uuid.UUID]struct{} - clearedscores bool - done bool - oldValue func(context.Context) (*User, error) - predicates []predicate.User + op Op + typ string + id *uuid.UUID + _StudentNumber *string + _HandleName *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + scores map[uuid.UUID]struct{} + removedscores map[uuid.UUID]struct{} + clearedscores bool + done bool + oldValue func(context.Context) (*User, error) + predicates []predicate.User } var _ ent.Mutation = (*UserMutation)(nil) @@ -806,40 +662,40 @@ func (m *UserMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { } } -// SetMailAdress sets the "MailAdress" field. -func (m *UserMutation) SetMailAdress(s string) { - m._MailAdress = &s +// SetStudentNumber sets the "StudentNumber" field. +func (m *UserMutation) SetStudentNumber(s string) { + m._StudentNumber = &s } -// MailAdress returns the value of the "MailAdress" field in the mutation. -func (m *UserMutation) MailAdress() (r string, exists bool) { - v := m._MailAdress +// StudentNumber returns the value of the "StudentNumber" field in the mutation. +func (m *UserMutation) StudentNumber() (r string, exists bool) { + v := m._StudentNumber if v == nil { return } return *v, true } -// OldMailAdress returns the old "MailAdress" field's value of the User entity. +// OldStudentNumber returns the old "StudentNumber" 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) OldMailAdress(ctx context.Context) (v string, err error) { +func (m *UserMutation) OldStudentNumber(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldMailAdress is only allowed on UpdateOne operations") + return v, errors.New("OldStudentNumber is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldMailAdress requires an ID field in the mutation") + return v, errors.New("OldStudentNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldMailAdress: %w", err) + return v, fmt.Errorf("querying old value for OldStudentNumber: %w", err) } - return oldValue.MailAdress, nil + return oldValue.StudentNumber, nil } -// ResetMailAdress resets all changes to the "MailAdress" field. -func (m *UserMutation) ResetMailAdress() { - m._MailAdress = nil +// ResetStudentNumber resets all changes to the "StudentNumber" field. +func (m *UserMutation) ResetStudentNumber() { + m._StudentNumber = nil } // SetHandleName sets the "HandleName" field. @@ -878,114 +734,6 @@ func (m *UserMutation) ResetHandleName() { m._HandleName = nil } -// SetName sets the "Name" field. -func (m *UserMutation) SetName(s string) { - m._Name = &s -} - -// Name returns the value of the "Name" field in the mutation. -func (m *UserMutation) Name() (r string, exists bool) { - v := m._Name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "Name" 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) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "Name" field. -func (m *UserMutation) ResetName() { - m._Name = nil -} - -// SetHashedPassword sets the "HashedPassword" field. -func (m *UserMutation) SetHashedPassword(s string) { - m._HashedPassword = &s -} - -// HashedPassword returns the value of the "HashedPassword" field in the mutation. -func (m *UserMutation) HashedPassword() (r string, exists bool) { - v := m._HashedPassword - if v == nil { - return - } - return *v, true -} - -// OldHashedPassword returns the old "HashedPassword" 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) OldHashedPassword(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldHashedPassword is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldHashedPassword requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldHashedPassword: %w", err) - } - return oldValue.HashedPassword, nil -} - -// ResetHashedPassword resets all changes to the "HashedPassword" field. -func (m *UserMutation) ResetHashedPassword() { - m._HashedPassword = nil -} - -// SetDepartment sets the "Department" field. -func (m *UserMutation) SetDepartment(u user.Department) { - m._Department = &u -} - -// Department returns the value of the "Department" field in the mutation. -func (m *UserMutation) Department() (r user.Department, exists bool) { - v := m._Department - if v == nil { - return - } - return *v, true -} - -// OldDepartment returns the old "Department" 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) OldDepartment(ctx context.Context) (v user.Department, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDepartment is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDepartment requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDepartment: %w", err) - } - return oldValue.Department, nil -} - -// ResetDepartment resets all changes to the "Department" field. -func (m *UserMutation) ResetDepartment() { - m._Department = nil -} - // SetCreatedAt sets the "created_at" field. func (m *UserMutation) SetCreatedAt(t time.Time) { m.created_at = &t @@ -1146,22 +894,13 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 7) - if m._MailAdress != nil { - fields = append(fields, user.FieldMailAdress) + fields := make([]string, 0, 4) + if m._StudentNumber != nil { + fields = append(fields, user.FieldStudentNumber) } if m._HandleName != nil { fields = append(fields, user.FieldHandleName) } - if m._Name != nil { - fields = append(fields, user.FieldName) - } - if m._HashedPassword != nil { - fields = append(fields, user.FieldHashedPassword) - } - if m._Department != nil { - fields = append(fields, user.FieldDepartment) - } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } @@ -1176,16 +915,10 @@ func (m *UserMutation) Fields() []string { // schema. func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { - case user.FieldMailAdress: - return m.MailAdress() + case user.FieldStudentNumber: + return m.StudentNumber() case user.FieldHandleName: return m.HandleName() - case user.FieldName: - return m.Name() - case user.FieldHashedPassword: - return m.HashedPassword() - case user.FieldDepartment: - return m.Department() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: @@ -1199,16 +932,10 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case user.FieldMailAdress: - return m.OldMailAdress(ctx) + case user.FieldStudentNumber: + return m.OldStudentNumber(ctx) case user.FieldHandleName: return m.OldHandleName(ctx) - case user.FieldName: - return m.OldName(ctx) - case user.FieldHashedPassword: - return m.OldHashedPassword(ctx) - case user.FieldDepartment: - return m.OldDepartment(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: @@ -1222,12 +949,12 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er // type. func (m *UserMutation) SetField(name string, value ent.Value) error { switch name { - case user.FieldMailAdress: + case user.FieldStudentNumber: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetMailAdress(v) + m.SetStudentNumber(v) return nil case user.FieldHandleName: v, ok := value.(string) @@ -1236,27 +963,6 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetHandleName(v) return nil - case user.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case user.FieldHashedPassword: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetHashedPassword(v) - return nil - case user.FieldDepartment: - v, ok := value.(user.Department) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDepartment(v) - return nil case user.FieldCreatedAt: v, ok := value.(time.Time) if !ok { @@ -1320,21 +1026,12 @@ func (m *UserMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *UserMutation) ResetField(name string) error { switch name { - case user.FieldMailAdress: - m.ResetMailAdress() + case user.FieldStudentNumber: + m.ResetStudentNumber() return nil case user.FieldHandleName: m.ResetHandleName() return nil - case user.FieldName: - m.ResetName() - return nil - case user.FieldHashedPassword: - m.ResetHashedPassword() - return nil - case user.FieldDepartment: - m.ResetDepartment() - return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil diff --git a/typing-server/domain/repository/ent/runtime.go b/typing-server/domain/repository/ent/runtime.go index 46ed455..7ac9c43 100644 --- a/typing-server/domain/repository/ent/runtime.go +++ b/typing-server/domain/repository/ent/runtime.go @@ -23,24 +23,10 @@ func init() { score.DefaultID = scoreDescID.Default.(func() uuid.UUID) userFields := schema.User{}.Fields() _ = userFields - // userDescMailAdress is the schema descriptor for MailAdress field. - userDescMailAdress := userFields[1].Descriptor() - // user.MailAdressValidator is a validator for the "MailAdress" field. It is called by the builders before save. - user.MailAdressValidator = func() func(string) error { - validators := userDescMailAdress.Validators - fns := [...]func(string) error{ - validators[0].(func(string) error), - validators[1].(func(string) error), - } - return func(_MailAdress string) error { - for _, fn := range fns { - if err := fn(_MailAdress); err != nil { - return err - } - } - return nil - } - }() + // userDescStudentNumber is the schema descriptor for StudentNumber field. + userDescStudentNumber := userFields[1].Descriptor() + // user.StudentNumberValidator is a validator for the "StudentNumber" field. It is called by the builders before save. + user.StudentNumberValidator = userDescStudentNumber.Validators[0].(func(string) error) // userDescHandleName is the schema descriptor for HandleName field. userDescHandleName := userFields[2].Descriptor() // user.HandleNameValidator is a validator for the "HandleName" field. It is called by the builders before save. @@ -59,48 +45,12 @@ func init() { return nil } }() - // userDescName is the schema descriptor for Name field. - userDescName := userFields[3].Descriptor() - // user.NameValidator is a validator for the "Name" field. It is called by the builders before save. - user.NameValidator = func() func(string) error { - validators := userDescName.Validators - fns := [...]func(string) error{ - validators[0].(func(string) error), - validators[1].(func(string) error), - } - return func(_Name string) error { - for _, fn := range fns { - if err := fn(_Name); err != nil { - return err - } - } - return nil - } - }() - // userDescHashedPassword is the schema descriptor for HashedPassword field. - userDescHashedPassword := userFields[4].Descriptor() - // user.HashedPasswordValidator is a validator for the "HashedPassword" field. It is called by the builders before save. - user.HashedPasswordValidator = func() func(string) error { - validators := userDescHashedPassword.Validators - fns := [...]func(string) error{ - validators[0].(func(string) error), - validators[1].(func(string) error), - } - return func(_HashedPassword string) error { - for _, fn := range fns { - if err := fn(_HashedPassword); err != nil { - return err - } - } - return nil - } - }() // userDescCreatedAt is the schema descriptor for created_at field. - userDescCreatedAt := userFields[6].Descriptor() + userDescCreatedAt := userFields[3].Descriptor() // user.DefaultCreatedAt holds the default value on creation for the created_at field. user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time) // userDescUpdatedAt is the schema descriptor for updated_at field. - userDescUpdatedAt := userFields[7].Descriptor() + userDescUpdatedAt := userFields[4].Descriptor() // user.DefaultUpdatedAt holds the default value on creation for the updated_at field. user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time) // user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. diff --git a/typing-server/domain/repository/ent/schema/score.go b/typing-server/domain/repository/ent/schema/score.go index 9fc7a07..b01a954 100644 --- a/typing-server/domain/repository/ent/schema/score.go +++ b/typing-server/domain/repository/ent/schema/score.go @@ -16,8 +16,6 @@ func (Score) Fields() []ent.Field { field.UUID("id", uuid.UUID{}).Default(uuid.New).StorageKey("id").Unique(), field.Int("keystrokes"), field.Float("accuracy"), - field.Float("score").Comment("スコアはaccuracyとkeystrokesの積で計算される"), - field.Time("startedAt"), - field.Time("endedAt"), + field.Time("createdAt"), } } diff --git a/typing-server/domain/repository/ent/schema/user.go b/typing-server/domain/repository/ent/schema/user.go index 43baa7d..b4a949d 100644 --- a/typing-server/domain/repository/ent/schema/user.go +++ b/typing-server/domain/repository/ent/schema/user.go @@ -19,11 +19,12 @@ func (User) Fields() []ent.Field { //カラムとしてvarcher型(255)のMailAdress,varcher型(255)のHandleName,varcher型(255)のName,varcher型(255)のHashedPassword,enum型のDepartment,datetime型のCreatedAt,datetime型のUpdatedAtを持たせる return []ent.Field{ field.UUID("id", uuid.UUID{}).Default(uuid.New).StorageKey("id").Unique(), - field.String("MailAdress").NotEmpty().MaxLen(255), + field.String("StudentNumber").NotEmpty().Unique(), + // field.String("MailAdress").NotEmpty().MaxLen(255), field.String("HandleName").NotEmpty().MaxLen(36), - field.String("Name").NotEmpty().MaxLen(36), - field.String("HashedPassword").NotEmpty().MaxLen(255), - field.Enum("Department").Values("CS", "BI", "IA"), + // field.String("Name").NotEmpty().MaxLen(36), + // field.String("HashedPassword").NotEmpty().MaxLen(255), + // field.Enum("Department").Values("CS", "BI", "IA"), field.Time("created_at").Immutable().Default(time.Now), field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), } diff --git a/typing-server/domain/repository/ent/score.go b/typing-server/domain/repository/ent/score.go index feedf18..927b8b1 100644 --- a/typing-server/domain/repository/ent/score.go +++ b/typing-server/domain/repository/ent/score.go @@ -22,12 +22,8 @@ type Score struct { Keystrokes int `json:"keystrokes,omitempty"` // Accuracy holds the value of the "accuracy" field. Accuracy float64 `json:"accuracy,omitempty"` - // スコアはaccuracyとkeystrokesの積で計算される - Score float64 `json:"score,omitempty"` - // StartedAt holds the value of the "startedAt" field. - StartedAt time.Time `json:"startedAt,omitempty"` - // EndedAt holds the value of the "endedAt" field. - EndedAt time.Time `json:"endedAt,omitempty"` + // CreatedAt holds the value of the "createdAt" field. + CreatedAt time.Time `json:"createdAt,omitempty"` user_scores *uuid.UUID selectValues sql.SelectValues } @@ -37,11 +33,11 @@ func (*Score) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case score.FieldAccuracy, score.FieldScore: + case score.FieldAccuracy: values[i] = new(sql.NullFloat64) case score.FieldKeystrokes: values[i] = new(sql.NullInt64) - case score.FieldStartedAt, score.FieldEndedAt: + case score.FieldCreatedAt: values[i] = new(sql.NullTime) case score.FieldID: values[i] = new(uuid.UUID) @@ -80,23 +76,11 @@ func (s *Score) assignValues(columns []string, values []any) error { } else if value.Valid { s.Accuracy = value.Float64 } - case score.FieldScore: - if value, ok := values[i].(*sql.NullFloat64); !ok { - return fmt.Errorf("unexpected type %T for field score", values[i]) - } else if value.Valid { - s.Score = value.Float64 - } - case score.FieldStartedAt: + case score.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field startedAt", values[i]) + return fmt.Errorf("unexpected type %T for field createdAt", values[i]) } else if value.Valid { - s.StartedAt = value.Time - } - case score.FieldEndedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field endedAt", values[i]) - } else if value.Valid { - s.EndedAt = value.Time + s.CreatedAt = value.Time } case score.ForeignKeys[0]: if value, ok := values[i].(*sql.NullScanner); !ok { @@ -147,14 +131,8 @@ func (s *Score) String() string { builder.WriteString("accuracy=") builder.WriteString(fmt.Sprintf("%v", s.Accuracy)) builder.WriteString(", ") - builder.WriteString("score=") - builder.WriteString(fmt.Sprintf("%v", s.Score)) - builder.WriteString(", ") - builder.WriteString("startedAt=") - builder.WriteString(s.StartedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("endedAt=") - builder.WriteString(s.EndedAt.Format(time.ANSIC)) + builder.WriteString("createdAt=") + builder.WriteString(s.CreatedAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } diff --git a/typing-server/domain/repository/ent/score/score.go b/typing-server/domain/repository/ent/score/score.go index c00a12d..a880202 100644 --- a/typing-server/domain/repository/ent/score/score.go +++ b/typing-server/domain/repository/ent/score/score.go @@ -16,12 +16,8 @@ const ( FieldKeystrokes = "keystrokes" // FieldAccuracy holds the string denoting the accuracy field in the database. FieldAccuracy = "accuracy" - // FieldScore holds the string denoting the score field in the database. - FieldScore = "score" - // FieldStartedAt holds the string denoting the startedat field in the database. - FieldStartedAt = "started_at" - // FieldEndedAt holds the string denoting the endedat field in the database. - FieldEndedAt = "ended_at" + // FieldCreatedAt holds the string denoting the createdat field in the database. + FieldCreatedAt = "created_at" // Table holds the table name of the score in the database. Table = "scores" ) @@ -31,9 +27,7 @@ var Columns = []string{ FieldID, FieldKeystrokes, FieldAccuracy, - FieldScore, - FieldStartedAt, - FieldEndedAt, + FieldCreatedAt, } // ForeignKeys holds the SQL foreign-keys that are owned by the "scores" @@ -80,17 +74,7 @@ func ByAccuracy(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldAccuracy, opts...).ToFunc() } -// ByScore orders the results by the score field. -func ByScore(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldScore, opts...).ToFunc() -} - -// ByStartedAt orders the results by the startedAt field. -func ByStartedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldStartedAt, opts...).ToFunc() -} - -// ByEndedAt orders the results by the endedAt field. -func ByEndedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldEndedAt, opts...).ToFunc() +// ByCreatedAt orders the results by the createdAt field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() } diff --git a/typing-server/domain/repository/ent/score/where.go b/typing-server/domain/repository/ent/score/where.go index 2ba1440..6d1618d 100644 --- a/typing-server/domain/repository/ent/score/where.go +++ b/typing-server/domain/repository/ent/score/where.go @@ -65,19 +65,9 @@ func Accuracy(v float64) predicate.Score { return predicate.Score(sql.FieldEQ(FieldAccuracy, v)) } -// Score applies equality check predicate on the "score" field. It's identical to ScoreEQ. -func Score(v float64) predicate.Score { - return predicate.Score(sql.FieldEQ(FieldScore, v)) -} - -// StartedAt applies equality check predicate on the "startedAt" field. It's identical to StartedAtEQ. -func StartedAt(v time.Time) predicate.Score { - return predicate.Score(sql.FieldEQ(FieldStartedAt, v)) -} - -// EndedAt applies equality check predicate on the "endedAt" field. It's identical to EndedAtEQ. -func EndedAt(v time.Time) predicate.Score { - return predicate.Score(sql.FieldEQ(FieldEndedAt, v)) +// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Score { + return predicate.Score(sql.FieldEQ(FieldCreatedAt, v)) } // KeystrokesEQ applies the EQ predicate on the "keystrokes" field. @@ -160,124 +150,44 @@ func AccuracyLTE(v float64) predicate.Score { return predicate.Score(sql.FieldLTE(FieldAccuracy, v)) } -// ScoreEQ applies the EQ predicate on the "score" field. -func ScoreEQ(v float64) predicate.Score { - return predicate.Score(sql.FieldEQ(FieldScore, v)) -} - -// ScoreNEQ applies the NEQ predicate on the "score" field. -func ScoreNEQ(v float64) predicate.Score { - return predicate.Score(sql.FieldNEQ(FieldScore, v)) -} - -// ScoreIn applies the In predicate on the "score" field. -func ScoreIn(vs ...float64) predicate.Score { - return predicate.Score(sql.FieldIn(FieldScore, vs...)) -} - -// ScoreNotIn applies the NotIn predicate on the "score" field. -func ScoreNotIn(vs ...float64) predicate.Score { - return predicate.Score(sql.FieldNotIn(FieldScore, vs...)) -} - -// ScoreGT applies the GT predicate on the "score" field. -func ScoreGT(v float64) predicate.Score { - return predicate.Score(sql.FieldGT(FieldScore, v)) -} - -// ScoreGTE applies the GTE predicate on the "score" field. -func ScoreGTE(v float64) predicate.Score { - return predicate.Score(sql.FieldGTE(FieldScore, v)) -} - -// ScoreLT applies the LT predicate on the "score" field. -func ScoreLT(v float64) predicate.Score { - return predicate.Score(sql.FieldLT(FieldScore, v)) -} - -// ScoreLTE applies the LTE predicate on the "score" field. -func ScoreLTE(v float64) predicate.Score { - return predicate.Score(sql.FieldLTE(FieldScore, v)) -} - -// StartedAtEQ applies the EQ predicate on the "startedAt" field. -func StartedAtEQ(v time.Time) predicate.Score { - return predicate.Score(sql.FieldEQ(FieldStartedAt, v)) -} - -// StartedAtNEQ applies the NEQ predicate on the "startedAt" field. -func StartedAtNEQ(v time.Time) predicate.Score { - return predicate.Score(sql.FieldNEQ(FieldStartedAt, v)) -} - -// StartedAtIn applies the In predicate on the "startedAt" field. -func StartedAtIn(vs ...time.Time) predicate.Score { - return predicate.Score(sql.FieldIn(FieldStartedAt, vs...)) -} - -// StartedAtNotIn applies the NotIn predicate on the "startedAt" field. -func StartedAtNotIn(vs ...time.Time) predicate.Score { - return predicate.Score(sql.FieldNotIn(FieldStartedAt, vs...)) -} - -// StartedAtGT applies the GT predicate on the "startedAt" field. -func StartedAtGT(v time.Time) predicate.Score { - return predicate.Score(sql.FieldGT(FieldStartedAt, v)) -} - -// StartedAtGTE applies the GTE predicate on the "startedAt" field. -func StartedAtGTE(v time.Time) predicate.Score { - return predicate.Score(sql.FieldGTE(FieldStartedAt, v)) -} - -// StartedAtLT applies the LT predicate on the "startedAt" field. -func StartedAtLT(v time.Time) predicate.Score { - return predicate.Score(sql.FieldLT(FieldStartedAt, v)) -} - -// StartedAtLTE applies the LTE predicate on the "startedAt" field. -func StartedAtLTE(v time.Time) predicate.Score { - return predicate.Score(sql.FieldLTE(FieldStartedAt, v)) -} - -// EndedAtEQ applies the EQ predicate on the "endedAt" field. -func EndedAtEQ(v time.Time) predicate.Score { - return predicate.Score(sql.FieldEQ(FieldEndedAt, v)) +// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +func CreatedAtEQ(v time.Time) predicate.Score { + return predicate.Score(sql.FieldEQ(FieldCreatedAt, v)) } -// EndedAtNEQ applies the NEQ predicate on the "endedAt" field. -func EndedAtNEQ(v time.Time) predicate.Score { - return predicate.Score(sql.FieldNEQ(FieldEndedAt, v)) +// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +func CreatedAtNEQ(v time.Time) predicate.Score { + return predicate.Score(sql.FieldNEQ(FieldCreatedAt, v)) } -// EndedAtIn applies the In predicate on the "endedAt" field. -func EndedAtIn(vs ...time.Time) predicate.Score { - return predicate.Score(sql.FieldIn(FieldEndedAt, vs...)) +// CreatedAtIn applies the In predicate on the "createdAt" field. +func CreatedAtIn(vs ...time.Time) predicate.Score { + return predicate.Score(sql.FieldIn(FieldCreatedAt, vs...)) } -// EndedAtNotIn applies the NotIn predicate on the "endedAt" field. -func EndedAtNotIn(vs ...time.Time) predicate.Score { - return predicate.Score(sql.FieldNotIn(FieldEndedAt, vs...)) +// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Score { + return predicate.Score(sql.FieldNotIn(FieldCreatedAt, vs...)) } -// EndedAtGT applies the GT predicate on the "endedAt" field. -func EndedAtGT(v time.Time) predicate.Score { - return predicate.Score(sql.FieldGT(FieldEndedAt, v)) +// CreatedAtGT applies the GT predicate on the "createdAt" field. +func CreatedAtGT(v time.Time) predicate.Score { + return predicate.Score(sql.FieldGT(FieldCreatedAt, v)) } -// EndedAtGTE applies the GTE predicate on the "endedAt" field. -func EndedAtGTE(v time.Time) predicate.Score { - return predicate.Score(sql.FieldGTE(FieldEndedAt, v)) +// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +func CreatedAtGTE(v time.Time) predicate.Score { + return predicate.Score(sql.FieldGTE(FieldCreatedAt, v)) } -// EndedAtLT applies the LT predicate on the "endedAt" field. -func EndedAtLT(v time.Time) predicate.Score { - return predicate.Score(sql.FieldLT(FieldEndedAt, v)) +// CreatedAtLT applies the LT predicate on the "createdAt" field. +func CreatedAtLT(v time.Time) predicate.Score { + return predicate.Score(sql.FieldLT(FieldCreatedAt, v)) } -// EndedAtLTE applies the LTE predicate on the "endedAt" field. -func EndedAtLTE(v time.Time) predicate.Score { - return predicate.Score(sql.FieldLTE(FieldEndedAt, v)) +// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +func CreatedAtLTE(v time.Time) predicate.Score { + return predicate.Score(sql.FieldLTE(FieldCreatedAt, v)) } // And groups predicates with the AND operator between them. diff --git a/typing-server/domain/repository/ent/score_create.go b/typing-server/domain/repository/ent/score_create.go index c751671..71b4edb 100644 --- a/typing-server/domain/repository/ent/score_create.go +++ b/typing-server/domain/repository/ent/score_create.go @@ -33,21 +33,9 @@ func (sc *ScoreCreate) SetAccuracy(f float64) *ScoreCreate { return sc } -// SetScore sets the "score" field. -func (sc *ScoreCreate) SetScore(f float64) *ScoreCreate { - sc.mutation.SetScore(f) - return sc -} - -// SetStartedAt sets the "startedAt" field. -func (sc *ScoreCreate) SetStartedAt(t time.Time) *ScoreCreate { - sc.mutation.SetStartedAt(t) - return sc -} - -// SetEndedAt sets the "endedAt" field. -func (sc *ScoreCreate) SetEndedAt(t time.Time) *ScoreCreate { - sc.mutation.SetEndedAt(t) +// SetCreatedAt sets the "createdAt" field. +func (sc *ScoreCreate) SetCreatedAt(t time.Time) *ScoreCreate { + sc.mutation.SetCreatedAt(t) return sc } @@ -114,14 +102,8 @@ func (sc *ScoreCreate) check() error { if _, ok := sc.mutation.Accuracy(); !ok { return &ValidationError{Name: "accuracy", err: errors.New(`ent: missing required field "Score.accuracy"`)} } - if _, ok := sc.mutation.Score(); !ok { - return &ValidationError{Name: "score", err: errors.New(`ent: missing required field "Score.score"`)} - } - if _, ok := sc.mutation.StartedAt(); !ok { - return &ValidationError{Name: "startedAt", err: errors.New(`ent: missing required field "Score.startedAt"`)} - } - if _, ok := sc.mutation.EndedAt(); !ok { - return &ValidationError{Name: "endedAt", err: errors.New(`ent: missing required field "Score.endedAt"`)} + if _, ok := sc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "Score.createdAt"`)} } return nil } @@ -166,17 +148,9 @@ func (sc *ScoreCreate) createSpec() (*Score, *sqlgraph.CreateSpec) { _spec.SetField(score.FieldAccuracy, field.TypeFloat64, value) _node.Accuracy = value } - if value, ok := sc.mutation.Score(); ok { - _spec.SetField(score.FieldScore, field.TypeFloat64, value) - _node.Score = value - } - if value, ok := sc.mutation.StartedAt(); ok { - _spec.SetField(score.FieldStartedAt, field.TypeTime, value) - _node.StartedAt = value - } - if value, ok := sc.mutation.EndedAt(); ok { - _spec.SetField(score.FieldEndedAt, field.TypeTime, value) - _node.EndedAt = value + if value, ok := sc.mutation.CreatedAt(); ok { + _spec.SetField(score.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value } return _node, _spec } diff --git a/typing-server/domain/repository/ent/score_update.go b/typing-server/domain/repository/ent/score_update.go index 24047ff..26be882 100644 --- a/typing-server/domain/repository/ent/score_update.go +++ b/typing-server/domain/repository/ent/score_update.go @@ -70,51 +70,16 @@ func (su *ScoreUpdate) AddAccuracy(f float64) *ScoreUpdate { return su } -// SetScore sets the "score" field. -func (su *ScoreUpdate) SetScore(f float64) *ScoreUpdate { - su.mutation.ResetScore() - su.mutation.SetScore(f) +// SetCreatedAt sets the "createdAt" field. +func (su *ScoreUpdate) SetCreatedAt(t time.Time) *ScoreUpdate { + su.mutation.SetCreatedAt(t) return su } -// SetNillableScore sets the "score" field if the given value is not nil. -func (su *ScoreUpdate) SetNillableScore(f *float64) *ScoreUpdate { - if f != nil { - su.SetScore(*f) - } - return su -} - -// AddScore adds f to the "score" field. -func (su *ScoreUpdate) AddScore(f float64) *ScoreUpdate { - su.mutation.AddScore(f) - return su -} - -// SetStartedAt sets the "startedAt" field. -func (su *ScoreUpdate) SetStartedAt(t time.Time) *ScoreUpdate { - su.mutation.SetStartedAt(t) - return su -} - -// SetNillableStartedAt sets the "startedAt" field if the given value is not nil. -func (su *ScoreUpdate) SetNillableStartedAt(t *time.Time) *ScoreUpdate { +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (su *ScoreUpdate) SetNillableCreatedAt(t *time.Time) *ScoreUpdate { if t != nil { - su.SetStartedAt(*t) - } - return su -} - -// SetEndedAt sets the "endedAt" field. -func (su *ScoreUpdate) SetEndedAt(t time.Time) *ScoreUpdate { - su.mutation.SetEndedAt(t) - return su -} - -// SetNillableEndedAt sets the "endedAt" field if the given value is not nil. -func (su *ScoreUpdate) SetNillableEndedAt(t *time.Time) *ScoreUpdate { - if t != nil { - su.SetEndedAt(*t) + su.SetCreatedAt(*t) } return su } @@ -172,17 +137,8 @@ func (su *ScoreUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := su.mutation.AddedAccuracy(); ok { _spec.AddField(score.FieldAccuracy, field.TypeFloat64, value) } - if value, ok := su.mutation.Score(); ok { - _spec.SetField(score.FieldScore, field.TypeFloat64, value) - } - if value, ok := su.mutation.AddedScore(); ok { - _spec.AddField(score.FieldScore, field.TypeFloat64, value) - } - if value, ok := su.mutation.StartedAt(); ok { - _spec.SetField(score.FieldStartedAt, field.TypeTime, value) - } - if value, ok := su.mutation.EndedAt(); ok { - _spec.SetField(score.FieldEndedAt, field.TypeTime, value) + if value, ok := su.mutation.CreatedAt(); ok { + _spec.SetField(score.FieldCreatedAt, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -246,51 +202,16 @@ func (suo *ScoreUpdateOne) AddAccuracy(f float64) *ScoreUpdateOne { return suo } -// SetScore sets the "score" field. -func (suo *ScoreUpdateOne) SetScore(f float64) *ScoreUpdateOne { - suo.mutation.ResetScore() - suo.mutation.SetScore(f) +// SetCreatedAt sets the "createdAt" field. +func (suo *ScoreUpdateOne) SetCreatedAt(t time.Time) *ScoreUpdateOne { + suo.mutation.SetCreatedAt(t) return suo } -// SetNillableScore sets the "score" field if the given value is not nil. -func (suo *ScoreUpdateOne) SetNillableScore(f *float64) *ScoreUpdateOne { - if f != nil { - suo.SetScore(*f) - } - return suo -} - -// AddScore adds f to the "score" field. -func (suo *ScoreUpdateOne) AddScore(f float64) *ScoreUpdateOne { - suo.mutation.AddScore(f) - return suo -} - -// SetStartedAt sets the "startedAt" field. -func (suo *ScoreUpdateOne) SetStartedAt(t time.Time) *ScoreUpdateOne { - suo.mutation.SetStartedAt(t) - return suo -} - -// SetNillableStartedAt sets the "startedAt" field if the given value is not nil. -func (suo *ScoreUpdateOne) SetNillableStartedAt(t *time.Time) *ScoreUpdateOne { +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (suo *ScoreUpdateOne) SetNillableCreatedAt(t *time.Time) *ScoreUpdateOne { if t != nil { - suo.SetStartedAt(*t) - } - return suo -} - -// SetEndedAt sets the "endedAt" field. -func (suo *ScoreUpdateOne) SetEndedAt(t time.Time) *ScoreUpdateOne { - suo.mutation.SetEndedAt(t) - return suo -} - -// SetNillableEndedAt sets the "endedAt" field if the given value is not nil. -func (suo *ScoreUpdateOne) SetNillableEndedAt(t *time.Time) *ScoreUpdateOne { - if t != nil { - suo.SetEndedAt(*t) + suo.SetCreatedAt(*t) } return suo } @@ -378,17 +299,8 @@ func (suo *ScoreUpdateOne) sqlSave(ctx context.Context) (_node *Score, err error if value, ok := suo.mutation.AddedAccuracy(); ok { _spec.AddField(score.FieldAccuracy, field.TypeFloat64, value) } - if value, ok := suo.mutation.Score(); ok { - _spec.SetField(score.FieldScore, field.TypeFloat64, value) - } - if value, ok := suo.mutation.AddedScore(); ok { - _spec.AddField(score.FieldScore, field.TypeFloat64, value) - } - if value, ok := suo.mutation.StartedAt(); ok { - _spec.SetField(score.FieldStartedAt, field.TypeTime, value) - } - if value, ok := suo.mutation.EndedAt(); ok { - _spec.SetField(score.FieldEndedAt, field.TypeTime, value) + if value, ok := suo.mutation.CreatedAt(); ok { + _spec.SetField(score.FieldCreatedAt, field.TypeTime, value) } _node = &Score{config: suo.config} _spec.Assign = _node.assignValues diff --git a/typing-server/domain/repository/ent/user.go b/typing-server/domain/repository/ent/user.go index 9fc4f15..23e39d5 100644 --- a/typing-server/domain/repository/ent/user.go +++ b/typing-server/domain/repository/ent/user.go @@ -18,16 +18,10 @@ type User struct { config `json:"-"` // ID of the ent. ID uuid.UUID `json:"id,omitempty"` - // MailAdress holds the value of the "MailAdress" field. - MailAdress string `json:"MailAdress,omitempty"` + // StudentNumber holds the value of the "StudentNumber" field. + StudentNumber string `json:"StudentNumber,omitempty"` // HandleName holds the value of the "HandleName" field. HandleName string `json:"HandleName,omitempty"` - // Name holds the value of the "Name" field. - Name string `json:"Name,omitempty"` - // HashedPassword holds the value of the "HashedPassword" field. - HashedPassword string `json:"HashedPassword,omitempty"` - // Department holds the value of the "Department" field. - Department user.Department `json:"Department,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. @@ -61,7 +55,7 @@ func (*User) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case user.FieldMailAdress, user.FieldHandleName, user.FieldName, user.FieldHashedPassword, user.FieldDepartment: + case user.FieldStudentNumber, user.FieldHandleName: values[i] = new(sql.NullString) case user.FieldCreatedAt, user.FieldUpdatedAt: values[i] = new(sql.NullTime) @@ -88,11 +82,11 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value != nil { u.ID = *value } - case user.FieldMailAdress: + case user.FieldStudentNumber: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field MailAdress", values[i]) + return fmt.Errorf("unexpected type %T for field StudentNumber", values[i]) } else if value.Valid { - u.MailAdress = value.String + u.StudentNumber = value.String } case user.FieldHandleName: if value, ok := values[i].(*sql.NullString); !ok { @@ -100,24 +94,6 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value.Valid { u.HandleName = value.String } - case user.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field Name", values[i]) - } else if value.Valid { - u.Name = value.String - } - case user.FieldHashedPassword: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field HashedPassword", values[i]) - } else if value.Valid { - u.HashedPassword = value.String - } - case user.FieldDepartment: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field Department", values[i]) - } else if value.Valid { - u.Department = user.Department(value.String) - } case user.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) @@ -171,21 +147,12 @@ func (u *User) String() string { var builder strings.Builder builder.WriteString("User(") builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) - builder.WriteString("MailAdress=") - builder.WriteString(u.MailAdress) + builder.WriteString("StudentNumber=") + builder.WriteString(u.StudentNumber) builder.WriteString(", ") builder.WriteString("HandleName=") builder.WriteString(u.HandleName) builder.WriteString(", ") - builder.WriteString("Name=") - builder.WriteString(u.Name) - builder.WriteString(", ") - builder.WriteString("HashedPassword=") - builder.WriteString(u.HashedPassword) - builder.WriteString(", ") - builder.WriteString("Department=") - builder.WriteString(fmt.Sprintf("%v", u.Department)) - builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(u.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") diff --git a/typing-server/domain/repository/ent/user/user.go b/typing-server/domain/repository/ent/user/user.go index 177591c..0cf6fe4 100644 --- a/typing-server/domain/repository/ent/user/user.go +++ b/typing-server/domain/repository/ent/user/user.go @@ -3,7 +3,6 @@ package user import ( - "fmt" "time" "entgo.io/ent/dialect/sql" @@ -16,16 +15,10 @@ const ( Label = "user" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldMailAdress holds the string denoting the mailadress field in the database. - FieldMailAdress = "mail_adress" + // FieldStudentNumber holds the string denoting the studentnumber field in the database. + FieldStudentNumber = "student_number" // FieldHandleName holds the string denoting the handlename field in the database. FieldHandleName = "handle_name" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // FieldHashedPassword holds the string denoting the hashedpassword field in the database. - FieldHashedPassword = "hashed_password" - // FieldDepartment holds the string denoting the department field in the database. - FieldDepartment = "department" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" // FieldUpdatedAt holds the string denoting the updated_at field in the database. @@ -46,11 +39,8 @@ const ( // Columns holds all SQL columns for user fields. var Columns = []string{ FieldID, - FieldMailAdress, + FieldStudentNumber, FieldHandleName, - FieldName, - FieldHashedPassword, - FieldDepartment, FieldCreatedAt, FieldUpdatedAt, } @@ -66,14 +56,10 @@ func ValidColumn(column string) bool { } var ( - // MailAdressValidator is a validator for the "MailAdress" field. It is called by the builders before save. - MailAdressValidator func(string) error + // StudentNumberValidator is a validator for the "StudentNumber" field. It is called by the builders before save. + StudentNumberValidator func(string) error // HandleNameValidator is a validator for the "HandleName" field. It is called by the builders before save. HandleNameValidator func(string) error - // NameValidator is a validator for the "Name" field. It is called by the builders before save. - NameValidator func(string) error - // HashedPasswordValidator is a validator for the "HashedPassword" field. It is called by the builders before save. - HashedPasswordValidator func(string) error // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. @@ -84,30 +70,6 @@ var ( DefaultID func() uuid.UUID ) -// Department defines the type for the "Department" enum field. -type Department string - -// Department values. -const ( - DepartmentCS Department = "CS" - DepartmentBI Department = "BI" - DepartmentIA Department = "IA" -) - -func (_department Department) String() string { - return string(_department) -} - -// DepartmentValidator is a validator for the "Department" field enum values. It is called by the builders before save. -func DepartmentValidator(_department Department) error { - switch _department { - case DepartmentCS, DepartmentBI, DepartmentIA: - return nil - default: - return fmt.Errorf("user: invalid enum value for Department field: %q", _department) - } -} - // OrderOption defines the ordering options for the User queries. type OrderOption func(*sql.Selector) @@ -116,9 +78,9 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByMailAdress orders the results by the MailAdress field. -func ByMailAdress(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldMailAdress, opts...).ToFunc() +// ByStudentNumber orders the results by the StudentNumber field. +func ByStudentNumber(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStudentNumber, opts...).ToFunc() } // ByHandleName orders the results by the HandleName field. @@ -126,21 +88,6 @@ func ByHandleName(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldHandleName, opts...).ToFunc() } -// ByName orders the results by the Name field. -func ByName(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldName, opts...).ToFunc() -} - -// ByHashedPassword orders the results by the HashedPassword field. -func ByHashedPassword(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldHashedPassword, opts...).ToFunc() -} - -// ByDepartment orders the results by the Department field. -func ByDepartment(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDepartment, opts...).ToFunc() -} - // ByCreatedAt orders the results by the created_at field. func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() diff --git a/typing-server/domain/repository/ent/user/where.go b/typing-server/domain/repository/ent/user/where.go index 092eb36..0653f73 100644 --- a/typing-server/domain/repository/ent/user/where.go +++ b/typing-server/domain/repository/ent/user/where.go @@ -56,9 +56,9 @@ func IDLTE(id uuid.UUID) predicate.User { return predicate.User(sql.FieldLTE(FieldID, id)) } -// MailAdress applies equality check predicate on the "MailAdress" field. It's identical to MailAdressEQ. -func MailAdress(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldMailAdress, v)) +// StudentNumber applies equality check predicate on the "StudentNumber" field. It's identical to StudentNumberEQ. +func StudentNumber(v string) predicate.User { + return predicate.User(sql.FieldEQ(FieldStudentNumber, v)) } // HandleName applies equality check predicate on the "HandleName" field. It's identical to HandleNameEQ. @@ -66,16 +66,6 @@ func HandleName(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldHandleName, v)) } -// Name applies equality check predicate on the "Name" field. It's identical to NameEQ. -func Name(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldName, v)) -} - -// HashedPassword applies equality check predicate on the "HashedPassword" field. It's identical to HashedPasswordEQ. -func HashedPassword(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldHashedPassword, v)) -} - // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.User { return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) @@ -86,69 +76,69 @@ func UpdatedAt(v time.Time) predicate.User { return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) } -// MailAdressEQ applies the EQ predicate on the "MailAdress" field. -func MailAdressEQ(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldMailAdress, v)) +// StudentNumberEQ applies the EQ predicate on the "StudentNumber" field. +func StudentNumberEQ(v string) predicate.User { + return predicate.User(sql.FieldEQ(FieldStudentNumber, v)) } -// MailAdressNEQ applies the NEQ predicate on the "MailAdress" field. -func MailAdressNEQ(v string) predicate.User { - return predicate.User(sql.FieldNEQ(FieldMailAdress, v)) +// StudentNumberNEQ applies the NEQ predicate on the "StudentNumber" field. +func StudentNumberNEQ(v string) predicate.User { + return predicate.User(sql.FieldNEQ(FieldStudentNumber, v)) } -// MailAdressIn applies the In predicate on the "MailAdress" field. -func MailAdressIn(vs ...string) predicate.User { - return predicate.User(sql.FieldIn(FieldMailAdress, vs...)) +// StudentNumberIn applies the In predicate on the "StudentNumber" field. +func StudentNumberIn(vs ...string) predicate.User { + return predicate.User(sql.FieldIn(FieldStudentNumber, vs...)) } -// MailAdressNotIn applies the NotIn predicate on the "MailAdress" field. -func MailAdressNotIn(vs ...string) predicate.User { - return predicate.User(sql.FieldNotIn(FieldMailAdress, vs...)) +// StudentNumberNotIn applies the NotIn predicate on the "StudentNumber" field. +func StudentNumberNotIn(vs ...string) predicate.User { + return predicate.User(sql.FieldNotIn(FieldStudentNumber, vs...)) } -// MailAdressGT applies the GT predicate on the "MailAdress" field. -func MailAdressGT(v string) predicate.User { - return predicate.User(sql.FieldGT(FieldMailAdress, v)) +// StudentNumberGT applies the GT predicate on the "StudentNumber" field. +func StudentNumberGT(v string) predicate.User { + return predicate.User(sql.FieldGT(FieldStudentNumber, v)) } -// MailAdressGTE applies the GTE predicate on the "MailAdress" field. -func MailAdressGTE(v string) predicate.User { - return predicate.User(sql.FieldGTE(FieldMailAdress, v)) +// StudentNumberGTE applies the GTE predicate on the "StudentNumber" field. +func StudentNumberGTE(v string) predicate.User { + return predicate.User(sql.FieldGTE(FieldStudentNumber, v)) } -// MailAdressLT applies the LT predicate on the "MailAdress" field. -func MailAdressLT(v string) predicate.User { - return predicate.User(sql.FieldLT(FieldMailAdress, v)) +// StudentNumberLT applies the LT predicate on the "StudentNumber" field. +func StudentNumberLT(v string) predicate.User { + return predicate.User(sql.FieldLT(FieldStudentNumber, v)) } -// MailAdressLTE applies the LTE predicate on the "MailAdress" field. -func MailAdressLTE(v string) predicate.User { - return predicate.User(sql.FieldLTE(FieldMailAdress, v)) +// StudentNumberLTE applies the LTE predicate on the "StudentNumber" field. +func StudentNumberLTE(v string) predicate.User { + return predicate.User(sql.FieldLTE(FieldStudentNumber, v)) } -// MailAdressContains applies the Contains predicate on the "MailAdress" field. -func MailAdressContains(v string) predicate.User { - return predicate.User(sql.FieldContains(FieldMailAdress, v)) +// StudentNumberContains applies the Contains predicate on the "StudentNumber" field. +func StudentNumberContains(v string) predicate.User { + return predicate.User(sql.FieldContains(FieldStudentNumber, v)) } -// MailAdressHasPrefix applies the HasPrefix predicate on the "MailAdress" field. -func MailAdressHasPrefix(v string) predicate.User { - return predicate.User(sql.FieldHasPrefix(FieldMailAdress, v)) +// StudentNumberHasPrefix applies the HasPrefix predicate on the "StudentNumber" field. +func StudentNumberHasPrefix(v string) predicate.User { + return predicate.User(sql.FieldHasPrefix(FieldStudentNumber, v)) } -// MailAdressHasSuffix applies the HasSuffix predicate on the "MailAdress" field. -func MailAdressHasSuffix(v string) predicate.User { - return predicate.User(sql.FieldHasSuffix(FieldMailAdress, v)) +// StudentNumberHasSuffix applies the HasSuffix predicate on the "StudentNumber" field. +func StudentNumberHasSuffix(v string) predicate.User { + return predicate.User(sql.FieldHasSuffix(FieldStudentNumber, v)) } -// MailAdressEqualFold applies the EqualFold predicate on the "MailAdress" field. -func MailAdressEqualFold(v string) predicate.User { - return predicate.User(sql.FieldEqualFold(FieldMailAdress, v)) +// StudentNumberEqualFold applies the EqualFold predicate on the "StudentNumber" field. +func StudentNumberEqualFold(v string) predicate.User { + return predicate.User(sql.FieldEqualFold(FieldStudentNumber, v)) } -// MailAdressContainsFold applies the ContainsFold predicate on the "MailAdress" field. -func MailAdressContainsFold(v string) predicate.User { - return predicate.User(sql.FieldContainsFold(FieldMailAdress, v)) +// StudentNumberContainsFold applies the ContainsFold predicate on the "StudentNumber" field. +func StudentNumberContainsFold(v string) predicate.User { + return predicate.User(sql.FieldContainsFold(FieldStudentNumber, v)) } // HandleNameEQ applies the EQ predicate on the "HandleName" field. @@ -216,156 +206,6 @@ func HandleNameContainsFold(v string) predicate.User { return predicate.User(sql.FieldContainsFold(FieldHandleName, v)) } -// NameEQ applies the EQ predicate on the "Name" field. -func NameEQ(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldName, v)) -} - -// NameNEQ applies the NEQ predicate on the "Name" field. -func NameNEQ(v string) predicate.User { - return predicate.User(sql.FieldNEQ(FieldName, v)) -} - -// NameIn applies the In predicate on the "Name" field. -func NameIn(vs ...string) predicate.User { - return predicate.User(sql.FieldIn(FieldName, vs...)) -} - -// NameNotIn applies the NotIn predicate on the "Name" field. -func NameNotIn(vs ...string) predicate.User { - return predicate.User(sql.FieldNotIn(FieldName, vs...)) -} - -// NameGT applies the GT predicate on the "Name" field. -func NameGT(v string) predicate.User { - return predicate.User(sql.FieldGT(FieldName, v)) -} - -// NameGTE applies the GTE predicate on the "Name" field. -func NameGTE(v string) predicate.User { - return predicate.User(sql.FieldGTE(FieldName, v)) -} - -// NameLT applies the LT predicate on the "Name" field. -func NameLT(v string) predicate.User { - return predicate.User(sql.FieldLT(FieldName, v)) -} - -// NameLTE applies the LTE predicate on the "Name" field. -func NameLTE(v string) predicate.User { - return predicate.User(sql.FieldLTE(FieldName, v)) -} - -// NameContains applies the Contains predicate on the "Name" field. -func NameContains(v string) predicate.User { - return predicate.User(sql.FieldContains(FieldName, v)) -} - -// NameHasPrefix applies the HasPrefix predicate on the "Name" field. -func NameHasPrefix(v string) predicate.User { - return predicate.User(sql.FieldHasPrefix(FieldName, v)) -} - -// NameHasSuffix applies the HasSuffix predicate on the "Name" field. -func NameHasSuffix(v string) predicate.User { - return predicate.User(sql.FieldHasSuffix(FieldName, v)) -} - -// NameEqualFold applies the EqualFold predicate on the "Name" field. -func NameEqualFold(v string) predicate.User { - return predicate.User(sql.FieldEqualFold(FieldName, v)) -} - -// NameContainsFold applies the ContainsFold predicate on the "Name" field. -func NameContainsFold(v string) predicate.User { - return predicate.User(sql.FieldContainsFold(FieldName, v)) -} - -// HashedPasswordEQ applies the EQ predicate on the "HashedPassword" field. -func HashedPasswordEQ(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldHashedPassword, v)) -} - -// HashedPasswordNEQ applies the NEQ predicate on the "HashedPassword" field. -func HashedPasswordNEQ(v string) predicate.User { - return predicate.User(sql.FieldNEQ(FieldHashedPassword, v)) -} - -// HashedPasswordIn applies the In predicate on the "HashedPassword" field. -func HashedPasswordIn(vs ...string) predicate.User { - return predicate.User(sql.FieldIn(FieldHashedPassword, vs...)) -} - -// HashedPasswordNotIn applies the NotIn predicate on the "HashedPassword" field. -func HashedPasswordNotIn(vs ...string) predicate.User { - return predicate.User(sql.FieldNotIn(FieldHashedPassword, vs...)) -} - -// HashedPasswordGT applies the GT predicate on the "HashedPassword" field. -func HashedPasswordGT(v string) predicate.User { - return predicate.User(sql.FieldGT(FieldHashedPassword, v)) -} - -// HashedPasswordGTE applies the GTE predicate on the "HashedPassword" field. -func HashedPasswordGTE(v string) predicate.User { - return predicate.User(sql.FieldGTE(FieldHashedPassword, v)) -} - -// HashedPasswordLT applies the LT predicate on the "HashedPassword" field. -func HashedPasswordLT(v string) predicate.User { - return predicate.User(sql.FieldLT(FieldHashedPassword, v)) -} - -// HashedPasswordLTE applies the LTE predicate on the "HashedPassword" field. -func HashedPasswordLTE(v string) predicate.User { - return predicate.User(sql.FieldLTE(FieldHashedPassword, v)) -} - -// HashedPasswordContains applies the Contains predicate on the "HashedPassword" field. -func HashedPasswordContains(v string) predicate.User { - return predicate.User(sql.FieldContains(FieldHashedPassword, v)) -} - -// HashedPasswordHasPrefix applies the HasPrefix predicate on the "HashedPassword" field. -func HashedPasswordHasPrefix(v string) predicate.User { - return predicate.User(sql.FieldHasPrefix(FieldHashedPassword, v)) -} - -// HashedPasswordHasSuffix applies the HasSuffix predicate on the "HashedPassword" field. -func HashedPasswordHasSuffix(v string) predicate.User { - return predicate.User(sql.FieldHasSuffix(FieldHashedPassword, v)) -} - -// HashedPasswordEqualFold applies the EqualFold predicate on the "HashedPassword" field. -func HashedPasswordEqualFold(v string) predicate.User { - return predicate.User(sql.FieldEqualFold(FieldHashedPassword, v)) -} - -// HashedPasswordContainsFold applies the ContainsFold predicate on the "HashedPassword" field. -func HashedPasswordContainsFold(v string) predicate.User { - return predicate.User(sql.FieldContainsFold(FieldHashedPassword, v)) -} - -// DepartmentEQ applies the EQ predicate on the "Department" field. -func DepartmentEQ(v Department) predicate.User { - return predicate.User(sql.FieldEQ(FieldDepartment, v)) -} - -// DepartmentNEQ applies the NEQ predicate on the "Department" field. -func DepartmentNEQ(v Department) predicate.User { - return predicate.User(sql.FieldNEQ(FieldDepartment, v)) -} - -// DepartmentIn applies the In predicate on the "Department" field. -func DepartmentIn(vs ...Department) predicate.User { - return predicate.User(sql.FieldIn(FieldDepartment, vs...)) -} - -// DepartmentNotIn applies the NotIn predicate on the "Department" field. -func DepartmentNotIn(vs ...Department) predicate.User { - return predicate.User(sql.FieldNotIn(FieldDepartment, vs...)) -} - // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.User { return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) diff --git a/typing-server/domain/repository/ent/user_create.go b/typing-server/domain/repository/ent/user_create.go index 657e776..c2864ac 100644 --- a/typing-server/domain/repository/ent/user_create.go +++ b/typing-server/domain/repository/ent/user_create.go @@ -22,9 +22,9 @@ type UserCreate struct { hooks []Hook } -// SetMailAdress sets the "MailAdress" field. -func (uc *UserCreate) SetMailAdress(s string) *UserCreate { - uc.mutation.SetMailAdress(s) +// SetStudentNumber sets the "StudentNumber" field. +func (uc *UserCreate) SetStudentNumber(s string) *UserCreate { + uc.mutation.SetStudentNumber(s) return uc } @@ -34,24 +34,6 @@ func (uc *UserCreate) SetHandleName(s string) *UserCreate { return uc } -// SetName sets the "Name" field. -func (uc *UserCreate) SetName(s string) *UserCreate { - uc.mutation.SetName(s) - return uc -} - -// SetHashedPassword sets the "HashedPassword" field. -func (uc *UserCreate) SetHashedPassword(s string) *UserCreate { - uc.mutation.SetHashedPassword(s) - return uc -} - -// SetDepartment sets the "Department" field. -func (uc *UserCreate) SetDepartment(u user.Department) *UserCreate { - uc.mutation.SetDepartment(u) - return uc -} - // SetCreatedAt sets the "created_at" field. func (uc *UserCreate) SetCreatedAt(t time.Time) *UserCreate { uc.mutation.SetCreatedAt(t) @@ -160,12 +142,12 @@ func (uc *UserCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (uc *UserCreate) check() error { - if _, ok := uc.mutation.MailAdress(); !ok { - return &ValidationError{Name: "MailAdress", err: errors.New(`ent: missing required field "User.MailAdress"`)} + if _, ok := uc.mutation.StudentNumber(); !ok { + return &ValidationError{Name: "StudentNumber", err: errors.New(`ent: missing required field "User.StudentNumber"`)} } - if v, ok := uc.mutation.MailAdress(); ok { - if err := user.MailAdressValidator(v); err != nil { - return &ValidationError{Name: "MailAdress", err: fmt.Errorf(`ent: validator failed for field "User.MailAdress": %w`, err)} + if v, ok := uc.mutation.StudentNumber(); ok { + if err := user.StudentNumberValidator(v); err != nil { + return &ValidationError{Name: "StudentNumber", err: fmt.Errorf(`ent: validator failed for field "User.StudentNumber": %w`, err)} } } if _, ok := uc.mutation.HandleName(); !ok { @@ -176,30 +158,6 @@ func (uc *UserCreate) check() error { return &ValidationError{Name: "HandleName", err: fmt.Errorf(`ent: validator failed for field "User.HandleName": %w`, err)} } } - if _, ok := uc.mutation.Name(); !ok { - return &ValidationError{Name: "Name", err: errors.New(`ent: missing required field "User.Name"`)} - } - if v, ok := uc.mutation.Name(); ok { - if err := user.NameValidator(v); err != nil { - return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "User.Name": %w`, err)} - } - } - if _, ok := uc.mutation.HashedPassword(); !ok { - return &ValidationError{Name: "HashedPassword", err: errors.New(`ent: missing required field "User.HashedPassword"`)} - } - if v, ok := uc.mutation.HashedPassword(); ok { - if err := user.HashedPasswordValidator(v); err != nil { - return &ValidationError{Name: "HashedPassword", err: fmt.Errorf(`ent: validator failed for field "User.HashedPassword": %w`, err)} - } - } - if _, ok := uc.mutation.Department(); !ok { - return &ValidationError{Name: "Department", err: errors.New(`ent: missing required field "User.Department"`)} - } - if v, ok := uc.mutation.Department(); ok { - if err := user.DepartmentValidator(v); err != nil { - return &ValidationError{Name: "Department", err: fmt.Errorf(`ent: validator failed for field "User.Department": %w`, err)} - } - } if _, ok := uc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)} } @@ -241,26 +199,14 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { _node.ID = id _spec.ID.Value = &id } - if value, ok := uc.mutation.MailAdress(); ok { - _spec.SetField(user.FieldMailAdress, field.TypeString, value) - _node.MailAdress = value + if value, ok := uc.mutation.StudentNumber(); ok { + _spec.SetField(user.FieldStudentNumber, field.TypeString, value) + _node.StudentNumber = value } if value, ok := uc.mutation.HandleName(); ok { _spec.SetField(user.FieldHandleName, field.TypeString, value) _node.HandleName = value } - if value, ok := uc.mutation.Name(); ok { - _spec.SetField(user.FieldName, field.TypeString, value) - _node.Name = value - } - if value, ok := uc.mutation.HashedPassword(); ok { - _spec.SetField(user.FieldHashedPassword, field.TypeString, value) - _node.HashedPassword = value - } - if value, ok := uc.mutation.Department(); ok { - _spec.SetField(user.FieldDepartment, field.TypeEnum, value) - _node.Department = value - } if value, ok := uc.mutation.CreatedAt(); ok { _spec.SetField(user.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value diff --git a/typing-server/domain/repository/ent/user_query.go b/typing-server/domain/repository/ent/user_query.go index 486462e..c88c6f5 100644 --- a/typing-server/domain/repository/ent/user_query.go +++ b/typing-server/domain/repository/ent/user_query.go @@ -299,12 +299,12 @@ func (uq *UserQuery) WithScores(opts ...func(*ScoreQuery)) *UserQuery { // Example: // // var v []struct { -// MailAdress string `json:"MailAdress,omitempty"` +// StudentNumber string `json:"StudentNumber,omitempty"` // Count int `json:"count,omitempty"` // } // // client.User.Query(). -// GroupBy(user.FieldMailAdress). +// GroupBy(user.FieldStudentNumber). // Aggregate(ent.Count()). // Scan(ctx, &v) func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { @@ -322,11 +322,11 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { // Example: // // var v []struct { -// MailAdress string `json:"MailAdress,omitempty"` +// StudentNumber string `json:"StudentNumber,omitempty"` // } // // client.User.Query(). -// Select(user.FieldMailAdress). +// Select(user.FieldStudentNumber). // Scan(ctx, &v) func (uq *UserQuery) Select(fields ...string) *UserSelect { uq.ctx.Fields = append(uq.ctx.Fields, fields...) diff --git a/typing-server/domain/repository/ent/user_update.go b/typing-server/domain/repository/ent/user_update.go index 9b94383..98f1d92 100644 --- a/typing-server/domain/repository/ent/user_update.go +++ b/typing-server/domain/repository/ent/user_update.go @@ -30,16 +30,16 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate { return uu } -// SetMailAdress sets the "MailAdress" field. -func (uu *UserUpdate) SetMailAdress(s string) *UserUpdate { - uu.mutation.SetMailAdress(s) +// SetStudentNumber sets the "StudentNumber" field. +func (uu *UserUpdate) SetStudentNumber(s string) *UserUpdate { + uu.mutation.SetStudentNumber(s) return uu } -// SetNillableMailAdress sets the "MailAdress" field if the given value is not nil. -func (uu *UserUpdate) SetNillableMailAdress(s *string) *UserUpdate { +// SetNillableStudentNumber sets the "StudentNumber" field if the given value is not nil. +func (uu *UserUpdate) SetNillableStudentNumber(s *string) *UserUpdate { if s != nil { - uu.SetMailAdress(*s) + uu.SetStudentNumber(*s) } return uu } @@ -58,48 +58,6 @@ func (uu *UserUpdate) SetNillableHandleName(s *string) *UserUpdate { return uu } -// SetName sets the "Name" field. -func (uu *UserUpdate) SetName(s string) *UserUpdate { - uu.mutation.SetName(s) - return uu -} - -// SetNillableName sets the "Name" field if the given value is not nil. -func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { - if s != nil { - uu.SetName(*s) - } - return uu -} - -// SetHashedPassword sets the "HashedPassword" field. -func (uu *UserUpdate) SetHashedPassword(s string) *UserUpdate { - uu.mutation.SetHashedPassword(s) - return uu -} - -// SetNillableHashedPassword sets the "HashedPassword" field if the given value is not nil. -func (uu *UserUpdate) SetNillableHashedPassword(s *string) *UserUpdate { - if s != nil { - uu.SetHashedPassword(*s) - } - return uu -} - -// SetDepartment sets the "Department" field. -func (uu *UserUpdate) SetDepartment(u user.Department) *UserUpdate { - uu.mutation.SetDepartment(u) - return uu -} - -// SetNillableDepartment sets the "Department" field if the given value is not nil. -func (uu *UserUpdate) SetNillableDepartment(u *user.Department) *UserUpdate { - if u != nil { - uu.SetDepartment(*u) - } - return uu -} - // SetUpdatedAt sets the "updated_at" field. func (uu *UserUpdate) SetUpdatedAt(t time.Time) *UserUpdate { uu.mutation.SetUpdatedAt(t) @@ -185,9 +143,9 @@ func (uu *UserUpdate) defaults() { // check runs all checks and user-defined validators on the builder. func (uu *UserUpdate) check() error { - if v, ok := uu.mutation.MailAdress(); ok { - if err := user.MailAdressValidator(v); err != nil { - return &ValidationError{Name: "MailAdress", err: fmt.Errorf(`ent: validator failed for field "User.MailAdress": %w`, err)} + if v, ok := uu.mutation.StudentNumber(); ok { + if err := user.StudentNumberValidator(v); err != nil { + return &ValidationError{Name: "StudentNumber", err: fmt.Errorf(`ent: validator failed for field "User.StudentNumber": %w`, err)} } } if v, ok := uu.mutation.HandleName(); ok { @@ -195,21 +153,6 @@ func (uu *UserUpdate) check() error { return &ValidationError{Name: "HandleName", err: fmt.Errorf(`ent: validator failed for field "User.HandleName": %w`, err)} } } - if v, ok := uu.mutation.Name(); ok { - if err := user.NameValidator(v); err != nil { - return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "User.Name": %w`, err)} - } - } - if v, ok := uu.mutation.HashedPassword(); ok { - if err := user.HashedPasswordValidator(v); err != nil { - return &ValidationError{Name: "HashedPassword", err: fmt.Errorf(`ent: validator failed for field "User.HashedPassword": %w`, err)} - } - } - if v, ok := uu.mutation.Department(); ok { - if err := user.DepartmentValidator(v); err != nil { - return &ValidationError{Name: "Department", err: fmt.Errorf(`ent: validator failed for field "User.Department": %w`, err)} - } - } return nil } @@ -225,21 +168,12 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } } } - if value, ok := uu.mutation.MailAdress(); ok { - _spec.SetField(user.FieldMailAdress, field.TypeString, value) + if value, ok := uu.mutation.StudentNumber(); ok { + _spec.SetField(user.FieldStudentNumber, field.TypeString, value) } if value, ok := uu.mutation.HandleName(); ok { _spec.SetField(user.FieldHandleName, field.TypeString, value) } - if value, ok := uu.mutation.Name(); ok { - _spec.SetField(user.FieldName, field.TypeString, value) - } - if value, ok := uu.mutation.HashedPassword(); ok { - _spec.SetField(user.FieldHashedPassword, field.TypeString, value) - } - if value, ok := uu.mutation.Department(); ok { - _spec.SetField(user.FieldDepartment, field.TypeEnum, value) - } if value, ok := uu.mutation.UpdatedAt(); ok { _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value) } @@ -308,16 +242,16 @@ type UserUpdateOne struct { mutation *UserMutation } -// SetMailAdress sets the "MailAdress" field. -func (uuo *UserUpdateOne) SetMailAdress(s string) *UserUpdateOne { - uuo.mutation.SetMailAdress(s) +// SetStudentNumber sets the "StudentNumber" field. +func (uuo *UserUpdateOne) SetStudentNumber(s string) *UserUpdateOne { + uuo.mutation.SetStudentNumber(s) return uuo } -// SetNillableMailAdress sets the "MailAdress" field if the given value is not nil. -func (uuo *UserUpdateOne) SetNillableMailAdress(s *string) *UserUpdateOne { +// SetNillableStudentNumber sets the "StudentNumber" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableStudentNumber(s *string) *UserUpdateOne { if s != nil { - uuo.SetMailAdress(*s) + uuo.SetStudentNumber(*s) } return uuo } @@ -336,48 +270,6 @@ func (uuo *UserUpdateOne) SetNillableHandleName(s *string) *UserUpdateOne { return uuo } -// SetName sets the "Name" field. -func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { - uuo.mutation.SetName(s) - return uuo -} - -// SetNillableName sets the "Name" field if the given value is not nil. -func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { - if s != nil { - uuo.SetName(*s) - } - return uuo -} - -// SetHashedPassword sets the "HashedPassword" field. -func (uuo *UserUpdateOne) SetHashedPassword(s string) *UserUpdateOne { - uuo.mutation.SetHashedPassword(s) - return uuo -} - -// SetNillableHashedPassword sets the "HashedPassword" field if the given value is not nil. -func (uuo *UserUpdateOne) SetNillableHashedPassword(s *string) *UserUpdateOne { - if s != nil { - uuo.SetHashedPassword(*s) - } - return uuo -} - -// SetDepartment sets the "Department" field. -func (uuo *UserUpdateOne) SetDepartment(u user.Department) *UserUpdateOne { - uuo.mutation.SetDepartment(u) - return uuo -} - -// SetNillableDepartment sets the "Department" field if the given value is not nil. -func (uuo *UserUpdateOne) SetNillableDepartment(u *user.Department) *UserUpdateOne { - if u != nil { - uuo.SetDepartment(*u) - } - return uuo -} - // SetUpdatedAt sets the "updated_at" field. func (uuo *UserUpdateOne) SetUpdatedAt(t time.Time) *UserUpdateOne { uuo.mutation.SetUpdatedAt(t) @@ -476,9 +368,9 @@ func (uuo *UserUpdateOne) defaults() { // check runs all checks and user-defined validators on the builder. func (uuo *UserUpdateOne) check() error { - if v, ok := uuo.mutation.MailAdress(); ok { - if err := user.MailAdressValidator(v); err != nil { - return &ValidationError{Name: "MailAdress", err: fmt.Errorf(`ent: validator failed for field "User.MailAdress": %w`, err)} + if v, ok := uuo.mutation.StudentNumber(); ok { + if err := user.StudentNumberValidator(v); err != nil { + return &ValidationError{Name: "StudentNumber", err: fmt.Errorf(`ent: validator failed for field "User.StudentNumber": %w`, err)} } } if v, ok := uuo.mutation.HandleName(); ok { @@ -486,21 +378,6 @@ func (uuo *UserUpdateOne) check() error { return &ValidationError{Name: "HandleName", err: fmt.Errorf(`ent: validator failed for field "User.HandleName": %w`, err)} } } - if v, ok := uuo.mutation.Name(); ok { - if err := user.NameValidator(v); err != nil { - return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "User.Name": %w`, err)} - } - } - if v, ok := uuo.mutation.HashedPassword(); ok { - if err := user.HashedPasswordValidator(v); err != nil { - return &ValidationError{Name: "HashedPassword", err: fmt.Errorf(`ent: validator failed for field "User.HashedPassword": %w`, err)} - } - } - if v, ok := uuo.mutation.Department(); ok { - if err := user.DepartmentValidator(v); err != nil { - return &ValidationError{Name: "Department", err: fmt.Errorf(`ent: validator failed for field "User.Department": %w`, err)} - } - } return nil } @@ -533,21 +410,12 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) } } } - if value, ok := uuo.mutation.MailAdress(); ok { - _spec.SetField(user.FieldMailAdress, field.TypeString, value) + if value, ok := uuo.mutation.StudentNumber(); ok { + _spec.SetField(user.FieldStudentNumber, field.TypeString, value) } if value, ok := uuo.mutation.HandleName(); ok { _spec.SetField(user.FieldHandleName, field.TypeString, value) } - if value, ok := uuo.mutation.Name(); ok { - _spec.SetField(user.FieldName, field.TypeString, value) - } - if value, ok := uuo.mutation.HashedPassword(); ok { - _spec.SetField(user.FieldHashedPassword, field.TypeString, value) - } - if value, ok := uuo.mutation.Department(); ok { - _spec.SetField(user.FieldDepartment, field.TypeEnum, value) - } if value, ok := uuo.mutation.UpdatedAt(); ok { _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value) } From 220575ceb4b67c04d867b7546f8e14bbbbf3c840 Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Fri, 22 Mar 2024 19:45:06 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=E9=96=8B=E7=99=BA=E7=94=A8docker?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typing-server/Dockerfile | 4 ++-- typing-server/Dockerfile.dev | 29 ++++++++++++++++++++++++++++ typing-server/docker-compose.dev.yml | 8 ++++---- 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 typing-server/Dockerfile.dev diff --git a/typing-server/Dockerfile b/typing-server/Dockerfile index ea4df5a..d6a4f1f 100644 --- a/typing-server/Dockerfile +++ b/typing-server/Dockerfile @@ -14,7 +14,7 @@ RUN go mod download RUN CGO_ENABLED=0 GOOS=linux go build -v -o server ./api/cmd/main.go # 実行イメージ -FROM alpine:latest +FROM alpine:latest RUN apk --no-cache add ca-certificates # tzdataパッケージのインストール @@ -26,4 +26,4 @@ WORKDIR /root COPY --from=builder /app/server . # アプリケーションの実行 -CMD ["./server"] +CMD ["./server","-seed","false"] diff --git a/typing-server/Dockerfile.dev b/typing-server/Dockerfile.dev new file mode 100644 index 0000000..3ef3d2c --- /dev/null +++ b/typing-server/Dockerfile.dev @@ -0,0 +1,29 @@ +# 基本イメージ +FROM golang:1.22.0 as builder + +# 作業ディレクトリを設定 +WORKDIR /app + +# ソースコードをコピー +COPY . . + +# 依存関係をインストール +RUN go mod download + +# アプリケーションをビルド +RUN CGO_ENABLED=0 GOOS=linux go build -v -o server ./api/cmd/main.go + +# 実行イメージ +FROM alpine:latest +RUN apk --no-cache add ca-certificates + +# tzdataパッケージのインストール +RUN apk --no-cache add tzdata + +WORKDIR /root + +# ビルドしたバイナリをコピー +COPY --from=builder /app/server . + +# アプリケーションの実行 +CMD ["./server","-seed","true"] diff --git a/typing-server/docker-compose.dev.yml b/typing-server/docker-compose.dev.yml index c8beb76..4d842a9 100644 --- a/typing-server/docker-compose.dev.yml +++ b/typing-server/docker-compose.dev.yml @@ -5,7 +5,7 @@ services: condition: service_healthy build: context: . - dockerfile: Dockerfile + dockerfile: Dockerfile.dev volumes: - ./api:/app environment: @@ -14,9 +14,9 @@ services: - "8080:8080" networks: app_net: - ipv4_address: '172.28.1.3' + ipv4_address: "172.28.1.3" extra_hosts: - - 'db:172.28.1.5' + - "db:172.28.1.5" db: healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] @@ -36,7 +36,7 @@ services: - db-data:/var/lib/mysql networks: app_net: - ipv4_address: '172.28.1.5' + ipv4_address: "172.28.1.5" volumes: db-data: networks: From e8f7b880e863070347ce94d3150f49b7d72e3366 Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Fri, 22 Mar 2024 19:45:34 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=E3=82=B7=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=81=AE=E6=8C=BF=E5=85=A5=E3=81=A8?= =?UTF-8?q?=E3=81=9D=E3=81=AE=E3=83=95=E3=83=A9=E3=82=B0=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typing-server/api/cmd/main.go | 60 +++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/typing-server/api/cmd/main.go b/typing-server/api/cmd/main.go index 3a9ad5b..e592914 100644 --- a/typing-server/api/cmd/main.go +++ b/typing-server/api/cmd/main.go @@ -2,7 +2,10 @@ package main import ( "context" + "flag" + "fmt" "log/slog" + "math/rand" "net/http" "os" "os/signal" @@ -11,11 +14,14 @@ import ( "time" "github.com/go-sql-driver/mysql" - "github.com/su-its/typing/typing-server/api/presenter" "github.com/su-its/typing/typing-server/domain/repository/ent" + "github.com/su-its/typing/typing-server/domain/repository/ent/user" ) func main() { + seedFlag := flag.Bool("seed", false, "シードデータを挿入する場合はtrueを指定") + flag.Parse() + logger := slog.Default() // タイムゾーンの設定 @@ -57,8 +63,16 @@ func main() { } logger.Info("schema is created") - // ルートの登録 - presenter.RegisterRoutes() + // シードデータの挿入 + if *seedFlag { + if err := seedData(context.Background(), entClient); err != nil { + logger.Error("failed to seed data: %v", err) + return + } + logger.Info("シードデータが挿入されました") + } else { + logger.Info("シードデータは挿入されませんでした") + } // WaitGroupの宣言 var wg sync.WaitGroup @@ -100,3 +114,43 @@ func main() { close(errChan) logger.Info("server exited") } + +// TODO: 本番環境では削除する +func seedData(ctx context.Context, client *ent.Client) error { + // シードデータの作成 + for i := 0; i < 10; i++ { + isAlreadySeeded, err := client.User.Query().Where(user.StudentNumber(fmt.Sprintf("user%d", i+1))).Exist(ctx) + if err != nil { + return err + } + if isAlreadySeeded { + continue + } + + u, err := client.User.Create(). + SetStudentNumber(fmt.Sprintf("user%d", i+1)). + SetHandleName(fmt.Sprintf("handle%d", i+1)). + Save(ctx) + if err != nil { + panic(err) + } + + for j := 0; j < 5; j++ { + score, err := client.Score.Create(). + SetKeystrokes(rand.Intn(200)). + SetAccuracy(rand.Float64()). + SetCreatedAt(time.Now()). + Save(ctx) + if err != nil { + panic(err) + } + + _, err = client.User.UpdateOne(u). + AddScores(score).Save(ctx) + if err != nil { + panic(err) + } + } + } + return nil +} From a126298f7b66b88a7d0d3b074d79179e99d8112f Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Fri, 22 Mar 2024 19:58:30 +0900 Subject: [PATCH 4/6] =?UTF-8?q?docs:=20=E9=96=8B=E7=99=BA=E7=92=B0?= =?UTF-8?q?=E5=A2=83=E6=A7=8B=E7=AF=89=E3=81=AE=E6=89=8B=E9=A0=86=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typing-app/docs/get-started.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 typing-app/docs/get-started.md diff --git a/typing-app/docs/get-started.md b/typing-app/docs/get-started.md new file mode 100644 index 0000000..4ba5bae --- /dev/null +++ b/typing-app/docs/get-started.md @@ -0,0 +1,34 @@ +# 開発環境構築 + +## 1. リポジトリのクローン + +```bash +$ git clone https://github.com/su-its/typing.git +$ cd typing/typing-app +``` + +## 2. パッケージのインストール(npm ではなく bun を採用しています) + +### Bun をインストールする (まだインストールしていない場合) + +```bash +$ curl -fsSL https://bun.sh/install | bash +``` + +### プロジェクトの依存パッケージをインストール + +```bash +$ bun install +``` + +## 3. API & DB の起動(typing-server ディレクトリで実行) + +```bash +$ docker-compose --file docker-compose.dev.yml up +``` + +## 4. フロントエンドの起動(typing-app ディレクトリで実行) + +```bash +$ bun dev +``` From 8a772e3edfb4b795e68329a21f489fb1f2791e59 Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Sat, 23 Mar 2024 15:28:58 +0900 Subject: [PATCH 5/6] =?UTF-8?q?style:=20=E3=82=B9=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=82=B1=E3=83=BC=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/ent/mutation.go | 36 ++++++------ .../domain/repository/ent/runtime.go | 12 ++-- .../domain/repository/ent/schema/user.go | 6 +- typing-server/domain/repository/ent/user.go | 16 +++--- .../domain/repository/ent/user/user.go | 12 ++-- .../domain/repository/ent/user/where.go | 56 +++++++++---------- .../domain/repository/ent/user_create.go | 12 ++-- .../domain/repository/ent/user_query.go | 4 +- .../domain/repository/ent/user_update.go | 24 ++++---- 9 files changed, 89 insertions(+), 89 deletions(-) diff --git a/typing-server/domain/repository/ent/mutation.go b/typing-server/domain/repository/ent/mutation.go index 1f505a9..7c149eb 100644 --- a/typing-server/domain/repository/ent/mutation.go +++ b/typing-server/domain/repository/ent/mutation.go @@ -545,8 +545,8 @@ type UserMutation struct { op Op typ string id *uuid.UUID - _StudentNumber *string - _HandleName *string + student_number *string + handle_name *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} @@ -662,21 +662,21 @@ func (m *UserMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { } } -// SetStudentNumber sets the "StudentNumber" field. +// SetStudentNumber sets the "student_number" field. func (m *UserMutation) SetStudentNumber(s string) { - m._StudentNumber = &s + m.student_number = &s } -// StudentNumber returns the value of the "StudentNumber" field in the mutation. +// StudentNumber returns the value of the "student_number" field in the mutation. func (m *UserMutation) StudentNumber() (r string, exists bool) { - v := m._StudentNumber + v := m.student_number if v == nil { return } return *v, true } -// OldStudentNumber returns the old "StudentNumber" field's value of the User entity. +// OldStudentNumber returns the old "student_number" 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) OldStudentNumber(ctx context.Context) (v string, err error) { @@ -693,26 +693,26 @@ func (m *UserMutation) OldStudentNumber(ctx context.Context) (v string, err erro return oldValue.StudentNumber, nil } -// ResetStudentNumber resets all changes to the "StudentNumber" field. +// ResetStudentNumber resets all changes to the "student_number" field. func (m *UserMutation) ResetStudentNumber() { - m._StudentNumber = nil + m.student_number = nil } -// SetHandleName sets the "HandleName" field. +// SetHandleName sets the "handle_name" field. func (m *UserMutation) SetHandleName(s string) { - m._HandleName = &s + m.handle_name = &s } -// HandleName returns the value of the "HandleName" field in the mutation. +// HandleName returns the value of the "handle_name" field in the mutation. func (m *UserMutation) HandleName() (r string, exists bool) { - v := m._HandleName + v := m.handle_name if v == nil { return } return *v, true } -// OldHandleName returns the old "HandleName" field's value of the User entity. +// OldHandleName returns the old "handle_name" 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) OldHandleName(ctx context.Context) (v string, err error) { @@ -729,9 +729,9 @@ func (m *UserMutation) OldHandleName(ctx context.Context) (v string, err error) return oldValue.HandleName, nil } -// ResetHandleName resets all changes to the "HandleName" field. +// ResetHandleName resets all changes to the "handle_name" field. func (m *UserMutation) ResetHandleName() { - m._HandleName = nil + m.handle_name = nil } // SetCreatedAt sets the "created_at" field. @@ -895,10 +895,10 @@ func (m *UserMutation) Type() string { // AddedFields(). func (m *UserMutation) Fields() []string { fields := make([]string, 0, 4) - if m._StudentNumber != nil { + if m.student_number != nil { fields = append(fields, user.FieldStudentNumber) } - if m._HandleName != nil { + if m.handle_name != nil { fields = append(fields, user.FieldHandleName) } if m.created_at != nil { diff --git a/typing-server/domain/repository/ent/runtime.go b/typing-server/domain/repository/ent/runtime.go index 7ac9c43..569ca40 100644 --- a/typing-server/domain/repository/ent/runtime.go +++ b/typing-server/domain/repository/ent/runtime.go @@ -23,22 +23,22 @@ func init() { score.DefaultID = scoreDescID.Default.(func() uuid.UUID) userFields := schema.User{}.Fields() _ = userFields - // userDescStudentNumber is the schema descriptor for StudentNumber field. + // userDescStudentNumber is the schema descriptor for student_number field. userDescStudentNumber := userFields[1].Descriptor() - // user.StudentNumberValidator is a validator for the "StudentNumber" field. It is called by the builders before save. + // user.StudentNumberValidator is a validator for the "student_number" field. It is called by the builders before save. user.StudentNumberValidator = userDescStudentNumber.Validators[0].(func(string) error) - // userDescHandleName is the schema descriptor for HandleName field. + // userDescHandleName is the schema descriptor for handle_name field. userDescHandleName := userFields[2].Descriptor() - // user.HandleNameValidator is a validator for the "HandleName" field. It is called by the builders before save. + // user.HandleNameValidator is a validator for the "handle_name" field. It is called by the builders before save. user.HandleNameValidator = func() func(string) error { validators := userDescHandleName.Validators fns := [...]func(string) error{ validators[0].(func(string) error), validators[1].(func(string) error), } - return func(_HandleName string) error { + return func(handle_name string) error { for _, fn := range fns { - if err := fn(_HandleName); err != nil { + if err := fn(handle_name); err != nil { return err } } diff --git a/typing-server/domain/repository/ent/schema/user.go b/typing-server/domain/repository/ent/schema/user.go index b4a949d..b2c3389 100644 --- a/typing-server/domain/repository/ent/schema/user.go +++ b/typing-server/domain/repository/ent/schema/user.go @@ -19,9 +19,9 @@ func (User) Fields() []ent.Field { //カラムとしてvarcher型(255)のMailAdress,varcher型(255)のHandleName,varcher型(255)のName,varcher型(255)のHashedPassword,enum型のDepartment,datetime型のCreatedAt,datetime型のUpdatedAtを持たせる return []ent.Field{ field.UUID("id", uuid.UUID{}).Default(uuid.New).StorageKey("id").Unique(), - field.String("StudentNumber").NotEmpty().Unique(), - // field.String("MailAdress").NotEmpty().MaxLen(255), - field.String("HandleName").NotEmpty().MaxLen(36), + field.String("student_number").NotEmpty().Unique(), + // field.String("mail_address").NotEmpty().MaxLen(255), + field.String("handle_name").NotEmpty().MaxLen(36), // field.String("Name").NotEmpty().MaxLen(36), // field.String("HashedPassword").NotEmpty().MaxLen(255), // field.Enum("Department").Values("CS", "BI", "IA"), diff --git a/typing-server/domain/repository/ent/user.go b/typing-server/domain/repository/ent/user.go index 23e39d5..48edffc 100644 --- a/typing-server/domain/repository/ent/user.go +++ b/typing-server/domain/repository/ent/user.go @@ -18,10 +18,10 @@ type User struct { config `json:"-"` // ID of the ent. ID uuid.UUID `json:"id,omitempty"` - // StudentNumber holds the value of the "StudentNumber" field. - StudentNumber string `json:"StudentNumber,omitempty"` - // HandleName holds the value of the "HandleName" field. - HandleName string `json:"HandleName,omitempty"` + // StudentNumber holds the value of the "student_number" field. + StudentNumber string `json:"student_number,omitempty"` + // HandleName holds the value of the "handle_name" field. + HandleName string `json:"handle_name,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. @@ -84,13 +84,13 @@ func (u *User) assignValues(columns []string, values []any) error { } case user.FieldStudentNumber: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field StudentNumber", values[i]) + return fmt.Errorf("unexpected type %T for field student_number", values[i]) } else if value.Valid { u.StudentNumber = value.String } case user.FieldHandleName: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field HandleName", values[i]) + return fmt.Errorf("unexpected type %T for field handle_name", values[i]) } else if value.Valid { u.HandleName = value.String } @@ -147,10 +147,10 @@ func (u *User) String() string { var builder strings.Builder builder.WriteString("User(") builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) - builder.WriteString("StudentNumber=") + builder.WriteString("student_number=") builder.WriteString(u.StudentNumber) builder.WriteString(", ") - builder.WriteString("HandleName=") + builder.WriteString("handle_name=") builder.WriteString(u.HandleName) builder.WriteString(", ") builder.WriteString("created_at=") diff --git a/typing-server/domain/repository/ent/user/user.go b/typing-server/domain/repository/ent/user/user.go index 0cf6fe4..46991e3 100644 --- a/typing-server/domain/repository/ent/user/user.go +++ b/typing-server/domain/repository/ent/user/user.go @@ -15,9 +15,9 @@ const ( Label = "user" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldStudentNumber holds the string denoting the studentnumber field in the database. + // FieldStudentNumber holds the string denoting the student_number field in the database. FieldStudentNumber = "student_number" - // FieldHandleName holds the string denoting the handlename field in the database. + // FieldHandleName holds the string denoting the handle_name field in the database. FieldHandleName = "handle_name" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" @@ -56,9 +56,9 @@ func ValidColumn(column string) bool { } var ( - // StudentNumberValidator is a validator for the "StudentNumber" field. It is called by the builders before save. + // StudentNumberValidator is a validator for the "student_number" field. It is called by the builders before save. StudentNumberValidator func(string) error - // HandleNameValidator is a validator for the "HandleName" field. It is called by the builders before save. + // HandleNameValidator is a validator for the "handle_name" field. It is called by the builders before save. HandleNameValidator func(string) error // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time @@ -78,12 +78,12 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByStudentNumber orders the results by the StudentNumber field. +// ByStudentNumber orders the results by the student_number field. func ByStudentNumber(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldStudentNumber, opts...).ToFunc() } -// ByHandleName orders the results by the HandleName field. +// ByHandleName orders the results by the handle_name field. func ByHandleName(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldHandleName, opts...).ToFunc() } diff --git a/typing-server/domain/repository/ent/user/where.go b/typing-server/domain/repository/ent/user/where.go index 0653f73..1cb262d 100644 --- a/typing-server/domain/repository/ent/user/where.go +++ b/typing-server/domain/repository/ent/user/where.go @@ -56,12 +56,12 @@ func IDLTE(id uuid.UUID) predicate.User { return predicate.User(sql.FieldLTE(FieldID, id)) } -// StudentNumber applies equality check predicate on the "StudentNumber" field. It's identical to StudentNumberEQ. +// StudentNumber applies equality check predicate on the "student_number" field. It's identical to StudentNumberEQ. func StudentNumber(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldStudentNumber, v)) } -// HandleName applies equality check predicate on the "HandleName" field. It's identical to HandleNameEQ. +// HandleName applies equality check predicate on the "handle_name" field. It's identical to HandleNameEQ. func HandleName(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldHandleName, v)) } @@ -76,132 +76,132 @@ func UpdatedAt(v time.Time) predicate.User { return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) } -// StudentNumberEQ applies the EQ predicate on the "StudentNumber" field. +// StudentNumberEQ applies the EQ predicate on the "student_number" field. func StudentNumberEQ(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldStudentNumber, v)) } -// StudentNumberNEQ applies the NEQ predicate on the "StudentNumber" field. +// StudentNumberNEQ applies the NEQ predicate on the "student_number" field. func StudentNumberNEQ(v string) predicate.User { return predicate.User(sql.FieldNEQ(FieldStudentNumber, v)) } -// StudentNumberIn applies the In predicate on the "StudentNumber" field. +// StudentNumberIn applies the In predicate on the "student_number" field. func StudentNumberIn(vs ...string) predicate.User { return predicate.User(sql.FieldIn(FieldStudentNumber, vs...)) } -// StudentNumberNotIn applies the NotIn predicate on the "StudentNumber" field. +// StudentNumberNotIn applies the NotIn predicate on the "student_number" field. func StudentNumberNotIn(vs ...string) predicate.User { return predicate.User(sql.FieldNotIn(FieldStudentNumber, vs...)) } -// StudentNumberGT applies the GT predicate on the "StudentNumber" field. +// StudentNumberGT applies the GT predicate on the "student_number" field. func StudentNumberGT(v string) predicate.User { return predicate.User(sql.FieldGT(FieldStudentNumber, v)) } -// StudentNumberGTE applies the GTE predicate on the "StudentNumber" field. +// StudentNumberGTE applies the GTE predicate on the "student_number" field. func StudentNumberGTE(v string) predicate.User { return predicate.User(sql.FieldGTE(FieldStudentNumber, v)) } -// StudentNumberLT applies the LT predicate on the "StudentNumber" field. +// StudentNumberLT applies the LT predicate on the "student_number" field. func StudentNumberLT(v string) predicate.User { return predicate.User(sql.FieldLT(FieldStudentNumber, v)) } -// StudentNumberLTE applies the LTE predicate on the "StudentNumber" field. +// StudentNumberLTE applies the LTE predicate on the "student_number" field. func StudentNumberLTE(v string) predicate.User { return predicate.User(sql.FieldLTE(FieldStudentNumber, v)) } -// StudentNumberContains applies the Contains predicate on the "StudentNumber" field. +// StudentNumberContains applies the Contains predicate on the "student_number" field. func StudentNumberContains(v string) predicate.User { return predicate.User(sql.FieldContains(FieldStudentNumber, v)) } -// StudentNumberHasPrefix applies the HasPrefix predicate on the "StudentNumber" field. +// StudentNumberHasPrefix applies the HasPrefix predicate on the "student_number" field. func StudentNumberHasPrefix(v string) predicate.User { return predicate.User(sql.FieldHasPrefix(FieldStudentNumber, v)) } -// StudentNumberHasSuffix applies the HasSuffix predicate on the "StudentNumber" field. +// StudentNumberHasSuffix applies the HasSuffix predicate on the "student_number" field. func StudentNumberHasSuffix(v string) predicate.User { return predicate.User(sql.FieldHasSuffix(FieldStudentNumber, v)) } -// StudentNumberEqualFold applies the EqualFold predicate on the "StudentNumber" field. +// StudentNumberEqualFold applies the EqualFold predicate on the "student_number" field. func StudentNumberEqualFold(v string) predicate.User { return predicate.User(sql.FieldEqualFold(FieldStudentNumber, v)) } -// StudentNumberContainsFold applies the ContainsFold predicate on the "StudentNumber" field. +// StudentNumberContainsFold applies the ContainsFold predicate on the "student_number" field. func StudentNumberContainsFold(v string) predicate.User { return predicate.User(sql.FieldContainsFold(FieldStudentNumber, v)) } -// HandleNameEQ applies the EQ predicate on the "HandleName" field. +// HandleNameEQ applies the EQ predicate on the "handle_name" field. func HandleNameEQ(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldHandleName, v)) } -// HandleNameNEQ applies the NEQ predicate on the "HandleName" field. +// HandleNameNEQ applies the NEQ predicate on the "handle_name" field. func HandleNameNEQ(v string) predicate.User { return predicate.User(sql.FieldNEQ(FieldHandleName, v)) } -// HandleNameIn applies the In predicate on the "HandleName" field. +// HandleNameIn applies the In predicate on the "handle_name" field. func HandleNameIn(vs ...string) predicate.User { return predicate.User(sql.FieldIn(FieldHandleName, vs...)) } -// HandleNameNotIn applies the NotIn predicate on the "HandleName" field. +// HandleNameNotIn applies the NotIn predicate on the "handle_name" field. func HandleNameNotIn(vs ...string) predicate.User { return predicate.User(sql.FieldNotIn(FieldHandleName, vs...)) } -// HandleNameGT applies the GT predicate on the "HandleName" field. +// HandleNameGT applies the GT predicate on the "handle_name" field. func HandleNameGT(v string) predicate.User { return predicate.User(sql.FieldGT(FieldHandleName, v)) } -// HandleNameGTE applies the GTE predicate on the "HandleName" field. +// HandleNameGTE applies the GTE predicate on the "handle_name" field. func HandleNameGTE(v string) predicate.User { return predicate.User(sql.FieldGTE(FieldHandleName, v)) } -// HandleNameLT applies the LT predicate on the "HandleName" field. +// HandleNameLT applies the LT predicate on the "handle_name" field. func HandleNameLT(v string) predicate.User { return predicate.User(sql.FieldLT(FieldHandleName, v)) } -// HandleNameLTE applies the LTE predicate on the "HandleName" field. +// HandleNameLTE applies the LTE predicate on the "handle_name" field. func HandleNameLTE(v string) predicate.User { return predicate.User(sql.FieldLTE(FieldHandleName, v)) } -// HandleNameContains applies the Contains predicate on the "HandleName" field. +// HandleNameContains applies the Contains predicate on the "handle_name" field. func HandleNameContains(v string) predicate.User { return predicate.User(sql.FieldContains(FieldHandleName, v)) } -// HandleNameHasPrefix applies the HasPrefix predicate on the "HandleName" field. +// HandleNameHasPrefix applies the HasPrefix predicate on the "handle_name" field. func HandleNameHasPrefix(v string) predicate.User { return predicate.User(sql.FieldHasPrefix(FieldHandleName, v)) } -// HandleNameHasSuffix applies the HasSuffix predicate on the "HandleName" field. +// HandleNameHasSuffix applies the HasSuffix predicate on the "handle_name" field. func HandleNameHasSuffix(v string) predicate.User { return predicate.User(sql.FieldHasSuffix(FieldHandleName, v)) } -// HandleNameEqualFold applies the EqualFold predicate on the "HandleName" field. +// HandleNameEqualFold applies the EqualFold predicate on the "handle_name" field. func HandleNameEqualFold(v string) predicate.User { return predicate.User(sql.FieldEqualFold(FieldHandleName, v)) } -// HandleNameContainsFold applies the ContainsFold predicate on the "HandleName" field. +// HandleNameContainsFold applies the ContainsFold predicate on the "handle_name" field. func HandleNameContainsFold(v string) predicate.User { return predicate.User(sql.FieldContainsFold(FieldHandleName, v)) } diff --git a/typing-server/domain/repository/ent/user_create.go b/typing-server/domain/repository/ent/user_create.go index c2864ac..edae558 100644 --- a/typing-server/domain/repository/ent/user_create.go +++ b/typing-server/domain/repository/ent/user_create.go @@ -22,13 +22,13 @@ type UserCreate struct { hooks []Hook } -// SetStudentNumber sets the "StudentNumber" field. +// SetStudentNumber sets the "student_number" field. func (uc *UserCreate) SetStudentNumber(s string) *UserCreate { uc.mutation.SetStudentNumber(s) return uc } -// SetHandleName sets the "HandleName" field. +// SetHandleName sets the "handle_name" field. func (uc *UserCreate) SetHandleName(s string) *UserCreate { uc.mutation.SetHandleName(s) return uc @@ -143,19 +143,19 @@ func (uc *UserCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (uc *UserCreate) check() error { if _, ok := uc.mutation.StudentNumber(); !ok { - return &ValidationError{Name: "StudentNumber", err: errors.New(`ent: missing required field "User.StudentNumber"`)} + return &ValidationError{Name: "student_number", err: errors.New(`ent: missing required field "User.student_number"`)} } if v, ok := uc.mutation.StudentNumber(); ok { if err := user.StudentNumberValidator(v); err != nil { - return &ValidationError{Name: "StudentNumber", err: fmt.Errorf(`ent: validator failed for field "User.StudentNumber": %w`, err)} + return &ValidationError{Name: "student_number", err: fmt.Errorf(`ent: validator failed for field "User.student_number": %w`, err)} } } if _, ok := uc.mutation.HandleName(); !ok { - return &ValidationError{Name: "HandleName", err: errors.New(`ent: missing required field "User.HandleName"`)} + return &ValidationError{Name: "handle_name", err: errors.New(`ent: missing required field "User.handle_name"`)} } if v, ok := uc.mutation.HandleName(); ok { if err := user.HandleNameValidator(v); err != nil { - return &ValidationError{Name: "HandleName", err: fmt.Errorf(`ent: validator failed for field "User.HandleName": %w`, err)} + return &ValidationError{Name: "handle_name", err: fmt.Errorf(`ent: validator failed for field "User.handle_name": %w`, err)} } } if _, ok := uc.mutation.CreatedAt(); !ok { diff --git a/typing-server/domain/repository/ent/user_query.go b/typing-server/domain/repository/ent/user_query.go index c88c6f5..a5b89b7 100644 --- a/typing-server/domain/repository/ent/user_query.go +++ b/typing-server/domain/repository/ent/user_query.go @@ -299,7 +299,7 @@ func (uq *UserQuery) WithScores(opts ...func(*ScoreQuery)) *UserQuery { // Example: // // var v []struct { -// StudentNumber string `json:"StudentNumber,omitempty"` +// StudentNumber string `json:"student_number,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -322,7 +322,7 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { // Example: // // var v []struct { -// StudentNumber string `json:"StudentNumber,omitempty"` +// StudentNumber string `json:"student_number,omitempty"` // } // // client.User.Query(). diff --git a/typing-server/domain/repository/ent/user_update.go b/typing-server/domain/repository/ent/user_update.go index 98f1d92..68c90b6 100644 --- a/typing-server/domain/repository/ent/user_update.go +++ b/typing-server/domain/repository/ent/user_update.go @@ -30,13 +30,13 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate { return uu } -// SetStudentNumber sets the "StudentNumber" field. +// SetStudentNumber sets the "student_number" field. func (uu *UserUpdate) SetStudentNumber(s string) *UserUpdate { uu.mutation.SetStudentNumber(s) return uu } -// SetNillableStudentNumber sets the "StudentNumber" field if the given value is not nil. +// SetNillableStudentNumber sets the "student_number" field if the given value is not nil. func (uu *UserUpdate) SetNillableStudentNumber(s *string) *UserUpdate { if s != nil { uu.SetStudentNumber(*s) @@ -44,13 +44,13 @@ func (uu *UserUpdate) SetNillableStudentNumber(s *string) *UserUpdate { return uu } -// SetHandleName sets the "HandleName" field. +// SetHandleName sets the "handle_name" field. func (uu *UserUpdate) SetHandleName(s string) *UserUpdate { uu.mutation.SetHandleName(s) return uu } -// SetNillableHandleName sets the "HandleName" field if the given value is not nil. +// SetNillableHandleName sets the "handle_name" field if the given value is not nil. func (uu *UserUpdate) SetNillableHandleName(s *string) *UserUpdate { if s != nil { uu.SetHandleName(*s) @@ -145,12 +145,12 @@ func (uu *UserUpdate) defaults() { func (uu *UserUpdate) check() error { if v, ok := uu.mutation.StudentNumber(); ok { if err := user.StudentNumberValidator(v); err != nil { - return &ValidationError{Name: "StudentNumber", err: fmt.Errorf(`ent: validator failed for field "User.StudentNumber": %w`, err)} + return &ValidationError{Name: "student_number", err: fmt.Errorf(`ent: validator failed for field "User.student_number": %w`, err)} } } if v, ok := uu.mutation.HandleName(); ok { if err := user.HandleNameValidator(v); err != nil { - return &ValidationError{Name: "HandleName", err: fmt.Errorf(`ent: validator failed for field "User.HandleName": %w`, err)} + return &ValidationError{Name: "handle_name", err: fmt.Errorf(`ent: validator failed for field "User.handle_name": %w`, err)} } } return nil @@ -242,13 +242,13 @@ type UserUpdateOne struct { mutation *UserMutation } -// SetStudentNumber sets the "StudentNumber" field. +// SetStudentNumber sets the "student_number" field. func (uuo *UserUpdateOne) SetStudentNumber(s string) *UserUpdateOne { uuo.mutation.SetStudentNumber(s) return uuo } -// SetNillableStudentNumber sets the "StudentNumber" field if the given value is not nil. +// SetNillableStudentNumber sets the "student_number" field if the given value is not nil. func (uuo *UserUpdateOne) SetNillableStudentNumber(s *string) *UserUpdateOne { if s != nil { uuo.SetStudentNumber(*s) @@ -256,13 +256,13 @@ func (uuo *UserUpdateOne) SetNillableStudentNumber(s *string) *UserUpdateOne { return uuo } -// SetHandleName sets the "HandleName" field. +// SetHandleName sets the "handle_name" field. func (uuo *UserUpdateOne) SetHandleName(s string) *UserUpdateOne { uuo.mutation.SetHandleName(s) return uuo } -// SetNillableHandleName sets the "HandleName" field if the given value is not nil. +// SetNillableHandleName sets the "handle_name" field if the given value is not nil. func (uuo *UserUpdateOne) SetNillableHandleName(s *string) *UserUpdateOne { if s != nil { uuo.SetHandleName(*s) @@ -370,12 +370,12 @@ func (uuo *UserUpdateOne) defaults() { func (uuo *UserUpdateOne) check() error { if v, ok := uuo.mutation.StudentNumber(); ok { if err := user.StudentNumberValidator(v); err != nil { - return &ValidationError{Name: "StudentNumber", err: fmt.Errorf(`ent: validator failed for field "User.StudentNumber": %w`, err)} + return &ValidationError{Name: "student_number", err: fmt.Errorf(`ent: validator failed for field "User.student_number": %w`, err)} } } if v, ok := uuo.mutation.HandleName(); ok { if err := user.HandleNameValidator(v); err != nil { - return &ValidationError{Name: "HandleName", err: fmt.Errorf(`ent: validator failed for field "User.HandleName": %w`, err)} + return &ValidationError{Name: "handle_name", err: fmt.Errorf(`ent: validator failed for field "User.handle_name": %w`, err)} } } return nil From c68e5d51aab430c84f66d39d54cf92efa38d172b Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Sat, 23 Mar 2024 15:29:11 +0900 Subject: [PATCH 6/6] =?UTF-8?q?docs:=20=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typing-app/docs/get-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typing-app/docs/get-started.md b/typing-app/docs/get-started.md index 4ba5bae..a6dbbce 100644 --- a/typing-app/docs/get-started.md +++ b/typing-app/docs/get-started.md @@ -15,7 +15,7 @@ $ cd typing/typing-app $ curl -fsSL https://bun.sh/install | bash ``` -### プロジェクトの依存パッケージをインストール +### プロジェクトの依存パッケージをインストール(typing-app ディレクトリで実行) ```bash $ bun install @@ -24,7 +24,7 @@ $ bun install ## 3. API & DB の起動(typing-server ディレクトリで実行) ```bash -$ docker-compose --file docker-compose.dev.yml up +$ docker-compose --file docker-compose.dev.yml up --build ``` ## 4. フロントエンドの起動(typing-app ディレクトリで実行)