mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 09:49:13 +02:00
refactoring to clear db functions
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
|||||||
"github.com/pocketbase/pocketbase"
|
"github.com/pocketbase/pocketbase"
|
||||||
"github.com/pocketbase/pocketbase/models"
|
"github.com/pocketbase/pocketbase/models"
|
||||||
"htwkalender/model"
|
"htwkalender/model"
|
||||||
"htwkalender/service/functions"
|
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ func SaveEvents(seminarGroup []model.SeminarGroup, collection *models.Collection
|
|||||||
record.Set("Week", event.Week)
|
record.Set("Week", event.Week)
|
||||||
record.Set("Start", event.Start)
|
record.Set("Start", event.Start)
|
||||||
record.Set("End", event.End)
|
record.Set("End", event.End)
|
||||||
record.Set("Name", functions.ReplaceEmptyString(event.Name, "Sonderveranstaltungen"))
|
record.Set("Name", event.Name)
|
||||||
record.Set("EventType", event.EventType)
|
record.Set("EventType", event.EventType)
|
||||||
record.Set("Prof", event.Prof)
|
record.Set("Prof", event.Prof)
|
||||||
record.Set("Rooms", event.Rooms)
|
record.Set("Rooms", event.Rooms)
|
||||||
|
@@ -30,6 +30,8 @@ func GetSeminarEvents(c echo.Context, app *pocketbase.PocketBase) error {
|
|||||||
|
|
||||||
seminarGroups = clearEmptySeminarGroups(seminarGroups)
|
seminarGroups = clearEmptySeminarGroups(seminarGroups)
|
||||||
|
|
||||||
|
seminarGroups = replaceEmptyEventNames(seminarGroups)
|
||||||
|
|
||||||
savedRecords, dbError := db.SaveEvents(seminarGroups, collection, app)
|
savedRecords, dbError := db.SaveEvents(seminarGroups, collection, app)
|
||||||
|
|
||||||
if dbError != nil {
|
if dbError != nil {
|
||||||
@@ -39,6 +41,17 @@ func GetSeminarEvents(c echo.Context, app *pocketbase.PocketBase) error {
|
|||||||
return c.JSON(http.StatusOK, savedRecords)
|
return c.JSON(http.StatusOK, savedRecords)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func replaceEmptyEventNames(groups []model.SeminarGroup) []model.SeminarGroup {
|
||||||
|
for i, group := range groups {
|
||||||
|
for j, event := range group.Events {
|
||||||
|
if event.Name == "" {
|
||||||
|
groups[i].Events[j].Name = "Sonderveranstaltungen"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
|
||||||
func clearEmptySeminarGroups(seminarGroups []model.SeminarGroup) []model.SeminarGroup {
|
func clearEmptySeminarGroups(seminarGroups []model.SeminarGroup) []model.SeminarGroup {
|
||||||
var newSeminarGroups []model.SeminarGroup
|
var newSeminarGroups []model.SeminarGroup
|
||||||
for _, seminarGroup := range seminarGroups {
|
for _, seminarGroup := range seminarGroups {
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
package fetch
|
package fetch
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"htwkalender/model"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func Test_extractSemesterAndYear(t *testing.T) {
|
func Test_extractSemesterAndYear(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
@@ -50,3 +54,68 @@ func Test_extractSemesterAndYear(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_replaceEmptyEventNames(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
groups []model.SeminarGroup
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []model.SeminarGroup
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Test 1",
|
||||||
|
args: args{
|
||||||
|
groups: []model.SeminarGroup{
|
||||||
|
{
|
||||||
|
Events: []model.Event{
|
||||||
|
{
|
||||||
|
Name: "Test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []model.SeminarGroup{
|
||||||
|
{
|
||||||
|
Events: []model.Event{
|
||||||
|
{
|
||||||
|
Name: "Test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test 1",
|
||||||
|
args: args{
|
||||||
|
groups: []model.SeminarGroup{
|
||||||
|
{
|
||||||
|
Events: []model.Event{
|
||||||
|
{
|
||||||
|
Name: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []model.SeminarGroup{
|
||||||
|
{
|
||||||
|
Events: []model.Event{
|
||||||
|
{
|
||||||
|
Name: "Sonderveranstaltungen",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := replaceEmptyEventNames(tt.args.groups); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("replaceEmptyEventNames() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user