mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 17:59:14 +02:00
98 implement anonymized DTO events
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"htwkalender/model"
|
||||
"htwkalender/service/db"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
func GetRooms(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
@@ -14,10 +16,19 @@ func GetRooms(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
|
||||
func GetRoomScheduleForDay(c echo.Context, app *pocketbase.PocketBase, room string, date string) error {
|
||||
events := db.GetRoomScheduleForDay(app, room, date)
|
||||
return c.JSON(http.StatusOK, events)
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
}
|
||||
|
||||
func GetRoomSchedule(c echo.Context, app *pocketbase.PocketBase, room string, from string, to string) error {
|
||||
events := db.GetRoomSchedule(app, room, from, to)
|
||||
return c.JSON(http.StatusOK, events)
|
||||
return c.JSON(http.StatusOK, anonymizeRooms(events))
|
||||
}
|
||||
|
||||
// Transform the events to anonymized events throwing away all unnecessary information
|
||||
func anonymizeRooms(events []model.Event) []model.AnonymizedEventDTO {
|
||||
var anonymizedEvents = []model.AnonymizedEventDTO{}
|
||||
for _, event := range events {
|
||||
anonymizedEvents = append(anonymizedEvents, event.AnonymizeEvent())
|
||||
}
|
||||
return anonymizedEvents
|
||||
}
|
||||
|
125
backend/service/room/roomService_test.go
Normal file
125
backend/service/room/roomService_test.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"htwkalender/model"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
func Test_anonymizeRooms(t *testing.T) {
|
||||
type args struct {
|
||||
events []model.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []model.AnonymizedEventDTO
|
||||
}{
|
||||
{
|
||||
name: "anonymize single event",
|
||||
args: args{
|
||||
events: []model.Event{
|
||||
{
|
||||
UUID: "testUUID",
|
||||
Day: "Montag",
|
||||
Week: "52",
|
||||
Start: types.DateTime{},
|
||||
End: types.DateTime{},
|
||||
Name: "Secret",
|
||||
EventType: "V",
|
||||
Prof: "Prof. Dr. Secret",
|
||||
Rooms: "Room",
|
||||
Notes: "Secret",
|
||||
BookedAt: "Secret",
|
||||
Course: "42INM-3",
|
||||
Semester: "ws",
|
||||
Compulsory: "p",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []model.AnonymizedEventDTO{
|
||||
{
|
||||
Day: "Montag",
|
||||
Week: "52",
|
||||
Start: types.DateTime{},
|
||||
End: types.DateTime{},
|
||||
Rooms: "Room",
|
||||
Free: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "anonymize empty list",
|
||||
args: args{
|
||||
events: []model.Event{},
|
||||
},
|
||||
want: []model.AnonymizedEventDTO{},
|
||||
},
|
||||
{
|
||||
name: "anonymize multiple events",
|
||||
args: args{
|
||||
events: []model.Event{
|
||||
{
|
||||
UUID: "testUUID1",
|
||||
Day: "Montag",
|
||||
Week: "51",
|
||||
Start: types.DateTime{},
|
||||
End: types.DateTime{},
|
||||
Name: "Incognito",
|
||||
EventType: "V",
|
||||
Prof: "Prof. Dr. Incognito",
|
||||
Rooms: "Room",
|
||||
Notes: "Incognito",
|
||||
BookedAt: "Incognito",
|
||||
Course: "69INM-2",
|
||||
Semester: "sose",
|
||||
Compulsory: "p",
|
||||
},
|
||||
{
|
||||
UUID: "testUUID2",
|
||||
Day: "Dienstag",
|
||||
Week: "52",
|
||||
Start: types.DateTime{},
|
||||
End: types.DateTime{},
|
||||
Name: "Private",
|
||||
EventType: "S",
|
||||
Prof: "Prof.In. Dr.-Ing. Private",
|
||||
Rooms: "Room",
|
||||
Notes: "Private",
|
||||
BookedAt: "Private",
|
||||
Course: "42MIM-3",
|
||||
Semester: "ws",
|
||||
Compulsory: "w",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []model.AnonymizedEventDTO{
|
||||
{
|
||||
Day: "Montag",
|
||||
Week: "51",
|
||||
Start: types.DateTime{},
|
||||
End: types.DateTime{},
|
||||
Rooms: "Room",
|
||||
Free: false,
|
||||
},
|
||||
{
|
||||
Day: "Dienstag",
|
||||
Week: "52",
|
||||
Start: types.DateTime{},
|
||||
End: types.DateTime{},
|
||||
Rooms: "Room",
|
||||
Free: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := anonymizeRooms(tt.args.events); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("anonymizeRooms() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user