Skip to content

Commit

Permalink
changed the API of the calendar to now include an entry_type and an d…
Browse files Browse the repository at this point in the history
…etailed_entry_type
  • Loading branch information
CommanderStorm committed Jan 30, 2023
1 parent d3df3d0 commit 09a36b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
34 changes: 18 additions & 16 deletions calendar/src/calendar.rs
Expand Up @@ -62,54 +62,56 @@ struct Event {
start: NaiveDateTime,
end: NaiveDateTime,
entry_type: EventType,
detailed_entry_type: String,
}

#[derive(Serialize, Debug)]
#[serde(rename_all = "lowercase")]
enum EventType {
Lecture(String),
Lecture,
Exercise,
Exam,
Barred,
Other(String),
Other,
}
impl EventType {
fn from(xml_event: &XMLEvent) -> Self {
fn from(xml_event: &XMLEvent) -> (Self, String) {
// only used for the lecture type
let course_type_name = xml_event
.course_type_name
.clone()
.unwrap_or_else(|| "Course type is unknown".to_string());
match xml_event.single_event_type_id.as_str() {
"SPERRE" => return EventType::Barred,
"PT" => return EventType::Exam,
"P" => return EventType::Lecture(course_type_name), // Prüfung (geplant) is sometimes used for lectures
"SPERRE" => return (EventType::Barred, "".to_string()),
"PT" => return (EventType::Exam, "".to_string()),
"P" => return (EventType::Lecture, course_type_name), // Prüfung (geplant) is sometimes used for lectures
_ => {}
}
match xml_event.event_type_id.as_str() {
"LV" => EventType::Lecture(course_type_name),
"PT" => EventType::Exam,
"EX" => EventType::Exercise,
"LV" => (EventType::Lecture, course_type_name),
"PT" => (EventType::Exam, "".to_string()),
"EX" => (EventType::Exercise, "".to_string()),
_ => match &xml_event.event_type_name {
Some(event_type_name) => EventType::Other(format!(
"{}: {}",
xml_event.single_event_type_name, event_type_name
)),
None => EventType::Other(xml_event.single_event_type_name.clone()),
Some(event_type_name) => (
EventType::Other,
format!("{}: {}", xml_event.single_event_type_name, event_type_name),
),
None => (EventType::Other, xml_event.single_event_type_name.clone()),
},
}
}
}

impl From<XMLEvent> for Event {
fn from(xml_event: XMLEvent) -> Self {
let _type = EventType::from(&xml_event);
let (entry_type, detailed_entry_type) = EventType::from(&xml_event);
let title = xml_event.event_title;
Self {
title,
start: xml_event.dtstart,
end: xml_event.dtend,
entry_type: _type,
entry_type,
detailed_entry_type,
}
}
}
46 changes: 22 additions & 24 deletions openapi.yaml
Expand Up @@ -1745,34 +1745,18 @@ components:
- last_sync
CalendarEntry:
type: object
examples:
Quantenteleportation:
title: Quantenteleportation
entry_type: lecture
start: '2018-01-01T00:00:00'
end: '2018-01-01T00:00:00'
detailed_entry_type: Vorlesung mit anliegeneder übung
properties:
title:
description: The title of the Entry
type: string
example: Quantenteleportation
entry_type:
anyOf:
- type: string
enum:
- exercise
- exam
- barred
example: exercise
- type: object
properties:
Lecture:
description: more precise description what kind of Lecture this is
type: string
example: Vorlesung mit integrierter Übung
required:
- lecture
- type: object
properties:
Other:
description: more precise description what other event this is
type: string
required:
- other
start:
description: The start of the entry
type: string
Expand All @@ -1783,11 +1767,25 @@ components:
type: string
format: date-time
example: '2018-01-01T00:00:00'
entry_type:
type: string
enum:
- lecture
- exercise
- exam
- barred
- other
description: What this calendar entry means. Each of these should be displayed in a different color
detailed_entry_type:
type: string
description: 'For some Entrys, we do have more information (what kind of a `lecture` is it? What kind of an other `entry` is it?)'
example: Vorlesung mit Zentralübung
required:
- title
- entry_type
- start
- end
- entry_type
- detailed_entry_type
RankingFactors:
type: object
properties:
Expand Down

0 comments on commit 09a36b3

Please sign in to comment.