Skip to content

Commit

Permalink
count registrations on event/room (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
dheidemann committed Jul 7, 2024
1 parent 715118f commit 3ade84a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 14 deletions.
2 changes: 2 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ query {
room {
number
name
capacity
}
registrations
}
needsTutors
availableTutors {
Expand Down
112 changes: 103 additions & 9 deletions server/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions server/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ type Topic {
}

type EventTutorRoomPair {
tutors: [Tutor!]!
tutors: [Tutor!]
room: Room
registrations: Int
}

type Event {
Expand Down
16 changes: 14 additions & 2 deletions server/graph/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@ func (r *eventResolver) TutorsAssigned(ctx context.Context, obj *models.Event) (
if room, exists := roomMap[roomKey]; exists {
room.Tutors = append(room.Tutors, eventToTutorRelation.Tutor)
} else {
registrationsCount, err := r.DB.NewSelect().
Model((*models.StudentToEvent)(nil)).
Where("event_id = ?", obj.ID).
Where("room_number = ?", eventToTutorRelation.Room.Name).
Where("building_id = ?", eventToTutorRelation.BuildingID).
Count(ctx)

if err != nil {
return nil, err
}

roomMap[roomKey] = &model.EventTutorRoomPair{
Tutors: []*models.Tutor{eventToTutorRelation.Tutor},
Room: eventToTutorRelation.Room,
Tutors: []*models.Tutor{eventToTutorRelation.Tutor},
Room: eventToTutorRelation.Room,
Registrations: &registrationsCount,
}
}
}
Expand Down

0 comments on commit 3ade84a

Please sign in to comment.