Skip to content

Commit

Permalink
Merge pull request #96 from eurofurence/issue-94-more-fixes
Browse files Browse the repository at this point in the history
room fixes during implementation part 2
  • Loading branch information
Jumpy-Squirrel authored Nov 12, 2024
2 parents 5c116fb + 2d35c08 commit 0973f41
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
5 changes: 2 additions & 3 deletions internal/controller/v1/groupsctl/groups_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"context"
"github.com/eurofurence/reg-room-service/internal/application/web"
"github.com/eurofurence/reg-room-service/internal/controller/v1/util"
"net/http"
"net/url"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"net/http"
"net/url"

modelsv1 "github.com/eurofurence/reg-room-service/internal/api/v1"
"github.com/eurofurence/reg-room-service/internal/application/common"
Expand Down
4 changes: 4 additions & 0 deletions internal/service/groups/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (g *groupService) findGroupsFullAccess(ctx context.Context, minSize uint, m
}
}

sort.Slice(result, func(i, j int) bool {
return groupLessByName(result[i], result[j])
})

return result, nil
}

Expand Down
7 changes: 7 additions & 0 deletions internal/service/groups/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,10 @@ func groupHasFlag(group *modelsv1.Group, wantedFlag string) bool {
}
return false
}

func groupLessByName(left *modelsv1.Group, right *modelsv1.Group) bool {
if left == nil || right == nil {
return left == nil && right != nil
}
return left.Name < right.Name
}
8 changes: 8 additions & 0 deletions internal/service/rooms/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
aulogging "github.com/StephanHCB/go-autumn-logging"
modelsv1 "github.com/eurofurence/reg-room-service/internal/api/v1"
"github.com/eurofurence/reg-room-service/internal/application/common"
"github.com/eurofurence/reg-room-service/internal/repository/downstreams"
"github.com/eurofurence/reg-room-service/internal/repository/downstreams/attendeeservice"
Expand Down Expand Up @@ -67,3 +68,10 @@ func (r *roomService) checkAttending(ctx context.Context, badgeNo int64, notAtte
return notAttendingErr
}
}

func roomLessByName(left *modelsv1.Room, right *modelsv1.Room) bool {
if left == nil || right == nil {
return left == nil && right != nil
}
return left.Name < right.Name
}
4 changes: 4 additions & 0 deletions internal/service/rooms/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (r *roomService) findRoomsFullAccess(ctx context.Context, params *FindRoomP
result = append(result, room)
}

sort.Slice(result, func(i, j int) bool {
return roomLessByName(result[i], result[j])
})

return result, nil
}

Expand Down
6 changes: 1 addition & 5 deletions test/acceptance/groups_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func TestGroupsList_AdminSuccess(t *testing.T) {
Invites: nil,
}
expected := modelsv1.GroupList{}
if id1 < id2 {
expected.Groups = append(expected.Groups, &grp1, &grp2)
} else {
expected.Groups = append(expected.Groups, &grp2, &grp1)
}
expected.Groups = append(expected.Groups, &grp1, &grp2) // sorted alphabetically by name
tstEqualResponseBodies(t, expected, actual)
}

Expand Down
28 changes: 10 additions & 18 deletions test/acceptance/rooms_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ func TestRoomsList_AdminSuccess(t *testing.T) {
docs.Then("Then the request is successful and the response includes all room information")
actual := modelsv1.RoomList{}
tstRequireSuccessResponse(t, response, http.StatusOK, &actual)
rm1 := modelsv1.Room{
ID: tstRoomLocationToRoomID(location1),
Name: "rodents",
Flags: []string{},
Comments: p("A nice comment for rodents"),
Size: 2,
Occupants: []modelsv1.Member{squirrel},
}
rm2 := modelsv1.Room{
ID: tstRoomLocationToRoomID(location2),
Name: "cats",
Expand All @@ -39,12 +31,16 @@ func TestRoomsList_AdminSuccess(t *testing.T) {
Size: 2,
Occupants: []modelsv1.Member{snep},
}
expected := modelsv1.RoomList{}
if rm1.ID < rm2.ID {
expected.Rooms = append(expected.Rooms, &rm1, &rm2)
} else {
expected.Rooms = append(expected.Rooms, &rm2, &rm1)
rm1 := modelsv1.Room{
ID: tstRoomLocationToRoomID(location1),
Name: "rodents",
Flags: []string{},
Comments: p("A nice comment for rodents"),
Size: 2,
Occupants: []modelsv1.Member{squirrel},
}
expected := modelsv1.RoomList{}
expected.Rooms = append(expected.Rooms, &rm2, &rm1) // sorted by name
tstEqualResponseBodies(t, expected, actual)
}

Expand Down Expand Up @@ -109,11 +105,7 @@ func TestRoomsList_ApiTokenSuccess(t *testing.T) {
Occupants: []modelsv1.Member{snep},
}
expected := modelsv1.RoomList{}
if rm1.ID < rm2.ID {
expected.Rooms = append(expected.Rooms, &rm1, &rm2)
} else {
expected.Rooms = append(expected.Rooms, &rm2, &rm1)
}
expected.Rooms = append(expected.Rooms, &rm2, &rm1) // sorted by name
tstEqualResponseBodies(t, expected, actual)
}

Expand Down

0 comments on commit 0973f41

Please sign in to comment.