mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 09:38:49 +02:00
Merge branch '51-mapped-htwk-room-search-for-api' into 'development'
feat:#51 added TR fix for room mapping See merge request htwk-software/htwkalender!63
This commit is contained in:
@ -5,20 +5,36 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func MapRoom(room string) string {
|
||||
func MapRoom(room string, output bool) string {
|
||||
// remove dots from room string
|
||||
room = strings.ReplaceAll(room, ".", "")
|
||||
|
||||
if output {
|
||||
//replace second point in TR_A1.23.1 -> TR_A1.23-1 with a minus
|
||||
re := regexp.MustCompile(`\b[TR_]+[A-ZÄÖÜ]?[0-9]{1,4}[.][0-9]{1,4}[.]\b`)
|
||||
room = re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
return match[:len(match)-1] + "-" + match[len(match)-1:]
|
||||
})
|
||||
// If the output flag is set, remove all dots from the room string
|
||||
room = strings.ReplaceAll(room, ".", "")
|
||||
} else {
|
||||
// If the output flag is false add a dot for all rooms with regexp TR_A123 -> TR_A1.23
|
||||
re := regexp.MustCompile(`\bTR_+[A-ZÄÖÜ]?[0-9]{1,4}[a-zäöü]?\b`)
|
||||
room = re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
return match[:len(match)-2] + "." + match[len(match)-2:]
|
||||
})
|
||||
room = strings.ReplaceAll(room, "-", ".")
|
||||
}
|
||||
|
||||
// Regular expression pattern to match room identifiers
|
||||
// The pattern looks for strings that start with two uppercase letters, optionally followed by an underscore,
|
||||
// followed by 1 to 3 digits, and ending with "-[A-Z]"
|
||||
re := regexp.MustCompile(`\b[A-ZÄÖÜ]{2}([_]+[A-ZÄÖÜ])?[0-9]{1,4}[a-zäöü]?-[A-ZÄÖÜ]\b`)
|
||||
re := regexp.MustCompile(`\b[A-ZÄÖÜ]{2}([_]+[A-ZÄÖÜ])?[0-9]{1,4}[a-zäöü]?[-]?[0-9]?-[A-ZÄÖÜ]\b`)
|
||||
|
||||
// Use the ReplaceAllStringFunc to process each match
|
||||
result := re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
room = re.ReplaceAllStringFunc(room, func(match string) string {
|
||||
// Remove the last two characters (i.e., "-<letter>")
|
||||
return match[:len(match)-2]
|
||||
})
|
||||
|
||||
return result
|
||||
return room
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import "testing"
|
||||
|
||||
func TestMapRoom(t *testing.T) {
|
||||
type args struct {
|
||||
room string
|
||||
room string
|
||||
output bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -14,21 +15,57 @@ func TestMapRoom(t *testing.T) {
|
||||
{
|
||||
name: "Test 1 MapRoom",
|
||||
args: args{
|
||||
room: "H.1.1",
|
||||
room: "H.1.1",
|
||||
output: true,
|
||||
},
|
||||
want: "H11",
|
||||
},
|
||||
{
|
||||
name: "Test Treftsbau MapRoom",
|
||||
args: args{
|
||||
room: "TR_L3.03-S,TR_L3.02-S,TR_L2.13-L,TR_L2.05-S,TR_L1.14-H,TR_L1.07-H,TR_L1.06-B,TR_L0.14-S,TR_Innenhof_FF,TR_C1.62-L,TR_B1.50-S,TR_B1.49-S,TR_B1.48-S,TR_B1.46-S,TR_B1.45-S,TR_B0.71-L,TR_B0.70-L,TR_B0.67-L,TR_A_Cafeteria,TR_A2.28-L,TR_A1.40-F,TR_A1.37-S,TR_A1.34-S,TR_A1.29-H,TR_A1.28-S,TR_A1.27-S,TR_A1.26-S,TR_A1.25-S,TR_A1.24-H,TR_A0.34-L,TR_A0.33-L,TR_A0.32.2-L,TR_A0.32.1-L,TR_A0.31.1-L,NI_FoyerK_F,NI_Foyer1_F,NI104-L,NI103-L,NI102-L,NI070-L,GU319-L,GU318-L,GU317b-L,GU317a-L,GU313-L,GU309-L,GU301-L,GU225-L,GU224-L,GU219-L,GU203-L,GU202-L,GU201-L,GU014-L,GU013-L,GU012-L,GU011-L,GU010-L,GU009-L,GU001-L,FÖ306-S,FÖ305-S,FÖ304-S",
|
||||
room: "TR_L3.03-S,TR_L3.02-S,TR_L2.13-L,TR_L2.05-S,TR_L1.14-H,TR_L1.07-H,TR_L1.06-B,TR_L0.14-S,TR_Innenhof_FF,TR_C1.62-L,TR_B1.50-S,TR_B1.49-S,TR_B1.48-S,TR_B1.46-S,TR_B1.45-S,TR_B0.71-L,TR_B0.70-L,TR_B0.67-L,TR_A_Cafeteria,TR_A2.28-L,TR_A1.40-F,TR_A1.37-S,TR_A1.34-S,TR_A1.29-H,TR_A1.28-S,TR_A1.27-S,TR_A1.26-S,TR_A1.25-S,TR_A1.24-H,TR_A0.34-L,TR_A0.33-L,TR_A0.32.2-L,TR_A0.32.1-L,TR_A0.31.1-L,NI_FoyerK_F,NI_Foyer1_F,NI104-L,NI103-L,NI102-L,NI070-L,GU319-L,GU318-L,GU317b-L,GU317a-L,GU313-L,GU309-L,GU301-L,GU225-L,GU224-L,GU219-L,GU203-L,GU202-L,GU201-L,GU014-L,GU013-L,GU012-L,GU011-L,GU010-L,GU009-L,GU001-L,FÖ306-S,FÖ305-S,FÖ304-S",
|
||||
output: true,
|
||||
},
|
||||
want: "TR_L303,TR_L302,TR_L213,TR_L205,TR_L114,TR_L107,TR_L106,TR_L014,TR_Innenhof_FF,TR_C162,TR_B150,TR_B149,TR_B148,TR_B146,TR_B145,TR_B071,TR_B070,TR_B067,TR_A_Cafeteria,TR_A228,TR_A140,TR_A137,TR_A134,TR_A129,TR_A128,TR_A127,TR_A126,TR_A125,TR_A124,TR_A034,TR_A033,TR_A0322,TR_A0321,TR_A0311,NI_FoyerK_F,NI_Foyer1_F,NI104,NI103,NI102,NI070,GU319,GU318,GU317b,GU317a,GU313,GU309,GU301,GU225,GU224,GU219,GU203,GU202,GU201,GU014,GU013,GU012,GU011,GU010,GU009,GU001,FÖ306,FÖ305,FÖ304",
|
||||
want: "TR_L303,TR_L302,TR_L213,TR_L205,TR_L114,TR_L107,TR_L106,TR_L014,TR_Innenhof_FF,TR_C162,TR_B150,TR_B149,TR_B148,TR_B146,TR_B145,TR_B071,TR_B070,TR_B067,TR_A_Cafeteria,TR_A228,TR_A140,TR_A137,TR_A134,TR_A129,TR_A128,TR_A127,TR_A126,TR_A125,TR_A124,TR_A034,TR_A033,TR_A032-2,TR_A032-1,TR_A031-1,NI_FoyerK_F,NI_Foyer1_F,NI104,NI103,NI102,NI070,GU319,GU318,GU317b,GU317a,GU313,GU309,GU301,GU225,GU224,GU219,GU203,GU202,GU201,GU014,GU013,GU012,GU011,GU010,GU009,GU001,FÖ306,FÖ305,FÖ304",
|
||||
},
|
||||
{
|
||||
name: "Test Trefstbau MapRoom Input",
|
||||
args: args{
|
||||
room: "TR_L321",
|
||||
output: false,
|
||||
},
|
||||
want: "TR_L3.21",
|
||||
},
|
||||
{
|
||||
name: "Test Trefstbau MapRoom Input",
|
||||
args: args{
|
||||
room: "TR_A032-2",
|
||||
output: false,
|
||||
},
|
||||
want: "TR_A0.32.2",
|
||||
},
|
||||
{
|
||||
name: "Test Trefstbau MapRoom Input double point",
|
||||
args: args{
|
||||
//TR_A1.23.1 -> TR_A1.23-1
|
||||
room: "TR_A1.23.1",
|
||||
output: true,
|
||||
},
|
||||
want: "TR_A123-1",
|
||||
},
|
||||
{
|
||||
name: "Test Trefstbau MapRoom Input double point with -S",
|
||||
args: args{
|
||||
//TR_A1.23.1 -> TR_A1.23-1
|
||||
room: "TR_A1.23.1-S",
|
||||
output: true,
|
||||
},
|
||||
want: "TR_A123-1",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := MapRoom(tt.args.room); got != tt.want {
|
||||
if got := MapRoom(tt.args.room, tt.args.output); got != tt.want {
|
||||
t.Errorf("MapRoom() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
|
@ -45,7 +45,7 @@ func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string)
|
||||
func GetRoomSchedule(app *pocketbase.PocketBase, room string, from string, to string, mapped string) ([]model.AnonymizedEventDTO, error) {
|
||||
|
||||
if mapped == "true" {
|
||||
room = functions.MapRoom(room)
|
||||
room = functions.MapRoom(room, false)
|
||||
}
|
||||
|
||||
roomSchedule, err := db.GetRoomSchedule(app, room, from, to)
|
||||
@ -57,7 +57,7 @@ func GetRoomSchedule(app *pocketbase.PocketBase, room string, from string, to st
|
||||
// If mapped is "true", map the rooms again after anonymization
|
||||
if mapped == "true" {
|
||||
for i := range anonymizedRoomSchedule {
|
||||
anonymizedRoomSchedule[i].Rooms = functions.MapRoom(anonymizedRoomSchedule[i].Rooms)
|
||||
anonymizedRoomSchedule[i].Rooms = functions.MapRoom(anonymizedRoomSchedule[i].Rooms, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user