Logo

Cake Planner

Backend

event_model.cpp

File Header Information

FieldValue
SPDX CommentEvent Model Implementation
SPDX TypeSOURCE
ContributorZHENG Robert
License IDMIT
Fileevent_model.cpp
DescriptionEvent Model Implementation
Version0.15.0
Date2026-01-24
AuthorZHENG Robert (robert@hase-zheng.net)
CopyrightCopyright (c) 2026 ZHENG Robert
LicenseMIT

Table of Contents

API Documentation

crow::json::wvalue Event::toJson() const

Converts the Event object to a JSON value.

Returns: A crow::json::wvalue containing the event data.


std::vector Event::getRange(const QString &start,

Retrieves a list of events within a specific date range for a user.

ParameterDescription
startThe start date (inclusive, format yyyy-MM-dd).
endThe end date (inclusive, format yyyy-MM-dd).
userIdThe ID of the user requesting the events.

Returns: A vector of Event objects.


QSqlQuery query(db)

Function implementation.


bool Event::create(const QString &userId)

Creates a new event in the database.

ParameterDescription
userIdThe ID of the user creating the event (the baker).

Returns: True if successful, false otherwise.


QSqlQuery userQuery(db)

Function implementation.


QSqlQuery query(db)

Function implementation.


std::optional Event::getById(const QString& eventId, const QString& currentUserId)

Retrieves a specific event by its ID.

ParameterDescription
eventIdThe ID of the event to retrieve.
currentUserIdThe ID of the currently logged-in user.

Returns: An optional Event object if found, std::nullopt otherwise.


QSqlQuery query(db)

Function implementation.


bool Event::deleteEvent(const QString& eventId, const QString& currentUserId)

Deletes an event.

ParameterDescription
eventIdThe ID of the event to delete.
currentUserIdThe ID of the user attempting to delete the event.

Returns: True if successful and authorized, false otherwise.


QSqlQuery query(db)

Function implementation.


bool Event::rateEvent(const QString& eventId, const QString& userId, int stars, const QString& comment)

Rates an event.

ParameterDescription
eventIdThe ID of the event to rate.
userIdThe ID of the user submitting the rating.
starsThe number of stars (rating value).
commentAn optional comment.

Returns: True if successful, false otherwise.


QSqlQuery query(db)

Function implementation.


INSERT INTO ratings (id, event_id, rater_id, rating_value, comment)

Function implementation.


bool Event::uploadPhoto(const QString& eventId, const QString& userId, const QString& filename)

Uploads a photo to an event's gallery.

ParameterDescription
eventIdThe ID of the event.
userIdThe ID of the user uploading the photo.
filenameThe relative path/filename of the uploaded photo.

Returns: True if successful, false otherwise.


QSqlQuery query(db)

Function implementation.


INSERT INTO event_photos (event_id, user_id, photo_path, uploaded_at)

Function implementation.


QSqlQuery updateCover(db)

Function implementation.


std::string Event::toIcsString() const

Generates an ICS (iCalendar) string for the event.

Returns: The ICS string.


std::vector Event::getRanked(const QString& userId, int limit)

Retrieves a list of events ranked by their average rating.

ParameterDescription
userIdThe ID of the requesting user (used for group filtering).
limitThe maximum number of events to return.

Returns: A vector of ranked Event objects.


QSqlQuery query(db)

Function implementation.


QSqlQuery galQuery(db)

Function implementation.