package mysql import ( "context" "database/sql" "git.aiterp.net/stufflog3/stufflog3/entities" "git.aiterp.net/stufflog3/stufflog3/models" "git.aiterp.net/stufflog3/stufflog3/ports/mysql/mysqlcore" "time" ) type sprintRepository struct { db *sql.DB q *mysqlcore.Queries } func (r *sprintRepository) Find(ctx context.Context, scopeID, sprintID int) (*entities.Sprint, error) { row, err := r.q.GetSprint(ctx, mysqlcore.GetSprintParams{ScopeID: scopeID, ID: sprintID}) if err != nil { if err == sql.ErrNoRows { return nil, models.NotFoundError("Sprint") } return nil, err } return &entities.Sprint{ ID: row.ID, ScopeID: row.ScopeID, Name: row.Name, Description: row.Description, Kind: models.SprintKind(row.Kind), FromTime: row.FromTime, ToTime: row.ToTime, IsTimed: row.IsTimed, IsCoarse: row.IsCoarse, IsUnweighted: row.IsUnweighted, AggregateName: row.AggregateName, AggregateRequired: row.AggregateRequired, }, nil } func (r *sprintRepository) ListAt(ctx context.Context, scopeID int, at time.Time) ([]entities.Sprint, error) { rows, err := r.q.ListSprintsAt(ctx, mysqlcore.ListSprintsAtParams{ScopeID: scopeID, Time: at}) if err != nil { if err == sql.ErrNoRows { return nil, models.NotFoundError("Sprint") } return nil, err } sprints := make([]entities.Sprint, 0, len(rows)) for _, row := range rows { sprints = append(sprints, entities.Sprint{ ID: row.ID, ScopeID: row.ScopeID, Name: row.Name, Description: row.Description, Kind: models.SprintKind(row.Kind), FromTime: row.FromTime, ToTime: row.ToTime, IsTimed: row.IsTimed, IsCoarse: row.IsCoarse, IsUnweighted: row.IsUnweighted, AggregateName: row.AggregateName, AggregateRequired: row.AggregateRequired, }) } return sprints, nil } func (r *sprintRepository) ListBetween(ctx context.Context, scopeID int, from, to time.Time) ([]entities.Sprint, error) { rows, err := r.q.ListSprintsBetween(ctx, mysqlcore.ListSprintsBetweenParams{ ScopeID: scopeID, FromTime: from, ToTime: from, FromTime_2: to, ToTime_2: to, FromTime_3: from, ToTime_3: to, }) if err != nil { if err == sql.ErrNoRows { return nil, models.NotFoundError("Sprint") } return nil, err } sprints := make([]entities.Sprint, 0, len(rows)) for _, row := range rows { sprints = append(sprints, entities.Sprint{ ID: row.ID, ScopeID: row.ScopeID, Name: row.Name, Description: row.Description, Kind: models.SprintKind(row.Kind), FromTime: row.FromTime, ToTime: row.ToTime, IsTimed: row.IsTimed, IsCoarse: row.IsCoarse, IsUnweighted: row.IsUnweighted, AggregateName: row.AggregateName, AggregateRequired: row.AggregateRequired, }) } return sprints, nil } func (r *sprintRepository) Create(ctx context.Context, sprint entities.Sprint) (*entities.Sprint, error) { //TODO implement me panic("implement me") } func (r *sprintRepository) Update(ctx context.Context, sprint entities.Sprint, update models.SprintUpdate) error { //TODO implement me panic("implement me") } func (r *sprintRepository) Delete(ctx context.Context, sprint entities.Sprint) error { //TODO implement me panic("implement me") }