-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.go
38 lines (35 loc) · 1020 Bytes
/
team.go
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
package students
import (
"database/sql"
"errors"
"net/http"
sq "github.com/bokwoon95/go-structured-query/postgres"
"github.com/bokwoon95/nusskylabx/app/skylab"
"github.com/bokwoon95/nusskylabx/tables"
)
func (stu Students) Team(w http.ResponseWriter, r *http.Request) {
stu.skylb.Log.TraceRequest(r)
r = stu.skylb.SetRoleSection(w, r, skylab.RoleStudent, skylab.StudentTeam)
type Data struct {
Team skylab.Team
}
var data Data
user, _ := r.Context().Value(skylab.ContextUser).(skylab.User)
studentUserRoleID := user.Roles[skylab.RoleStudent]
t := tables.V_TEAMS()
err := sq.WithDefaultLog(sq.Lverbose).
From(t).
Where(sq.Int(studentUserRoleID).In(sq.Fields{t.STUDENT1_USER_ROLE_ID, t.STUDENT2_USER_ID})).
SelectRowx((&data.Team).RowMapper(t)).
Fetch(stu.skylb.DB)
if err != nil {
switch {
case errors.Is(err, sql.ErrNoRows):
stu.StudentNoTeam(w, r)
default:
stu.skylb.InternalServerError(w, r, err)
}
return
}
stu.skylb.Render(w, r, data, nil, "app/students/team.html")
}