mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2026-01-18 04:22:27 +01:00
feat: introduce feed management for individual and professor modules across frontend and backend services.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user