feat: introduce feed management for individual and professor modules across frontend and backend services.

This commit is contained in:
Elmar Kresse
2025-11-22 21:20:41 +01:00
parent 34ad90d50d
commit ac6e1fe0dd
21 changed files with 1655 additions and 240 deletions

View File

@@ -1,6 +1,9 @@
package professor
import (
"htwkalender/data-manager/model"
"htwkalender/data-manager/service/ical"
"log/slog"
"net/http"
"github.com/pocketbase/pocketbase/apis"
@@ -26,4 +29,35 @@ func RegisterRoutes(se *core.ServeEvent, service *ProfessorService) {
return e.JSON(http.StatusOK, modules)
}).Bind(apis.RequireAuth())
// POST /api/professor/feed - Create a professor-specific feed
se.Router.POST("/api/professor/feed", func(e *core.RequestEvent) error {
record := e.Auth
if record == nil {
return apis.NewForbiddenError("Only authenticated users can access this endpoint", nil)
}
userId := record.Id
if userId == "" {
return apis.NewBadRequestError("User ID not found", nil)
}
// Bind the feed collection from request body
var feedCollection []model.FeedCollection
err := e.BindBody(&feedCollection)
if err != nil {
slog.Error("Failed to bind request body", "error", err)
return apis.NewBadRequestError("Invalid request body", err)
}
// Create feed with type="prof" and link to authenticated user
token, err := ical.CreateIndividualFeedWithType(feedCollection, "prof", userId, service.app)
if err != nil {
slog.Error("Failed to create professor feed", "error", err, "userId", userId)
return apis.NewInternalServerError("Failed to create professor feed", err)
}
slog.Info("Created professor feed", "userId", userId, "token", token)
return e.JSON(http.StatusOK, token)
}).Bind(apis.RequireAuth())
}