Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse modeus api #14

Merged
merged 7 commits into from
Sep 26, 2024
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
96 changes: 85 additions & 11 deletions backend/app/controllers/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime
import datetime
import uuid
from typing import Optional

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, computed_field


class NetologyCreds(BaseModel):
Expand All @@ -17,15 +19,87 @@ class ModeusCreds(BaseModel):
password: str


"""
{"size":500,"timeMin":"2024-09-23T00:00:00+03:00","timeMax":"2024-09-29T23:59:59+03:00","attendeePersonId":["d69c87c8-aece-4f39-b6a2-7b467b968211"]}
_"""


class ModeusSearchEvents(BaseModel):
"""Modeus search events body."""
size: int = Field(examples=[50], default=50)
time_min: datetime.datetime = Field(alias="timeMin", examples=[datetime.datetime.now()])
time_max: datetime.datetime = Field(alias="timeMax",
examples=[datetime.datetime.now() - datetime.timedelta(days=7)])
attendee_person_id: list[str] = Field(alias="attendeePersonId", default="d69c87c8-aece-4f39-b6a2-7b467b968211")


class Location(BaseModel):
id: uuid.UUID = Field(alias="eventId")
custom_location: str = Field(alias="customLocation")

@computed_field # type: ignore
@property
def is_lxp(self) -> float:
return self.custom_location == 'LXP'


class Event(BaseModel):
name: str = Field(alias="name")
name_short: str = Field(alias="nameShort")
description: Optional[str] = Field(alias="description")
start_time: datetime.datetime = Field(alias="start")
end_time: datetime.datetime = Field(alias="end")
id: uuid.UUID


class Href(BaseModel):
href: str

@computed_field # type: ignore
@property
def id(self) -> uuid.UUID:
return uuid.UUID(self.href.replace('/', ''))

class Link(BaseModel):
self: Href
event: Href
person: Href

class Attender(BaseModel):
links: Link = Field(alias="_links")


class Teacher(BaseModel):
id: uuid.UUID
full_name: str = Field(alias="fullName")


class Embedded(BaseModel):
events: list[Event] = Field(alias="events")
locations: list[Location] = Field(alias="event-locations")
attendees: list[Attender] = Field(alias="event-attendees")
teacher: list[Teacher] = Field(alias="persons")


class FullEvent(Event, Location):
teacher_full_name: str


class ModeusCalendar(BaseModel):
"""Modeus calendar response."""

embedded: Embedded = Field(alias="_embedded")

size: int
time_min: datetime = Field(alias="timeMin")
time_max: datetime = Field(alias="timeMax")
attendee_person_id: list[str] = Field(alias="attendeePersonId")
def parse_modeus_response(self) -> list[FullEvent]:
locations = {location.id: location for location in self.embedded.locations}
AzamatKomaev marked this conversation as resolved.
Show resolved Hide resolved
teachers = {teacher.id: teacher for teacher in self.embedded.teacher}
teachers_with_events = {teacher.links.event.id: teacher.links for teacher in self.embedded.attendees}
full_events = []
for event in self.embedded.events:
try:
teacher_event = teachers_with_events[event.id]
teacher = teachers[teacher_event.person.id]
teacher_full_name = teacher.full_name
except KeyError:
teacher_full_name = 'unknown'
location = locations[event.id]
full_events.append(FullEvent(**{
"teacher_full_name": teacher_full_name,
**event.model_dump(by_alias=True), **location.model_dump(by_alias=True),
}))
return full_events
2 changes: 1 addition & 1 deletion backend/app/controllers/modeus.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class FromAuthorizationHeader(FromHeader[str]):
name = "Authorization"
name = "bearer-token"


class ModeusController(Controller):
Expand Down
1 change: 1 addition & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def configure_application(
show_error_details=settings.app.show_error_details,
)

app.serve_files("app/static")
configure_error_handlers(app)
configure_authentication(app, settings)
configure_docs(app, settings)
Expand Down
Binary file added backend/app/static/blacksheep-favicon-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/favicon.ico
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/images/blacksheep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/img/portfolio/cabin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/img/portfolio/cake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/img/portfolio/circus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/img/portfolio/game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/img/portfolio/safe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/app/static/img/portfolio/submarine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions backend/app/static/scripts/freelancer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
(function($) {
"use strict"; // Start of use strict

// Smooth scrolling using jQuery easing
$('a.js-scroll-trigger[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: (target.offset().top - 71)
}, 1000, "easeInOutExpo");
return false;
}
}
});

// Scroll to top button appear
$(document).scroll(function() {
var scrollDistance = $(this).scrollTop();
if (scrollDistance > 100) {
$('.scroll-to-top').fadeIn();
} else {
$('.scroll-to-top').fadeOut();
}
});

// Closes responsive menu when a scroll trigger link is clicked
$('.js-scroll-trigger').click(function() {
$('.navbar-collapse').collapse('hide');
});

// Activate scrollspy to add active class to navbar items on scroll
$('body').scrollspy({
target: '#mainNav',
offset: 80
});

// Collapse Navbar
var navbarCollapse = function() {
if ($("#mainNav").offset().top > 100) {
$("#mainNav").addClass("navbar-shrink");
} else {
$("#mainNav").removeClass("navbar-shrink");
}
};
// Collapse now if page is not at top
navbarCollapse();
// Collapse the navbar when page is scrolled
$(window).scroll(navbarCollapse);

// Floating label headings for the contact form
$(function() {
$("body").on("input propertychange", ".floating-label-form-group", function(e) {
$(this).toggleClass("floating-label-form-group-with-value", !!$(e.target).val());
}).on("focus", ".floating-label-form-group", function() {
$(this).addClass("floating-label-form-group-with-focus");
}).on("blur", ".floating-label-form-group", function() {
$(this).removeClass("floating-label-form-group-with-focus");
});
});

})(jQuery); // End of use strict
Loading
Loading