-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabs_grades.go
More file actions
40 lines (33 loc) · 1.1 KB
/
abs_grades.go
File metadata and controls
40 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"fmt"
"git.sr.ht/~runxiyu/cca/db"
)
type AbsGradesRow struct {
Grade string `json:"grade"`
Enabled bool `json:"enabled"`
MaxOwnChoices int64 `json:"max_own_choices"`
ReqGroups []db.GetRequirementGroupsByGradeRow `json:"req_groups"`
}
func (app *App) AbsGrades(ctx context.Context) ([]AbsGradesRow, error) {
// TODO: Transactions! And maybe get db queries thing from caller? I think maybe all abstract functions should do so
grades2 := []AbsGradesRow{}
grades, err := app.queries.GetGrades(ctx)
if err != nil {
return grades2, fmt.Errorf("fetch grades: %w", err)
}
for _, grade := range grades {
reqGroups, err := app.queries.GetRequirementGroupsByGrade(ctx, grade.Grade)
if err != nil {
return grades2, fmt.Errorf("fetch grade requirements: %w", err)
}
grades2 = append(grades2, AbsGradesRow{
Grade: grade.Grade,
Enabled: grade.Enabled,
MaxOwnChoices: grade.MaxOwnChoices,
ReqGroups: reqGroups,
})
}
return grades2, nil
}