diff --git a/frontend/src/api/loadCalendar.ts b/frontend/src/api/loadCalendar.ts index 87bfdda..1cfe705 100644 --- a/frontend/src/api/loadCalendar.ts +++ b/frontend/src/api/loadCalendar.ts @@ -21,7 +21,7 @@ export async function getCalender(token: string): Promise { if (import.meta.env.SSR) { return []; } - const request = new Request("/api/collections/feeds/records/" + token, { + const request = new Request("/api/feeds/records/" + token, { method: "GET", }); diff --git a/services/data-manager/model/feedModel.go b/services/data-manager/model/feedModel.go index 1306ab1..106d38e 100644 --- a/services/data-manager/model/feedModel.go +++ b/services/data-manager/model/feedModel.go @@ -24,9 +24,14 @@ import ( type Feed struct { Modules string `db:"modules" json:"modules"` Retrieved types.DateTime `db:"retrieved" json:"retrieved"` + Deleted bool `db:"deleted" json:"deleted"` models.BaseModel } +func (f *Feed) TableName() string { + return "feeds" +} + // SetModules set modules field func (f *Feed) SetModules(modules string) { f.Modules = modules diff --git a/services/data-manager/service/addCalDavRoutes.go b/services/data-manager/service/addCalDavRoutes.go index f487031..18271f2 100644 --- a/services/data-manager/service/addCalDavRoutes.go +++ b/services/data-manager/service/addCalDavRoutes.go @@ -21,7 +21,7 @@ import ( "github.com/pocketbase/pocketbase" "github.com/pocketbase/pocketbase/apis" "github.com/pocketbase/pocketbase/core" - "htwkalender/data-manager/service/db" + "htwkalender/data-manager/service/feed" "htwkalender/data-manager/service/ical" "io" "log/slog" @@ -58,7 +58,7 @@ func addFeedRoutes(app *pocketbase.PocketBase) { Path: "/api/feed", Handler: func(c echo.Context) error { token := c.QueryParam("token") - err := db.DeleteFeed(app.Dao(), token) + err := feed.MarkFeedForDeletion(app.Dao(), token) if err != nil { return c.JSON(http.StatusNotFound, err) } else { diff --git a/services/data-manager/service/db/dbFeeds.go b/services/data-manager/service/db/dbFeeds.go index 2ae46e1..40aef6f 100644 --- a/services/data-manager/service/db/dbFeeds.go +++ b/services/data-manager/service/db/dbFeeds.go @@ -84,3 +84,22 @@ func GetAllFeeds(db *daos.Dao) ([]model.Feed, error) { } return feeds, nil } + +func MarkForDelete(db *daos.Dao, token string) error { + // get record from db + feed := model.Feed{} + err := db.DB().Select("*").From("feeds").Where(dbx.NewExp("id = {:id}", dbx.Params{"id": token})).One(&feed) + if err != nil { + return err + } + // set delete flag + feed.Deleted = true + feed.Modules = "[\n {\n \"uuid\": \"\",\n \"name\": \"Deleted\",\n \"course\": \"\",\n \"userDefinedName\": \"Deleted\",\n \"reminder\": false\n }\n]" + + // save record + err = db.Save(&feed) + if err != nil { + return err + } + return nil +} diff --git a/services/data-manager/service/feed/feedFunctions.go b/services/data-manager/service/feed/feedFunctions.go index 6c3da36..6c16c7e 100644 --- a/services/data-manager/service/feed/feedFunctions.go +++ b/services/data-manager/service/feed/feedFunctions.go @@ -17,8 +17,6 @@ package feed import ( - "database/sql" - "github.com/pocketbase/dbx" "github.com/pocketbase/pocketbase/daos" "htwkalender/data-manager/model" database "htwkalender/data-manager/service/db" @@ -41,13 +39,9 @@ func ClearFeeds(db *daos.Dao, months int, clock localTime.Clock) { if feedRetrievedTime.Before(timeShift) { // delete feed - var sqlResult sql.Result - sqlResult, err = db.DB().Delete("feeds", dbx.NewExp("id = {:id}", dbx.Params{"id": feed.GetId()})).Execute() - if err != nil { - slog.Error("CleanFeeds: delete feed "+feed.GetId()+" failed", "error", err) - slog.Error("SQL Result: ", "error", sqlResult) - } else { - slog.Info("CleanFeeds: delete feed " + feed.GetId() + " successful") + feedErr := database.DeleteFeed(db, feed.GetId()) + if feedErr != nil { + slog.Error("CleanFeeds: failed to delete feed: "+feed.GetId(), "error", feedErr) } } } @@ -124,3 +118,7 @@ func combineRooms(events model.Events, index1 int, combinedEvents model.Events, } return combinedEvents[index2].Rooms } + +func MarkFeedForDeletion(db *daos.Dao, feedId string) error { + return database.MarkForDelete(db, feedId) +} diff --git a/services/ical/model/appModel.go b/services/ical/model/appModel.go index 2238b09..40f481d 100644 --- a/services/ical/model/appModel.go +++ b/services/ical/model/appModel.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package model import ( diff --git a/services/ical/model/icalModel.go b/services/ical/model/icalModel.go index 7ff9263..14121fd 100644 --- a/services/ical/model/icalModel.go +++ b/services/ical/model/icalModel.go @@ -61,6 +61,7 @@ type FeedModule struct { type FeedRecord struct { Modules []FeedModule `db:"modules" json:"modules"` Retrieved JSONTime `db:"retrieved" json:"retrieved"` + Deleted bool `db:"deleted" json:"deleted"` BaseModel } diff --git a/services/ical/model/moduleModel.go b/services/ical/model/moduleModel.go index eddb839..558801f 100644 --- a/services/ical/model/moduleModel.go +++ b/services/ical/model/moduleModel.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package model type Module struct { diff --git a/services/ical/service/connector/feedConnector.go b/services/ical/service/connector/feedConnector.go index e545791..4b98d77 100644 --- a/services/ical/service/connector/feedConnector.go +++ b/services/ical/service/connector/feedConnector.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package connector import ( diff --git a/services/ical/service/connector/grpc/client.go b/services/ical/service/connector/grpc/client.go index f9c7275..066d62b 100644 --- a/services/ical/service/connector/grpc/client.go +++ b/services/ical/service/connector/grpc/client.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package grpc import ( diff --git a/services/ical/service/connector/grpc/events.go b/services/ical/service/connector/grpc/events.go index fc82755..bcb6b1b 100644 --- a/services/ical/service/connector/grpc/events.go +++ b/services/ical/service/connector/grpc/events.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package grpc import ( diff --git a/services/ical/service/connector/grpc/feeds.go b/services/ical/service/connector/grpc/feeds.go index 0f1f082..e4ce937 100644 --- a/services/ical/service/connector/grpc/feeds.go +++ b/services/ical/service/connector/grpc/feeds.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package grpc import ( diff --git a/services/ical/service/connector/grpc/modules.go b/services/ical/service/connector/grpc/modules.go index aa47d79..d1bb195 100644 --- a/services/ical/service/connector/grpc/modules.go +++ b/services/ical/service/connector/grpc/modules.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package grpc import ( diff --git a/services/ical/service/connector/restHandler.go b/services/ical/service/connector/restHandler.go index 4af7ba0..9cc58a8 100644 --- a/services/ical/service/connector/restHandler.go +++ b/services/ical/service/connector/restHandler.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package connector import ( diff --git a/services/ical/service/functions/semester_test.go b/services/ical/service/functions/semester_test.go index 9595ede..6200a75 100644 --- a/services/ical/service/functions/semester_test.go +++ b/services/ical/service/functions/semester_test.go @@ -1,3 +1,19 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package functions import ( diff --git a/services/ical/service/ical/ical.go b/services/ical/service/ical/ical.go index baa6160..cca09d6 100644 --- a/services/ical/service/ical/ical.go +++ b/services/ical/service/ical/ical.go @@ -1,7 +1,24 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package ical import ( "bytes" + "fmt" "github.com/jordic/goics" "htwkalender/ical/model" "htwkalender/ical/service/connector" @@ -12,6 +29,8 @@ import ( const expirationTime = 5 * time.Minute +var FeedDeletedError = fmt.Errorf("feed deleted") + func Feed(app model.AppType, token string) (string, error) { // get feed by token feed, err := htwkalenderGrpc.GetFeed(token, app.GrpcClient) @@ -19,6 +38,10 @@ func Feed(app model.AppType, token string) (string, error) { return "", err } + if feed.Deleted { + return "", FeedDeletedError + } + var events model.Events // Get all events for modules @@ -45,7 +68,7 @@ func Feed(app model.AppType, token string) (string, error) { func FeedRecord(app model.AppType, token string) (model.FeedRecord, error) { feedRecord, err := connector.GetFeedByToken(app.DataManagerURL, token) - if err != nil { + if err != nil || feedRecord.Deleted { return model.FeedRecord{}, err } diff --git a/services/ical/service/routes.go b/services/ical/service/routes.go index 3975cac..b699deb 100644 --- a/services/ical/service/routes.go +++ b/services/ical/service/routes.go @@ -1,7 +1,24 @@ +//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. +//Copyright (C) 2024 HTWKalender support@htwkalender.de + +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Affero General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Affero General Public License for more details. + +//You should have received a copy of the GNU Affero General Public License +//along with this program. If not, see . + package service import ( "encoding/json" + "errors" "github.com/gofiber/fiber/v3" "htwkalender/ical/model" "htwkalender/ical/service/ical" @@ -19,9 +36,13 @@ func AddFeedRoutes(app model.AppType) { token := c.Query("token") results, err := ical.Feed(app, token) + if errors.Is(err, ical.FeedDeletedError) { + return c.SendStatus(fiber.StatusGone) + } + if err != nil { slog.Error("Failed to get feed", "error", err, "token", token) - return c.SendStatus(fiber.StatusGone) + return c.SendStatus(fiber.StatusNotFound) } c.Response().Header.Set("Content-type", "text/calendar") c.Response().Header.Set("charset", "utf-8") @@ -53,7 +74,7 @@ func AddFeedRoutes(app model.AppType) { }) // Define a route for the GET method on the root path '/' - app.Fiber.Get("/api/collections/feeds/records/:token", func(c fiber.Ctx) error { + app.Fiber.Get("/api/feeds/records/:token", func(c fiber.Ctx) error { token := c.Params("token") results, err := ical.FeedRecord(app, token)