Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions resources/yaml/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Calendars:
- ID: "1776ed34-fccf-4845-aa1b-5c6821649804"
Name: "HM Fristen & Termine"
Url: "https://api.betterhm.app/static/calendar/1776ed34-fccf-4845-aa1b-5c6821649804.ics"
SourceURL: "https://calendar.google.com/calendar/ical/qp1nk83jvkfm7a3m9goqhr5oo4%40group.calendar.google.com/public/basic.ics"
- ID: "870baf08-b182-4451-a1f5-657b8ef02852"
Name: "Gesetzliche Feiertage"
Url: "https://api.betterhm.app/static/calendar/870baf08-b182-4451-a1f5-657b8ef02852.ics"
SourceURL: "https://www.thunderbird.net/media/caldata/GermanHolidays.ics"
- id: "1776ed34-fccf-4845-aa1b-5c6821649804"
name: "HM Fristen & Termine"
url: "https://api.betterhm.app/static/calendar/1776ed34-fccf-4845-aa1b-5c6821649804.ics"
sourceURL: "https://calendar.proton.me/api/calendar/v1/url/973m76Afxr3ryM4NFjuZUVhmqMGh3SIpMX-1eSlwOL_bhqA38biXWzQPqaLfWLkVBOs9Sh7Q3E002rMctPnErw==/calendar.ics?CacheKey=R3FlWaFezXeobpnpHQapxw%3D%3D&PassphraseKey=956kJaPh_-UjxGYMfexjyo3oExfXMXdKKLL7W3vhd9I%3D"
- id: "870baf08-b182-4451-a1f5-657b8ef02852"
name: "Gesetzliche Feiertage"
url: "https://api.betterhm.app/static/calendar/870baf08-b182-4451-a1f5-657b8ef02852.ics"
sourceURL: "https://www.thunderbird.net/media/caldata/GermanHolidays.ics"
CapacityElements:
- enum_name: "STUCAFE_KARLSTR"
lrz_subdistrict_id: "rf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public StaticUpdater(YamlParser yamlParser) {
@PostConstruct
@Scheduled(cron = "0 0 4 * * *")
public void updateCalendar(){
yaml.Calendars().stream().filter(element -> element.SourceURL().isPresent()).forEach(element ->
downloadFile(element.SourceURL().get(), "resources/static/calendar/" + element.ID() + ".ics"));
yaml.Calendars().stream().filter(element -> element.sourceURL().isPresent()).forEach(element ->
downloadFile(element.sourceURL().get(), "resources/static/calendar/" + element.id() + ".ics"));
logger.info("Calendar files updated");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,47 @@

import app.betterhm.backend.configuration.httpNotFoundException;
import app.betterhm.backend.v1.models.CalendarElement;
import app.betterhm.backend.v1.models.CalendarWrapper;
import app.betterhm.backend.v1.services.CalendarService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* This class is responsible for handling the calendar requests
*/
@RestController
@RequestMapping("/v1/calendar")
public class CalendarController {
private final CalendarService calendarServiceObject;
private final CalendarService calendarServiceObject;

public CalendarController(CalendarService calendarServiceObject) {
this.calendarServiceObject = calendarServiceObject;
}
/**
* Returns the list of calendar elements
* @return Json list of calendar elements
*/
@GetMapping()
public List<CalendarElement> getCalendarList() {
return this.calendarServiceObject.getCalendarElementsList();
}
public CalendarController(CalendarService calendarServiceObject) {
this.calendarServiceObject = calendarServiceObject;
}

/**
* Returns the list of calendar elements
*
* @return Json list of calendar elements
*/
@GetMapping()
public CalendarWrapper getCalendarList() {
return new CalendarWrapper(this.calendarServiceObject.getCalendarElementsList());
}

/**
* Returns the calendar element with the given ID
* @param id UUID of the calendar element
* @return Json of the calendar element
*/
@GetMapping("/{id}")
public CalendarElement getCalendar(@PathVariable String id) {
CalendarElement singleCalendarElements = calendarServiceObject.getSingleCalendarElements(id);
if (singleCalendarElements == null) {
throw new httpNotFoundException();
}
return singleCalendarElements;
/**
* Returns the calendar element with the given ID
*
* @param id UUID of the calendar element
* @return Json of the calendar element
*/
@GetMapping("/{id}")
public CalendarElement getCalendar(@PathVariable String id) {
CalendarElement singleCalendarElements = calendarServiceObject.getSingleCalendarElements(id);
if (singleCalendarElements == null) {
throw new httpNotFoundException();
}
return singleCalendarElements;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
/**
* This Record is a Template for the calendar element
*/
public record CalendarElement(String ID, String Name, String Url, Optional<String> SourceURL, Optional<String> Description) {}
public record CalendarElement(
String id,
String name,
String url,
Optional<String> sourceURL,
Optional<String> description
) {
}
19 changes: 19 additions & 0 deletions src/main/java/app/betterhm/backend/v1/models/CalendarWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.betterhm.backend.v1.models;

import java.util.List;

public class CalendarWrapper {
private List<CalendarElement> data;

public CalendarWrapper(List<CalendarElement> elements) {
this.data = elements;
}

public List<CalendarElement> getData() {
return data;
}

public void setData(List<CalendarElement> data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public List<CalendarElement> getCalendarElementsList(){
}

/**
* Returns the calendar element with the given ID
* Returns the calendar element with the given id
* @param calendarElementID UUID of the calendar element
* @return CalendarElement
*/
public CalendarElement getSingleCalendarElements(String calendarElementID) {
return calendarElementsList.stream()
.filter(Element -> Element.ID().equals(calendarElementID))
.filter(element -> element.id().equals(calendarElementID))
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ private String getDataFromLRZ(CapacityConfigRecord capacityConfigRecord) {
String[] splitUrl = lrzApiUrl.split("\\{\\{subdistrict_id}}", 2); //builds the URL with the sub-district id
apiUrl = URI.create(splitUrl[0] + capacityConfigRecord.lrz_subdistrict_id() + splitUrl[1]).toURL();
} catch (PatternSyntaxException e) {
logger.error("Could not Split LRZ Api Url Provided by the config", e);
throw new PatternSyntaxException("Could not Split LRZ Api Url Provided by the config", lrzApiUrl, -1);
logger.error("Could not Split LRZ Api url Provided by the config", e);
throw new PatternSyntaxException("Could not Split LRZ Api url Provided by the config", lrzApiUrl, -1);
Comment on lines +116 to +117
Copy link

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider revising the error message for clarity and consistency (e.g., 'Could not split LRZ API URL from configuration').

Suggested change
logger.error("Could not Split LRZ Api url Provided by the config", e);
throw new PatternSyntaxException("Could not Split LRZ Api url Provided by the config", lrzApiUrl, -1);
logger.error("Could not split LRZ API URL from configuration", e);
throw new PatternSyntaxException("Could not split LRZ API URL from configuration", lrzApiUrl, -1);

Copilot uses AI. Check for mistakes.
}catch (MalformedURLException e) {
logger.error("Could not Generate a valid Url for the LRZ Wifi Api", e);
throw new IllegalStateException("Could not Generate a valid Url for the LRZ Wifi Api", e);
logger.error("Could not Generate a valid url for the LRZ Wifi Api", e);
throw new IllegalStateException("Could not Generate a valid url for the LRZ Wifi Api", e);
Comment on lines +119 to +120
Copy link

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider revising the error message for clarity and consistency (e.g., 'Could not generate a valid URL for the LRZ WiFi API').

Suggested change
logger.error("Could not Generate a valid url for the LRZ Wifi Api", e);
throw new IllegalStateException("Could not Generate a valid url for the LRZ Wifi Api", e);
logger.error("Could not generate a valid URL for the LRZ WiFi API", e);
throw new IllegalStateException("Could not generate a valid URL for the LRZ WiFi API", e);

Copilot uses AI. Check for mistakes.
}
//gets the data from the LRZ API
try (InputStream in = apiUrl.openStream()) {
Expand Down