mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-03 10:19:14 +02:00
feat:#34 refactored function to intended service, fixed docker files
This commit is contained in:
104
services/data-manager/model/eventModel.go
Normal file
104
services/data-manager/model/eventModel.go
Normal file
@@ -0,0 +1,104 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
type Events []Event
|
||||
|
||||
func (m Events) Contains(event Event) bool {
|
||||
return slices.Contains(m, event)
|
||||
}
|
||||
|
||||
type AnonymizedEventDTO struct {
|
||||
Day string `db:"Day" json:"day"`
|
||||
Week string `db:"Week" json:"week"`
|
||||
Start types.DateTime `db:"start" json:"start"`
|
||||
End types.DateTime `db:"end" json:"end"`
|
||||
Rooms string `db:"Rooms" json:"rooms"`
|
||||
Free bool `json:"free"`
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
Day string `db:"Day" json:"day"`
|
||||
Week string `db:"Week" json:"week"`
|
||||
Start types.DateTime `db:"start" json:"start"`
|
||||
End types.DateTime `db:"end" json:"end"`
|
||||
Name string `db:"Name" json:"name"`
|
||||
EventType string `db:"EventType" json:"eventType"`
|
||||
Compulsory string `db:"Compulsory" json:"compulsory"`
|
||||
Prof string `db:"Prof" json:"prof"`
|
||||
Rooms string `db:"Rooms" json:"rooms"`
|
||||
Notes string `db:"Notes" json:"notes"`
|
||||
BookedAt string `db:"BookedAt" json:"bookedAt"`
|
||||
Course string `db:"course" json:"course"`
|
||||
Semester string `db:"semester" json:"semester"`
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
type EventType struct {
|
||||
EventType string `db:"EventType" json:"eventType"`
|
||||
}
|
||||
|
||||
func (e *Event) Equals(event Event) bool {
|
||||
return e.Day == event.Day &&
|
||||
e.Week == event.Week &&
|
||||
e.Start == event.Start &&
|
||||
e.End == event.End &&
|
||||
e.Name == event.Name &&
|
||||
e.Course == event.Course &&
|
||||
e.Prof == event.Prof &&
|
||||
e.Rooms == event.Rooms &&
|
||||
e.EventType == event.EventType
|
||||
}
|
||||
|
||||
func (e *Event) TableName() string {
|
||||
return "events"
|
||||
}
|
||||
|
||||
// SetCourse func to set the course and returns the event
|
||||
func (e *Event) SetCourse(course string) Event {
|
||||
e.Course = course
|
||||
return *e
|
||||
}
|
||||
|
||||
// AnonymizeEvent Creates an AnonymizedEventDTO from an Event hiding all sensitive data
|
||||
func (e *Event) AnonymizeEvent() AnonymizedEventDTO {
|
||||
return AnonymizedEventDTO{
|
||||
Day: e.Day,
|
||||
Week: e.Week,
|
||||
Start: e.Start,
|
||||
End: e.End,
|
||||
Rooms: e.Rooms,
|
||||
Free: strings.Contains(strings.ToLower(e.Name), "zur freien verfügung"),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) GetName() string {
|
||||
return e.Name
|
||||
}
|
||||
|
||||
func (e *Event) SetName(name string) {
|
||||
e.Name = name
|
||||
}
|
480
services/data-manager/model/eventModel_test.go
Normal file
480
services/data-manager/model/eventModel_test.go
Normal file
@@ -0,0 +1,480 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
func TestEvents_Contains(t *testing.T) {
|
||||
specificTime, _ := types.ParseDateTime("2020-01-01 12:00:00.000Z")
|
||||
|
||||
type args struct {
|
||||
event Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
m Events
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "empty events",
|
||||
m: Events{},
|
||||
args: args{event: Event{}},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "one event",
|
||||
m: Events{{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"}},
|
||||
args: args{event: Event{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "two events",
|
||||
m: Events{{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"}, {Day: "test2", Week: "test2", Start: specificTime, End: specificTime, Name: "test2", Course: "test2", Prof: "test2", Rooms: "test2", EventType: "test2"}},
|
||||
args: args{event: Event{Day: "test2", Week: "test2", Start: specificTime, End: specificTime, Name: "test2", Course: "test2", Prof: "test2", Rooms: "test2", EventType: "test2"}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "two events with different values",
|
||||
m: Events{{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test", UUID: "439ßu56rf8u9ijn4f4-2345345"}, {Day: "test2", Week: "test2", Start: specificTime, End: specificTime, Name: "test2", Course: "test2", Prof: "test2", Rooms: "test2", EventType: "test2", UUID: "432a39ßu545349ijn4f4-23dsa45"}},
|
||||
args: args{event: Event{Day: "test3", Week: "test3", Start: specificTime, End: specificTime, Name: "test3", Course: "test3", Prof: "test3", Rooms: "test3", EventType: "test3", UUID: "934mf43r34f-g68h7655tg3"}},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.m.Contains(tt.args.event); got != tt.want {
|
||||
t.Errorf("Contains() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_Equals(t *testing.T) {
|
||||
specificTime, _ := types.ParseDateTime("2020-01-01 12:00:00.000Z")
|
||||
|
||||
type fields struct {
|
||||
UUID string
|
||||
Day string
|
||||
Week string
|
||||
Start types.DateTime
|
||||
End types.DateTime
|
||||
Name string
|
||||
EventType string
|
||||
Prof string
|
||||
Rooms string
|
||||
Notes string
|
||||
BookedAt string
|
||||
Course string
|
||||
Semester string
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
type args struct {
|
||||
event Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "empty events",
|
||||
fields: fields{},
|
||||
args: args{event: Event{}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "one empty one not",
|
||||
fields: fields{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"},
|
||||
args: args{event: Event{}},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "one event",
|
||||
fields: fields{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"},
|
||||
args: args{event: Event{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "two events",
|
||||
fields: fields{Day: "test", Week: "test", Start: specificTime, End: specificTime, Name: "test", Course: "test", Prof: "test", Rooms: "test", EventType: "test"},
|
||||
args: args{event: Event{Day: "test2", Week: "test2", Start: specificTime, End: specificTime, Name: "test2", Course: "test2", Prof: "test2", Rooms: "test2", EventType: "test2"}},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Event{
|
||||
UUID: tt.fields.UUID,
|
||||
Day: tt.fields.Day,
|
||||
Week: tt.fields.Week,
|
||||
Start: tt.fields.Start,
|
||||
End: tt.fields.End,
|
||||
Name: tt.fields.Name,
|
||||
EventType: tt.fields.EventType,
|
||||
Prof: tt.fields.Prof,
|
||||
Rooms: tt.fields.Rooms,
|
||||
Notes: tt.fields.Notes,
|
||||
BookedAt: tt.fields.BookedAt,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
if got := m.Equals(tt.args.event); got != tt.want {
|
||||
t.Errorf("Equals() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_AnonymizeEvent(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Day string
|
||||
Week string
|
||||
Start types.DateTime
|
||||
End types.DateTime
|
||||
Name string
|
||||
EventType string
|
||||
Compulsory string
|
||||
Prof string
|
||||
Rooms string
|
||||
Notes string
|
||||
BookedAt string
|
||||
Course string
|
||||
Semester string
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want AnonymizedEventDTO
|
||||
}{
|
||||
{
|
||||
name: "empty event",
|
||||
fields: fields{},
|
||||
want: AnonymizedEventDTO{Day: "", Week: "", Start: types.DateTime{}, End: types.DateTime{}, Rooms: "", Free: false},
|
||||
},
|
||||
{
|
||||
name: "one event",
|
||||
fields: fields{Name: "Event", Day: "test", Week: "test", Rooms: "test"},
|
||||
want: AnonymizedEventDTO{Day: "test", Week: "test", Start: types.DateTime{}, End: types.DateTime{}, Rooms: "test", Free: false},
|
||||
},
|
||||
{
|
||||
name: "one event with free",
|
||||
fields: fields{Name: "Räume zur freien Verfügung", Day: "test", Week: "test", Rooms: "test", Course: "test"},
|
||||
want: AnonymizedEventDTO{Day: "test", Week: "test", Start: types.DateTime{}, End: types.DateTime{}, Rooms: "test", Free: true},
|
||||
},
|
||||
{
|
||||
name: "another free event",
|
||||
fields: fields{Name: "Zur freien Verfügung", Day: "Montag", Week: "5", Start: types.DateTime{}, End: types.DateTime{}, Rooms: "TR_A1.28-S", Course: "42INM-3"},
|
||||
want: AnonymizedEventDTO{Day: "Montag", Week: "5", Start: types.DateTime{}, End: types.DateTime{}, Rooms: "TR_A1.28-S", Free: true},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Event{
|
||||
UUID: tt.fields.UUID,
|
||||
Day: tt.fields.Day,
|
||||
Week: tt.fields.Week,
|
||||
Start: tt.fields.Start,
|
||||
End: tt.fields.End,
|
||||
Name: tt.fields.Name,
|
||||
EventType: tt.fields.EventType,
|
||||
Compulsory: tt.fields.Compulsory,
|
||||
Prof: tt.fields.Prof,
|
||||
Rooms: tt.fields.Rooms,
|
||||
Notes: tt.fields.Notes,
|
||||
BookedAt: tt.fields.BookedAt,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
if got := m.AnonymizeEvent(); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Event.AnonymizeEvent() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_GetName(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Day string
|
||||
Week string
|
||||
Start types.DateTime
|
||||
End types.DateTime
|
||||
Name string
|
||||
EventType string
|
||||
Compulsory string
|
||||
Prof string
|
||||
Rooms string
|
||||
Notes string
|
||||
BookedAt string
|
||||
Course string
|
||||
Semester string
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty event",
|
||||
fields: fields{},
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "one event",
|
||||
fields: fields{Name: "Event"},
|
||||
want: "Event",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := &Event{
|
||||
UUID: tt.fields.UUID,
|
||||
Day: tt.fields.Day,
|
||||
Week: tt.fields.Week,
|
||||
Start: tt.fields.Start,
|
||||
End: tt.fields.End,
|
||||
Name: tt.fields.Name,
|
||||
EventType: tt.fields.EventType,
|
||||
Compulsory: tt.fields.Compulsory,
|
||||
Prof: tt.fields.Prof,
|
||||
Rooms: tt.fields.Rooms,
|
||||
Notes: tt.fields.Notes,
|
||||
BookedAt: tt.fields.BookedAt,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
if got := e.GetName(); got != tt.want {
|
||||
t.Errorf("GetName() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_SetCourse(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Day string
|
||||
Week string
|
||||
Start types.DateTime
|
||||
End types.DateTime
|
||||
Name string
|
||||
EventType string
|
||||
Compulsory string
|
||||
Prof string
|
||||
Rooms string
|
||||
Notes string
|
||||
BookedAt string
|
||||
Course string
|
||||
Semester string
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
type args struct {
|
||||
course string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want Event
|
||||
}{
|
||||
{
|
||||
name: "set course",
|
||||
fields: fields{},
|
||||
args: args{course: "test"},
|
||||
want: Event{Course: "test"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := &Event{
|
||||
UUID: tt.fields.UUID,
|
||||
Day: tt.fields.Day,
|
||||
Week: tt.fields.Week,
|
||||
Start: tt.fields.Start,
|
||||
End: tt.fields.End,
|
||||
Name: tt.fields.Name,
|
||||
EventType: tt.fields.EventType,
|
||||
Compulsory: tt.fields.Compulsory,
|
||||
Prof: tt.fields.Prof,
|
||||
Rooms: tt.fields.Rooms,
|
||||
Notes: tt.fields.Notes,
|
||||
BookedAt: tt.fields.BookedAt,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
if got := e.SetCourse(tt.args.course); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SetCourse() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_SetName(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Day string
|
||||
Week string
|
||||
Start types.DateTime
|
||||
End types.DateTime
|
||||
Name string
|
||||
EventType string
|
||||
Compulsory string
|
||||
Prof string
|
||||
Rooms string
|
||||
Notes string
|
||||
BookedAt string
|
||||
Course string
|
||||
Semester string
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "set name",
|
||||
fields: fields{
|
||||
Name: "name",
|
||||
},
|
||||
args: args{
|
||||
name: "name",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := &Event{
|
||||
UUID: tt.fields.UUID,
|
||||
Day: tt.fields.Day,
|
||||
Week: tt.fields.Week,
|
||||
Start: tt.fields.Start,
|
||||
End: tt.fields.End,
|
||||
Name: tt.fields.Name,
|
||||
EventType: tt.fields.EventType,
|
||||
Compulsory: tt.fields.Compulsory,
|
||||
Prof: tt.fields.Prof,
|
||||
Rooms: tt.fields.Rooms,
|
||||
Notes: tt.fields.Notes,
|
||||
BookedAt: tt.fields.BookedAt,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
e.SetName(tt.args.name)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvent_TableName(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Day string
|
||||
Week string
|
||||
Start types.DateTime
|
||||
End types.DateTime
|
||||
Name string
|
||||
EventType string
|
||||
Compulsory string
|
||||
Prof string
|
||||
Rooms string
|
||||
Notes string
|
||||
BookedAt string
|
||||
Course string
|
||||
Semester string
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "table name",
|
||||
fields: fields{},
|
||||
want: "events",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := &Event{
|
||||
UUID: tt.fields.UUID,
|
||||
Day: tt.fields.Day,
|
||||
Week: tt.fields.Week,
|
||||
Start: tt.fields.Start,
|
||||
End: tt.fields.End,
|
||||
Name: tt.fields.Name,
|
||||
EventType: tt.fields.EventType,
|
||||
Compulsory: tt.fields.Compulsory,
|
||||
Prof: tt.fields.Prof,
|
||||
Rooms: tt.fields.Rooms,
|
||||
Notes: tt.fields.Notes,
|
||||
BookedAt: tt.fields.BookedAt,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
if got := e.TableName(); got != tt.want {
|
||||
t.Errorf("TableName() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvents_Contains1(t *testing.T) {
|
||||
type args struct {
|
||||
event Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
m Events
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "empty events",
|
||||
m: Events{},
|
||||
args: args{event: Event{}},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.m.Contains(tt.args.event); got != tt.want {
|
||||
t.Errorf("Contains() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
33
services/data-manager/model/feedModel.go
Normal file
33
services/data-manager/model/feedModel.go
Normal file
@@ -0,0 +1,33 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
Modules string `db:"modules" json:"modules"`
|
||||
Retrieved types.DateTime `db:"retrieved" json:"retrieved"`
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
// SetModules set modules field
|
||||
func (f *Feed) SetModules(modules string) {
|
||||
f.Modules = modules
|
||||
}
|
45
services/data-manager/model/feedModel_test.go
Normal file
45
services/data-manager/model/feedModel_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFeed_SetModules(t *testing.T) {
|
||||
type fields struct {
|
||||
Modules string
|
||||
Retrieved types.DateTime
|
||||
BaseModel models.BaseModel
|
||||
}
|
||||
type args struct {
|
||||
modules string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "set modules",
|
||||
fields: fields{
|
||||
Modules: "",
|
||||
Retrieved: types.DateTime{},
|
||||
BaseModel: models.BaseModel{},
|
||||
},
|
||||
args: args{
|
||||
modules: "modules",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f := &Feed{
|
||||
Modules: tt.fields.Modules,
|
||||
Retrieved: tt.fields.Retrieved,
|
||||
BaseModel: tt.fields.BaseModel,
|
||||
}
|
||||
f.SetModules(tt.args.modules)
|
||||
})
|
||||
}
|
||||
}
|
47
services/data-manager/model/icalModel.go
Normal file
47
services/data-manager/model/icalModel.go
Normal file
@@ -0,0 +1,47 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// FeedModel is an iCal feed
|
||||
type FeedModel struct {
|
||||
Content string
|
||||
ExpiresAt time.Time
|
||||
Semester string
|
||||
Course string
|
||||
}
|
||||
|
||||
// Entry is a time entry
|
||||
type Entry struct {
|
||||
DateStart time.Time `json:"dateStart"`
|
||||
DateEnd time.Time `json:"dateEnd"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Entries is a collection of entries
|
||||
type Entries []*Entry
|
||||
|
||||
type FeedCollection struct {
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
Name string `db:"Name" json:"name"`
|
||||
Course string `db:"course" json:"course"`
|
||||
UserDefinedName string `db:"userDefinedName" json:"userDefinedName"`
|
||||
Reminder bool `db:"reminder" json:"reminder"`
|
||||
}
|
47
services/data-manager/model/moduleModel.go
Normal file
47
services/data-manager/model/moduleModel.go
Normal file
@@ -0,0 +1,47 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
type Module struct {
|
||||
UUID string `json:"uuid" db:"uuid"`
|
||||
Name string `json:"name" db:"Name"`
|
||||
Prof string `json:"prof" db:"Prof"`
|
||||
Course string `json:"course" db:"course"`
|
||||
Semester string `json:"semester" db:"semester"`
|
||||
Events Events `json:"events"`
|
||||
}
|
||||
|
||||
func (m *Module) SetName(name string) {
|
||||
m.Name = name
|
||||
}
|
||||
|
||||
type ModuleDTO struct {
|
||||
UUID string `json:"uuid" db:"uuid"`
|
||||
Name string `json:"name" db:"Name"`
|
||||
Prof string `json:"prof" db:"Prof"`
|
||||
Course string `json:"course" db:"course"`
|
||||
Semester string `json:"semester" db:"semester"`
|
||||
EventType string `db:"EventType" json:"eventType"`
|
||||
}
|
||||
|
||||
func (m *ModuleDTO) GetName() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
func (m *ModuleDTO) SetName(name string) {
|
||||
m.Name = name
|
||||
}
|
126
services/data-manager/model/moduleModel_test.go
Normal file
126
services/data-manager/model/moduleModel_test.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package model
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestModuleDTO_GetName(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Name string
|
||||
Prof string
|
||||
Course string
|
||||
Semester string
|
||||
EventType string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "get name",
|
||||
fields: fields{
|
||||
Name: "name",
|
||||
},
|
||||
want: "name",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &ModuleDTO{
|
||||
UUID: tt.fields.UUID,
|
||||
Name: tt.fields.Name,
|
||||
Prof: tt.fields.Prof,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
EventType: tt.fields.EventType,
|
||||
}
|
||||
if got := m.GetName(); got != tt.want {
|
||||
t.Errorf("GetName() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleDTO_SetName(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Name string
|
||||
Prof string
|
||||
Course string
|
||||
Semester string
|
||||
EventType string
|
||||
}
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "set name",
|
||||
fields: fields{
|
||||
Name: "name",
|
||||
},
|
||||
args: args{
|
||||
name: "name",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &ModuleDTO{
|
||||
UUID: tt.fields.UUID,
|
||||
Name: tt.fields.Name,
|
||||
Prof: tt.fields.Prof,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
EventType: tt.fields.EventType,
|
||||
}
|
||||
m.SetName(tt.args.name)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestModule_SetName(t *testing.T) {
|
||||
type fields struct {
|
||||
UUID string
|
||||
Name string
|
||||
Prof string
|
||||
Course string
|
||||
Semester string
|
||||
Events Events
|
||||
}
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "set name",
|
||||
fields: fields{
|
||||
Name: "name",
|
||||
},
|
||||
args: args{
|
||||
name: "name",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &Module{
|
||||
UUID: tt.fields.UUID,
|
||||
Name: tt.fields.Name,
|
||||
Prof: tt.fields.Prof,
|
||||
Course: tt.fields.Course,
|
||||
Semester: tt.fields.Semester,
|
||||
Events: tt.fields.Events,
|
||||
}
|
||||
m.SetName(tt.args.name)
|
||||
})
|
||||
}
|
||||
}
|
28
services/data-manager/model/seminarGroup.go
Normal file
28
services/data-manager/model/seminarGroup.go
Normal file
@@ -0,0 +1,28 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
type SeminarGroup struct {
|
||||
University string
|
||||
GroupShortcut string
|
||||
GroupId string
|
||||
Course string
|
||||
Faculty string
|
||||
FacultyId string
|
||||
Semester string
|
||||
Events []Event
|
||||
}
|
45
services/data-manager/model/seminarGroupXMLStruct.go
Normal file
45
services/data-manager/model/seminarGroupXMLStruct.go
Normal file
@@ -0,0 +1,45 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type Studium struct {
|
||||
XMLName xml.Name `xml:"studium"`
|
||||
Faculty []Faculty `xml:"fakultaet"`
|
||||
}
|
||||
|
||||
type Faculty struct {
|
||||
XMLName xml.Name `xml:"fakultaet"`
|
||||
Name string `xml:"name,attr"`
|
||||
ID string `xml:"id,attr"`
|
||||
Studiengang []Studiengang `xml:"studiengang"`
|
||||
}
|
||||
|
||||
type Studiengang struct {
|
||||
XMLName xml.Name `xml:"studiengang"`
|
||||
Name string `xml:"name,attr"`
|
||||
ID string `xml:"id,attr"`
|
||||
Semgrp []Semgrp `xml:"semgrp"`
|
||||
}
|
||||
|
||||
type Semgrp struct {
|
||||
XMLName xml.Name `xml:"semgrp"`
|
||||
Name string `xml:"name,attr"`
|
||||
}
|
72
services/data-manager/model/sportFetcherModel.go
Normal file
72
services/data-manager/model/sportFetcherModel.go
Normal file
@@ -0,0 +1,72 @@
|
||||
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
|
||||
//Copyright (C) 2024 HTWKalender support@htwkalender.de
|
||||
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU Affero General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU Affero General Public License for more details.
|
||||
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// MODELS
|
||||
|
||||
// SportEntry represents the overall event details.
|
||||
type SportEntry struct {
|
||||
Title string
|
||||
Details EventDetails
|
||||
AdditionalNote string
|
||||
ID string
|
||||
}
|
||||
|
||||
// EventDetails represents detailed information about the event.
|
||||
type EventDetails struct {
|
||||
DateRange DateRange
|
||||
Cycle string
|
||||
Gender string
|
||||
CourseLead CourseLead
|
||||
Location Location
|
||||
Participants Participants
|
||||
Cost string
|
||||
Type string
|
||||
}
|
||||
|
||||
// DateRange represents a start and end date.
|
||||
type DateRange struct {
|
||||
Start time.Time
|
||||
End time.Time
|
||||
}
|
||||
|
||||
// CourseLead represents a person with a name and a contact link.
|
||||
type CourseLead struct {
|
||||
Name string
|
||||
Link string
|
||||
}
|
||||
|
||||
// Location represents the location of the event.
|
||||
type Location struct {
|
||||
Name string
|
||||
Address string
|
||||
}
|
||||
|
||||
// Participants represents the participants' details.
|
||||
type Participants struct {
|
||||
Bookings int
|
||||
TotalPlaces int
|
||||
WaitList int
|
||||
}
|
||||
|
||||
type SportDayStartEnd struct {
|
||||
Start time.Time
|
||||
End time.Time
|
||||
Day time.Weekday
|
||||
}
|
Reference in New Issue
Block a user