mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-02 09:49:16 +02:00
feat:#150 added slog for more functions and improved return signature
This commit is contained in:
@@ -3,13 +3,12 @@ package v1
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"htwkalender/model"
|
||||
"htwkalender/service/db"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -41,12 +40,23 @@ func getSeminarHTML(semester string) (string, error) {
|
||||
|
||||
}
|
||||
|
||||
func SeminarGroups(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
func FetchSeminarGroups(app *pocketbase.PocketBase) ([]*models.Record, error) {
|
||||
var groups []model.SeminarGroup
|
||||
|
||||
resultSummer, _ := getSeminarHTML("ss")
|
||||
resultSummer, err := getSeminarHTML("ss")
|
||||
|
||||
if err != nil {
|
||||
slog.Error("Error while fetching seminar groups for winter semester", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resultWinter, _ := getSeminarHTML("ws")
|
||||
|
||||
if err != nil {
|
||||
slog.Error("Error while fetching seminar groups for summer semester", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groups = parseSeminarGroups(resultSummer)
|
||||
groups = append(groups, parseSeminarGroups(resultWinter)...)
|
||||
|
||||
@@ -55,16 +65,18 @@ func SeminarGroups(c echo.Context, app *pocketbase.PocketBase) error {
|
||||
|
||||
collection, dbError := db.FindCollection(app, "groups")
|
||||
if dbError != nil {
|
||||
return apis.NewNotFoundError("Collection not found", dbError)
|
||||
slog.Error("Error while searching collection groups", dbError)
|
||||
return nil, err
|
||||
}
|
||||
var insertedGroups []*models.Record
|
||||
|
||||
insertedGroups, dbError = db.SaveGroups(groups, collection, app)
|
||||
if dbError != nil {
|
||||
return apis.NewNotFoundError("Records could not be saved", dbError)
|
||||
slog.Error("Error while saving groups", dbError)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, insertedGroups)
|
||||
return insertedGroups, nil
|
||||
}
|
||||
|
||||
func removeDuplicates(groups []model.SeminarGroup) []model.SeminarGroup {
|
||||
|
Reference in New Issue
Block a user