mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-10 13:43:49 +02:00
Merge branch '11-missing-modules-with-multiple-courses-in-get-api-modules' into 'main'
Resolve "Missing modules with multiple courses in GET /api/modules" Closes #11 See merge request ekresse/htwkalender!6
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.21-alpine
|
||||
FROM golang:1.21.6
|
||||
|
||||
# Set the Current Working Directory inside the container
|
||||
WORKDIR /app
|
||||
@@ -12,7 +12,7 @@ COPY *.go ./
|
||||
COPY . .
|
||||
|
||||
# Build the Go app
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /htwkalender
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -o /htwkalender
|
||||
|
||||
# Expose port 8080 to the outside world
|
||||
EXPOSE 8080
|
||||
|
@@ -41,36 +41,44 @@ type Event struct {
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
func (m *Event) Equals(event Event) bool {
|
||||
return m.Day == event.Day &&
|
||||
m.Week == event.Week &&
|
||||
m.Start == event.Start &&
|
||||
m.End == event.End &&
|
||||
m.Name == event.Name &&
|
||||
m.Course == event.Course &&
|
||||
m.Prof == event.Prof &&
|
||||
m.Rooms == event.Rooms &&
|
||||
m.EventType == event.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 (m *Event) TableName() string {
|
||||
func (e *Event) TableName() string {
|
||||
return "events"
|
||||
}
|
||||
|
||||
// SetCourse func to set the course and returns the event
|
||||
func (m *Event) SetCourse(course string) Event {
|
||||
m.Course = course
|
||||
return *m
|
||||
func (e *Event) SetCourse(course string) Event {
|
||||
e.Course = course
|
||||
return *e
|
||||
}
|
||||
|
||||
// Creates an AnonymizedEventDTO from an Event hiding all sensitive data
|
||||
func (m *Event) AnonymizeEvent() AnonymizedEventDTO {
|
||||
func (e *Event) AnonymizeEvent() AnonymizedEventDTO {
|
||||
return AnonymizedEventDTO{
|
||||
Day: m.Day,
|
||||
Week: m.Week,
|
||||
Start: m.Start,
|
||||
End: m.End,
|
||||
Rooms: m.Rooms,
|
||||
Free: strings.Contains(strings.ToLower(m.Name), "zur freien verfügung"),
|
||||
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
|
||||
}
|
||||
|
@@ -8,3 +8,24 @@ type Module struct {
|
||||
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
|
||||
}
|
||||
|
@@ -189,16 +189,16 @@ func GetAllModulesForCourse(app *pocketbase.PocketBase, course string, semester
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func GetAllModulesDistinctByNameAndCourse(app *pocketbase.PocketBase) (model.Events, error) {
|
||||
var events model.Events
|
||||
func GetAllModulesDistinctByNameAndCourse(app *pocketbase.PocketBase) ([]model.ModuleDTO, error) {
|
||||
var modules []model.ModuleDTO
|
||||
|
||||
err := app.Dao().DB().Select("*").From("events").GroupBy("Name").Distinct(true).All(&events)
|
||||
err := app.Dao().DB().Select("Name", "EventType", "Prof", "course", "semester", "uuid").From("events").GroupBy("Name", "Course").Distinct(true).All(&modules)
|
||||
if err != nil {
|
||||
print("Error while getting events from database: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return events, nil
|
||||
return modules, nil
|
||||
}
|
||||
|
||||
func DeleteAllEventsForCourse(app *pocketbase.PocketBase, course string, semester string) error {
|
||||
|
@@ -13,17 +13,28 @@ import (
|
||||
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, course string, semester string) (model.Events, error) {
|
||||
|
||||
modules, err := db.GetAllModulesForCourse(app, course, semester)
|
||||
replaceEmptyEntry(modules, "Sonderveranstaltungen")
|
||||
|
||||
// Convert the []model.Module to []Named
|
||||
var namedEvents []Named
|
||||
for _, module := range modules {
|
||||
namedEvents = append(namedEvents, &module)
|
||||
}
|
||||
|
||||
replaceEmptyEntry(namedEvents, "Sonderveranstaltungen")
|
||||
return modules, err
|
||||
}
|
||||
|
||||
type Named interface {
|
||||
GetName() string
|
||||
SetName(name string)
|
||||
}
|
||||
|
||||
// replaceEmptyEntry replaces an empty entry in a module with a replacement string
|
||||
// If the module is not empty, nothing happens
|
||||
func replaceEmptyEntry(modules model.Events, replacement string) {
|
||||
|
||||
for i, module := range modules {
|
||||
if functions.OnlyWhitespace(module.Name) {
|
||||
modules[i].Name = replacement
|
||||
func replaceEmptyEntry(namedList []Named, replacement string) {
|
||||
for i, namedItem := range namedList {
|
||||
if functions.OnlyWhitespace(namedItem.GetName()) {
|
||||
namedList[i].SetName(replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +44,12 @@ func replaceEmptyEntry(modules model.Events, replacement string) {
|
||||
func GetAllModulesDistinct(app *pocketbase.PocketBase, c echo.Context) error {
|
||||
modules, err := db.GetAllModulesDistinctByNameAndCourse(app)
|
||||
|
||||
replaceEmptyEntry(modules, "Sonderveranstaltungen")
|
||||
var namedModules []Named
|
||||
for _, module := range modules {
|
||||
namedModules = append(namedModules, &module)
|
||||
}
|
||||
|
||||
replaceEmptyEntry(namedModules, "Sonderveranstaltungen")
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(400, err)
|
||||
|
@@ -1,37 +1,34 @@
|
||||
#user nobody;
|
||||
worker_processes 1;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
#error_log logs/error.log info;
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
error_log /var/log/nginx/error.log;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/proxy_access.log;
|
||||
error_log /var/log/nginx/proxy_error.log;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 180s;
|
||||
send_timeout 180s;
|
||||
|
||||
#gzip on;
|
||||
map $request_method $cache_bypass {
|
||||
default 0;
|
||||
POST 1;
|
||||
}
|
||||
|
||||
proxy_cache_path /dev/shm levels=1:2 keys_zone=mcache:16m inactive=600s max_size=512m;
|
||||
proxy_cache_methods GET HEAD;
|
||||
proxy_cache_min_uses 1;
|
||||
proxy_cache_key "$request_method$host$request_uri";
|
||||
proxy_cache_use_stale timeout updating;
|
||||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
@@ -46,6 +43,24 @@ http {
|
||||
send_timeout 600s;
|
||||
}
|
||||
|
||||
# Cache only specific URI
|
||||
location /api/modules {
|
||||
proxy_pass http://htwkalender-backend:8090;
|
||||
client_max_body_size 20m;
|
||||
proxy_connect_timeout 600s;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_send_timeout 600s;
|
||||
send_timeout 600s;
|
||||
proxy_cache_bypass 0;
|
||||
proxy_no_cache 0;
|
||||
proxy_cache mcache; # mcache=RAM
|
||||
proxy_cache_valid 200 301 302 30m;
|
||||
proxy_cache_valid 403 404 5m;
|
||||
proxy_cache_lock on;
|
||||
proxy_cache_use_stale timeout updating;
|
||||
add_header X-Proxy-Cache $upstream_cache_status;
|
||||
}
|
||||
|
||||
location /_ {
|
||||
proxy_pass http://htwkalender-backend:8090;
|
||||
}
|
||||
|
Reference in New Issue
Block a user