Gisle Aune
2 years ago
29 changed files with 1000 additions and 59 deletions
-
27entities/scope.go
-
5entities/sprint.go
-
1entities/stat.go
-
1models/item.go
-
5models/scope.go
-
16ports/httpapi/items.go
-
2ports/httpapi/scopes.go
-
37ports/mysql/db.go
-
76ports/mysql/items.go
-
140ports/mysql/mysqlcore/db.go
-
29ports/mysql/mysqlcore/items.sql.go
-
27ports/mysql/mysqlcore/projects.sql.go
-
12ports/mysql/mysqlcore/scopes.sql.go
-
247ports/mysql/mysqlcore/sprint.sql.go
-
9ports/mysql/mysqlcore/stats.sql.go
-
7ports/mysql/queries/items.sql
-
9ports/mysql/queries/projects.sql
-
4ports/mysql/queries/scopes.sql
-
40ports/mysql/queries/sprint.sql
-
3ports/mysql/queries/stats.sql
-
83ports/mysql/scopes.go
-
126ports/mysql/sprint.go
-
57ports/mysql/stats.go
-
25usecases/items/service.go
-
16usecases/projects/result.go
-
2usecases/scopes/context.go
-
32usecases/scopes/result.go
-
4usecases/scopes/service.go
-
17usecases/sprints/repository.go
@ -1,6 +1,7 @@ |
|||
package models |
|||
|
|||
type ScopeUpdate struct { |
|||
Name *string |
|||
Abbreviation *string |
|||
Name *string `json:"name"` |
|||
Abbreviation *string `json:"abbreviation"` |
|||
CustomLabels map[string]*string `json:"customLabels"` |
|||
} |
@ -0,0 +1,247 @@ |
|||
// Code generated by sqlc. DO NOT EDIT.
|
|||
// versions:
|
|||
// sqlc v1.13.0
|
|||
// source: sprint.sql
|
|||
|
|||
package mysqlcore |
|||
|
|||
import ( |
|||
"context" |
|||
"database/sql" |
|||
"time" |
|||
) |
|||
|
|||
const deleteAllScopeSprints = `-- name: DeleteAllScopeSprints :exec |
|||
DELETE FROM sprint WHERE scope_id = ? |
|||
` |
|||
|
|||
func (q *Queries) DeleteAllScopeSprints(ctx context.Context, scopeID int) error { |
|||
_, err := q.exec(ctx, q.deleteAllScopeSprintsStmt, deleteAllScopeSprints, scopeID) |
|||
return err |
|||
} |
|||
|
|||
const deleteSprint = `-- name: DeleteSprint :exec |
|||
DELETE FROM sprint WHERE id = ? |
|||
` |
|||
|
|||
func (q *Queries) DeleteSprint(ctx context.Context, id int) error { |
|||
_, err := q.exec(ctx, q.deleteSprintStmt, deleteSprint, id) |
|||
return err |
|||
} |
|||
|
|||
const getSprint = `-- name: GetSprint :one |
|||
SELECT id, scope_id, name, description, from_time, to_time, is_timed, is_coarse, is_unweighted, kind, aggregate_name, aggregate_required FROM sprint WHERE id = ? AND scope_id = ? |
|||
` |
|||
|
|||
type GetSprintParams struct { |
|||
ID int |
|||
ScopeID int |
|||
} |
|||
|
|||
func (q *Queries) GetSprint(ctx context.Context, arg GetSprintParams) (Sprint, error) { |
|||
row := q.queryRow(ctx, q.getSprintStmt, getSprint, arg.ID, arg.ScopeID) |
|||
var i Sprint |
|||
err := row.Scan( |
|||
&i.ID, |
|||
&i.ScopeID, |
|||
&i.Name, |
|||
&i.Description, |
|||
&i.FromTime, |
|||
&i.ToTime, |
|||
&i.IsTimed, |
|||
&i.IsCoarse, |
|||
&i.IsUnweighted, |
|||
&i.Kind, |
|||
&i.AggregateName, |
|||
&i.AggregateRequired, |
|||
) |
|||
return i, err |
|||
} |
|||
|
|||
const insertSprint = `-- name: InsertSprint :execresult |
|||
INSERT INTO sprint ( |
|||
scope_id, name, description, kind, from_time, to_time, |
|||
is_timed, is_coarse, aggregate_name, aggregate_required, is_unweighted |
|||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|||
` |
|||
|
|||
type InsertSprintParams struct { |
|||
ScopeID int |
|||
Name string |
|||
Description string |
|||
Kind int |
|||
FromTime time.Time |
|||
ToTime time.Time |
|||
IsTimed bool |
|||
IsCoarse bool |
|||
AggregateName string |
|||
AggregateRequired int |
|||
IsUnweighted bool |
|||
} |
|||
|
|||
func (q *Queries) InsertSprint(ctx context.Context, arg InsertSprintParams) (sql.Result, error) { |
|||
return q.exec(ctx, q.insertSprintStmt, insertSprint, |
|||
arg.ScopeID, |
|||
arg.Name, |
|||
arg.Description, |
|||
arg.Kind, |
|||
arg.FromTime, |
|||
arg.ToTime, |
|||
arg.IsTimed, |
|||
arg.IsCoarse, |
|||
arg.AggregateName, |
|||
arg.AggregateRequired, |
|||
arg.IsUnweighted, |
|||
) |
|||
} |
|||
|
|||
const listSprintsAt = `-- name: ListSprintsAt :many |
|||
SELECT id, scope_id, name, description, from_time, to_time, is_timed, is_coarse, is_unweighted, kind, aggregate_name, aggregate_required FROM sprint WHERE scope_id = ? AND from_time <= ? AND to_time > ? |
|||
` |
|||
|
|||
type ListSprintsAtParams struct { |
|||
ScopeID int |
|||
Time time.Time |
|||
} |
|||
|
|||
func (q *Queries) ListSprintsAt(ctx context.Context, arg ListSprintsAtParams) ([]Sprint, error) { |
|||
rows, err := q.query(ctx, q.listSprintsAtStmt, listSprintsAt, arg.ScopeID, arg.Time, arg.Time) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
defer rows.Close() |
|||
items := []Sprint{} |
|||
for rows.Next() { |
|||
var i Sprint |
|||
if err := rows.Scan( |
|||
&i.ID, |
|||
&i.ScopeID, |
|||
&i.Name, |
|||
&i.Description, |
|||
&i.FromTime, |
|||
&i.ToTime, |
|||
&i.IsTimed, |
|||
&i.IsCoarse, |
|||
&i.IsUnweighted, |
|||
&i.Kind, |
|||
&i.AggregateName, |
|||
&i.AggregateRequired, |
|||
); err != nil { |
|||
return nil, err |
|||
} |
|||
items = append(items, i) |
|||
} |
|||
if err := rows.Close(); err != nil { |
|||
return nil, err |
|||
} |
|||
if err := rows.Err(); err != nil { |
|||
return nil, err |
|||
} |
|||
return items, nil |
|||
} |
|||
|
|||
const listSprintsBetween = `-- name: ListSprintsBetween :many |
|||
SELECT id, scope_id, name, description, from_time, to_time, is_timed, is_coarse, is_unweighted, kind, aggregate_name, aggregate_required FROM sprint WHERE scope_id = ? |
|||
AND ( |
|||
-- from time is within from..to |
|||
(from_time <= ? AND to_time > ?) |
|||
-- or to time is within from..to |
|||
OR (from_time <= ? AND to_time > ?) |
|||
-- or from and to time are on each their side of from..to |
|||
OR (from_time < ? AND to_time >= ?) |
|||
) |
|||
` |
|||
|
|||
type ListSprintsBetweenParams struct { |
|||
ScopeID int |
|||
FromTime time.Time |
|||
ToTime time.Time |
|||
FromTime_2 time.Time |
|||
ToTime_2 time.Time |
|||
FromTime_3 time.Time |
|||
ToTime_3 time.Time |
|||
} |
|||
|
|||
func (q *Queries) ListSprintsBetween(ctx context.Context, arg ListSprintsBetweenParams) ([]Sprint, error) { |
|||
rows, err := q.query(ctx, q.listSprintsBetweenStmt, listSprintsBetween, |
|||
arg.ScopeID, |
|||
arg.FromTime, |
|||
arg.ToTime, |
|||
arg.FromTime_2, |
|||
arg.ToTime_2, |
|||
arg.FromTime_3, |
|||
arg.ToTime_3, |
|||
) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
defer rows.Close() |
|||
items := []Sprint{} |
|||
for rows.Next() { |
|||
var i Sprint |
|||
if err := rows.Scan( |
|||
&i.ID, |
|||
&i.ScopeID, |
|||
&i.Name, |
|||
&i.Description, |
|||
&i.FromTime, |
|||
&i.ToTime, |
|||
&i.IsTimed, |
|||
&i.IsCoarse, |
|||
&i.IsUnweighted, |
|||
&i.Kind, |
|||
&i.AggregateName, |
|||
&i.AggregateRequired, |
|||
); err != nil { |
|||
return nil, err |
|||
} |
|||
items = append(items, i) |
|||
} |
|||
if err := rows.Close(); err != nil { |
|||
return nil, err |
|||
} |
|||
if err := rows.Err(); err != nil { |
|||
return nil, err |
|||
} |
|||
return items, nil |
|||
} |
|||
|
|||
const updateSprint = `-- name: UpdateSprint :exec |
|||
UPDATE sprint |
|||
SET name = ?, |
|||
description = ?, |
|||
from_time = ?, |
|||
to_time = ?, |
|||
is_timed = ?, |
|||
is_coarse = ?, |
|||
aggregate_name = ?, |
|||
aggregate_required = ? |
|||
WHERE id = ? |
|||
` |
|||
|
|||
type UpdateSprintParams struct { |
|||
Name string |
|||
Description string |
|||
FromTime time.Time |
|||
ToTime time.Time |
|||
IsTimed bool |
|||
IsCoarse bool |
|||
AggregateName string |
|||
AggregateRequired int |
|||
ID int |
|||
} |
|||
|
|||
func (q *Queries) UpdateSprint(ctx context.Context, arg UpdateSprintParams) error { |
|||
_, err := q.exec(ctx, q.updateSprintStmt, updateSprint, |
|||
arg.Name, |
|||
arg.Description, |
|||
arg.FromTime, |
|||
arg.ToTime, |
|||
arg.IsTimed, |
|||
arg.IsCoarse, |
|||
arg.AggregateName, |
|||
arg.AggregateRequired, |
|||
arg.ID, |
|||
) |
|||
return err |
|||
} |
@ -0,0 +1,40 @@ |
|||
-- name: ListSprintsAt :many |
|||
SELECT * FROM sprint WHERE scope_id = ? AND from_time <= sqlc.arg(time) AND to_time > sqlc.arg(time); |
|||
|
|||
-- name: ListSprintsBetween :many |
|||
SELECT * FROM sprint WHERE scope_id = ? |
|||
AND ( |
|||
-- from time is within from..to |
|||
(from_time <= ? AND to_time > ?) |
|||
-- or to time is within from..to |
|||
OR (from_time <= ? AND to_time > ?) |
|||
-- or from and to time are on each their side of from..to |
|||
OR (from_time < ? AND to_time >= ?) |
|||
); |
|||
|
|||
-- name: GetSprint :one |
|||
SELECT * FROM sprint WHERE id = ? AND scope_id = ?; |
|||
|
|||
-- name: InsertSprint :execresult |
|||
INSERT INTO sprint ( |
|||
scope_id, name, description, kind, from_time, to_time, |
|||
is_timed, is_coarse, aggregate_name, aggregate_required, is_unweighted |
|||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); |
|||
|
|||
-- name: UpdateSprint :exec |
|||
UPDATE sprint |
|||
SET name = ?, |
|||
description = ?, |
|||
from_time = ?, |
|||
to_time = ?, |
|||
is_timed = ?, |
|||
is_coarse = ?, |
|||
aggregate_name = ?, |
|||
aggregate_required = ? |
|||
WHERE id = ?; |
|||
|
|||
-- name: DeleteSprint :exec |
|||
DELETE FROM sprint WHERE id = ?; |
|||
|
|||
-- name: DeleteAllScopeSprints :exec |
|||
DELETE FROM sprint WHERE scope_id = ?; |
@ -0,0 +1,126 @@ |
|||
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") |
|||
} |
@ -0,0 +1,32 @@ |
|||
package scopes |
|||
|
|||
import "git.aiterp.net/stufflog3/stufflog3/entities" |
|||
|
|||
type Result struct { |
|||
entities.Scope |
|||
|
|||
Members []ResultMember `json:"members"` |
|||
} |
|||
|
|||
type ResultMember struct { |
|||
ID string `json:"id"` |
|||
Name string `json:"name"` |
|||
Owner bool `json:"owner"` |
|||
} |
|||
|
|||
func generateResult(scope entities.Scope, members []entities.ScopeMember) Result { |
|||
res := Result{Scope: scope, Members: make([]ResultMember, 0, 2)} |
|||
for _, member := range members { |
|||
if member.ScopeID != scope.ID { |
|||
continue |
|||
} |
|||
|
|||
res.Members = append(res.Members, ResultMember{ |
|||
ID: member.UserID, |
|||
Name: member.Name, |
|||
Owner: member.Owner, |
|||
}) |
|||
} |
|||
|
|||
return res |
|||
} |
@ -0,0 +1,17 @@ |
|||
package sprints |
|||
|
|||
import ( |
|||
"context" |
|||
"git.aiterp.net/stufflog3/stufflog3/entities" |
|||
"git.aiterp.net/stufflog3/stufflog3/models" |
|||
"time" |
|||
) |
|||
|
|||
type Repository interface { |
|||
Find(ctx context.Context, scopeID, sprintID int) (*entities.Sprint, error) |
|||
ListAt(ctx context.Context, scopeID int, at time.Time) ([]entities.Sprint, error) |
|||
ListBetween(ctx context.Context, scopeID int, from, to time.Time) ([]entities.Sprint, error) |
|||
Create(ctx context.Context, sprint entities.Sprint) (*entities.Sprint, error) |
|||
Update(ctx context.Context, sprint entities.Sprint, update models.SprintUpdate) error |
|||
Delete(ctx context.Context, sprint entities.Sprint) error |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue