mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 17:48:49 +02:00
feat:#50 added test token generation
This commit is contained in:
@ -32,6 +32,18 @@ const expirationTime = 5 * time.Minute
|
||||
var FeedDeletedError = fmt.Errorf("feed deleted")
|
||||
|
||||
func Feed(app model.AppType, token string) (string, error) {
|
||||
|
||||
var events model.Events
|
||||
var modules map[string]model.FeedCollection
|
||||
|
||||
if token == "test" {
|
||||
// write down list of modules
|
||||
modules = generateTestModules()
|
||||
|
||||
// generate test feed with events from the last 7 days to the next 7 days
|
||||
events = generateTestEvents(modules)
|
||||
|
||||
} else {
|
||||
// get feed by token
|
||||
feed, err := htwkalenderGrpc.GetFeed(token, app.GrpcClient)
|
||||
if err != nil {
|
||||
@ -42,8 +54,6 @@ func Feed(app model.AppType, token string) (string, error) {
|
||||
return "", FeedDeletedError
|
||||
}
|
||||
|
||||
var events model.Events
|
||||
|
||||
// Get all events for modules
|
||||
events, err = htwkalenderGrpc.GetEvents(feed.Modules, app.GrpcClient)
|
||||
if err != nil {
|
||||
@ -53,10 +63,10 @@ func Feed(app model.AppType, token string) (string, error) {
|
||||
// Sort events by start date
|
||||
events.Sort()
|
||||
|
||||
modules := make(map[string]model.FeedCollection)
|
||||
for _, module := range feed.Modules {
|
||||
modules[module.UUID] = model.FeedCollection(module)
|
||||
}
|
||||
}
|
||||
|
||||
b := bytes.Buffer{}
|
||||
goics.NewICalEncode(&b).Encode(IcalModel{Events: events, Mapping: modules})
|
||||
|
111
services/ical/service/ical/testIcal.go
Normal file
111
services/ical/service/ical/testIcal.go
Normal file
@ -0,0 +1,111 @@
|
||||
package ical
|
||||
|
||||
import (
|
||||
"htwkalender/ical/model"
|
||||
"htwkalender/ical/service/functions"
|
||||
clock "htwkalender/ical/service/functions/time"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// generateTestEvents generates test events from the last 7 days to the next 7 days for the given modules
|
||||
func generateTestEvents(modules map[string]model.FeedCollection) []model.Event {
|
||||
var events []model.Event
|
||||
now := clock.RealClock{}
|
||||
|
||||
for _, module := range modules {
|
||||
// Generate 2-3 events per module in the 14-day range
|
||||
numEvents := rand.Intn(2) + 2 // 2 to 3 events
|
||||
for i := 0; i < numEvents; i++ {
|
||||
var startTime time.Time
|
||||
for {
|
||||
// Random day offset from today, between -7 to +7 days
|
||||
dayOffset := rand.Intn(15) - 7
|
||||
// Random time offset (start times at 9 AM, 1 PM, or 4 PM)
|
||||
timeOffsets := []time.Duration{9 * time.Hour, 13 * time.Hour, 16 * time.Hour}
|
||||
startTime = now.Now().AddDate(0, 0, dayOffset).Truncate(24 * time.Hour).Add(timeOffsets[rand.Intn(len(timeOffsets))])
|
||||
|
||||
// Check if the generated day is Saturday (6) or Sunday (0), if so, regenerate the day
|
||||
weekday := startTime.Weekday()
|
||||
if weekday != time.Saturday && weekday != time.Sunday {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
endTime := startTime.Add(2 * time.Hour) // Events last 2 hours
|
||||
|
||||
// Create a formatted string for the day and week
|
||||
day := startTime.Format("2006-01-02")
|
||||
week := startTime.Format("2006-W02")
|
||||
|
||||
// Create an event for this module
|
||||
event := model.Event{
|
||||
UUID: module.UUID + "_" + startTime.Format("20060102T1504"),
|
||||
Day: day,
|
||||
Week: week,
|
||||
Start: model.JSONTime(startTime),
|
||||
End: model.JSONTime(endTime),
|
||||
Name: module.Name,
|
||||
EventType: "P", // You can customize this based on module/course or other logic
|
||||
Compulsory: "V", // Assuming all events are compulsory
|
||||
Prof: "Prof. Dr. Test", // You can customize or randomize this as well
|
||||
Rooms: "LI-114", // You can customize or randomize this as well
|
||||
Notes: "This is a test event",
|
||||
BookedAt: now.Now().Format(time.RFC3339),
|
||||
Course: module.Course,
|
||||
Semester: functions.GetCurrentSemesterString(now), // Customize based on your data
|
||||
}
|
||||
events = append(events, event)
|
||||
}
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
func generateTestModules() map[string]model.FeedCollection {
|
||||
|
||||
return map[string]model.FeedCollection{
|
||||
"8129304z657843hf3487f69gh328467": {
|
||||
UUID: "8129304z657843hf3487f69gh328467",
|
||||
Name: "Big Data Management IK-M 1. FS",
|
||||
Course: "23INM",
|
||||
UserDefinedName: "Big Data Management IK-M 1. FS",
|
||||
Reminder: false,
|
||||
},
|
||||
"8129304z657843hf3487f69gh328468": {
|
||||
UUID: "8129304z657843hf3487f69gh328468",
|
||||
Name: "C133 OS Überwachungswirtschaft INM & MIM 2. FS (pf)",
|
||||
Course: "23INM",
|
||||
UserDefinedName: "C133 OS Überwachungswirtschaft INM & MIM 2. FS (pf)",
|
||||
Reminder: false,
|
||||
},
|
||||
"8129304z657843hf3487f69gh328469": {
|
||||
UUID: "8129304z657843hf3487f69gh328469",
|
||||
Name: "C230 Compilerbau INM (wpf) 2. FS",
|
||||
Course: "23INM",
|
||||
UserDefinedName: "C230 Compilerbau INM (wpf) 2. FS",
|
||||
Reminder: false,
|
||||
},
|
||||
"8129304z657843hf3487f69gh328470": {
|
||||
UUID: "8129304z657843hf3487f69gh328470",
|
||||
Name: "N873 Statistische Analyseverfahren in Data Science INM & MIM 2.FS (wpf)",
|
||||
Course: "23INM",
|
||||
UserDefinedName: "N873 Statistische Analyseverfahren in Data Science INM & MIM 2.FS (wpf)",
|
||||
Reminder: false,
|
||||
},
|
||||
"8129304z657843hf3487f69gh328471": {
|
||||
UUID: "8129304z657843hf3487f69gh328471",
|
||||
Name: "Softwareprojekt C073 MI-B & IN-B 4.FS sowie C922 Projektmanagementpraktikum IN-M 2. FS (pf)",
|
||||
Course: "23INM",
|
||||
UserDefinedName: "Softwareprojekt C073 MI-B & IN-B 4.FS sowie C922 Projektmanagementpraktikum IN-M 2. FS (pf)",
|
||||
Reminder: false,
|
||||
},
|
||||
"8129304z657843hf3487f69gh328472": {
|
||||
UUID: "8129304z657843hf3487f69gh328472",
|
||||
Name: "C803 Künstliche Intellligenz INM & MIM 2. FS (wpf)",
|
||||
Course: "23INM",
|
||||
UserDefinedName: "C803 Künstliche Intellligenz INM & MIM 2. FS (wpf)",
|
||||
Reminder: false,
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user