Skip to content

Commit ff0e530

Browse files
authored
Merge pull request #78 from CodeChefVIT/feat/score
update score routes and docs
2 parents 150d241 + f3283dd commit ff0e530

File tree

9 files changed

+350
-18
lines changed

9 files changed

+350
-18
lines changed

database/queries/score.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
-- name: GetTeamScores :many
2-
SELECT * FROM score WHERE team_id = $1;
2+
SELECT id, team_id, design, implementation, presentation, round, innovation, teamwork, comment
3+
FROM score
4+
WHERE team_id = $1;
35

46
-- name: CreateScore :exec
5-
INSERT INTO score (id, team_id, design, implementation, presentation, round)
6-
VALUES ($1, $2, $3, $4, $5, $6);
7+
INSERT INTO score (id, team_id, design, implementation, presentation, round, innovation, teamwork, comment)
8+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
79

810
-- name: UpdateScore :exec
911
UPDATE score
10-
SET team_id = $1, design = $2, implementation = $3, presentation = $4, round = $5
11-
WHERE id = $6;
12+
SET team_id = $1, design = $2, implementation = $3, presentation = $4, round = $5, innovation = $6, teamwork = $7, comment = $8
13+
WHERE id = $9;
1214

1315
-- name: DeleteScore :exec
1416
DELETE FROM score
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose Up
2+
ALTER TABLE score
3+
ADD COLUMN innovation INTEGER NOT NULL DEFAULT 0,
4+
ADD COLUMN teamwork INTEGER NOT NULL DEFAULT 0,
5+
ADD COLUMN comment TEXT;
6+
7+
-- +goose Down
8+
ALTER TABLE score
9+
DROP COLUMN innovation,
10+
DROP COLUMN teamwork,
11+
DROP COLUMN comment;

docs/sample.yaml

Lines changed: 280 additions & 6 deletions
Large diffs are not rendered by default.

pkg/controller/panel.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func UpdateScore(c echo.Context) error {
8686
Design: int32(points.Design),
8787
Implementation: int32(points.Implementation),
8888
Presentation: int32(points.Presentation),
89+
Teamwork: int32(points.Teamwork),
90+
Innovation: int32(points.Innovation),
91+
Comment: &points.Comment,
8992
Round: int32(points.Round),
9093
}
9194

@@ -166,6 +169,9 @@ func CreateScore(c echo.Context) error {
166169
Round: int32(points.Round),
167170
Presentation: int32(points.Presentation),
168171
Implementation: int32(points.Implementation),
172+
Teamwork: int32(points.Teamwork),
173+
Comment: &points.Comment,
174+
Innovation: int32(points.Innovation),
169175
Design: int32(points.Design),
170176
}
171177
score.ID, _ = uuid.NewV7()

pkg/controller/score.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,24 @@ func GetScore(c echo.Context) error {
4141
})
4242
}
4343

44+
if len(teamScore) == 0 {
45+
return c.JSON(http.StatusNotFound, &models.Response{
46+
Status: "fail",
47+
Message: "No scores found for the given team ID"},
48+
)
49+
}
50+
4451
scores := make([]models.GetScore, len(teamScore))
4552
for i := 0; i < len(teamScore); i++ {
4653
scores[i] = models.GetScore{
4754
Id: teamScore[i].ID.String(),
4855
TeamID: teamId,
4956
Design: int(teamScore[i].Design),
5057
Implementation: int(teamScore[i].Implementation),
51-
Presentation: int(teamScore[i].Implementation),
58+
Presentation: int(teamScore[i].Presentation),
59+
Innovation: int(teamScore[i].Innovation),
60+
Teamwork: int(teamScore[i].Teamwork),
61+
Comment: getSafeString(teamScore[i].Comment),
5262
Round: int(teamScore[i].Round),
5363
}
5464
}

pkg/db/models.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/score.sql.go

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/models/panel.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type UpdateScore struct {
1616
Implementation int `json:"implementation" validate:"required,min=0,max=10"`
1717
Presentation int `json:"presentation" validate:"required,min=0,max=10"`
1818
Round int `json:"round" validate:"required"`
19+
Innovation int `json:"innovation" validate:"required,min=0,max=10"`
20+
Teamwork int `json:"teamwork" validate:"required,min=0,max=10"`
21+
Comment string `json:"comment"`
1922
TeamID string `json:"team_id" validate:"required,uuid"`
2023
}
2124

@@ -24,5 +27,8 @@ type CreateScore struct {
2427
Implementation int `json:"implementation" validate:"required,min=0,max=10"`
2528
Presentation int `json:"presentation" validate:"required,min=0,max=10"`
2629
Round int `json:"round" validate:"required"`
30+
Innovation int `json:"innovation" validate:"required,min=0,max=10"`
31+
Teamwork int `json:"teamwork" validate:"required,min=0,max=10"`
32+
Comment string `json:"comment"`
2733
TeamID string `json:"team_id" validate:"required,uuid"`
2834
}

pkg/models/score.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ type GetScore struct {
55
Design int `json:"design" validate:"required,min=0,max=10"`
66
Implementation int `json:"implementation" validate:"required,min=0,max=10"`
77
Presentation int `json:"presentation" validate:"required,min=0,max=10"`
8-
Round int `json:"round" validate:"required,min=1"`
8+
Round int `json:"round" validate:"required"`
9+
Innovation int `json:"innovation" validate:"required,min=0,max=10"`
10+
Teamwork int `json:"teamwork" validate:"required,min=0,max=10"`
11+
Comment string `json:"comment"`
912
TeamID string `json:"team_id" validate:"required,uuid"`
1013
}

0 commit comments

Comments
 (0)