66 lines
2.3 KiB
C++
66 lines
2.3 KiB
C++
|
|
#ifndef SESSION_INFO_REPOSITORY_H
|
||
|
|
#define SESSION_INFO_REPOSITORY_H
|
||
|
|
|
||
|
|
#include "base_sql_table_repository.h"
|
||
|
|
#include "sessions_statistics_repository_interface.h"
|
||
|
|
|
||
|
|
#include <QSqlDatabase>
|
||
|
|
#include <optional>
|
||
|
|
|
||
|
|
class SessionsStatisticsRepository
|
||
|
|
: public SessionsStatisticsRepositoryInterface,
|
||
|
|
public BaseSqlTableRepository {
|
||
|
|
private:
|
||
|
|
static constexpr const char *SELECT_QUERY =
|
||
|
|
"SELECT session_id, begin_at, ticket_price, hall_id, hall_name, "
|
||
|
|
"total_seats, movie_id, movie_title, duration, genre_id, genre_name, "
|
||
|
|
"sold_tickets, refunded_tickets, sales_revenue, refund_expenses FROM "
|
||
|
|
"sessions_statistics";
|
||
|
|
|
||
|
|
// Overrides methods from SessionsStatisticRepositoryInterface
|
||
|
|
public:
|
||
|
|
explicit SessionsStatisticsRepository(QSqlDatabase &database,
|
||
|
|
QObject *parent);
|
||
|
|
|
||
|
|
RepositoryResult
|
||
|
|
getSessionById(qint32 sessionId,
|
||
|
|
SessionStatisticsDTO &sessionStatistics) const override;
|
||
|
|
|
||
|
|
RepositoryResult
|
||
|
|
getAllSessions(QVector<SessionStatisticsDTO> &sessions) const override;
|
||
|
|
|
||
|
|
// New methods
|
||
|
|
public:
|
||
|
|
RepositoryResult
|
||
|
|
getSessionsForGenre(qint32 genreName, std::optional<QDateTime> startDate,
|
||
|
|
std::optional<QDateTime> endDate,
|
||
|
|
QVector<SessionStatisticsDTO> &sessions) const override;
|
||
|
|
|
||
|
|
RepositoryResult
|
||
|
|
getSessionsForHall(qint32 hallId, std::optional<QDateTime> startDate,
|
||
|
|
std::optional<QDateTime> endDate,
|
||
|
|
QVector<SessionStatisticsDTO> &sessions) const override;
|
||
|
|
|
||
|
|
RepositoryResult
|
||
|
|
getSessionsForMovie(qint32 movieId, std::optional<QDateTime> startDate,
|
||
|
|
std::optional<QDateTime> endDate,
|
||
|
|
QVector<SessionStatisticsDTO> &sessions) const override;
|
||
|
|
|
||
|
|
private:
|
||
|
|
SessionStatisticsDTO mapQueryToDTO(const QSqlQuery &query) const;
|
||
|
|
|
||
|
|
void bindDateFilters(QString &queryString,
|
||
|
|
const std::optional<QDateTime> &startDate,
|
||
|
|
const std::optional<QDateTime> &endDate) const;
|
||
|
|
|
||
|
|
void bindDateValues(QSqlQuery &query,
|
||
|
|
const std::optional<QDateTime> &startDate,
|
||
|
|
const std::optional<QDateTime> &endDate) const;
|
||
|
|
|
||
|
|
RepositoryResult
|
||
|
|
executeAndMapQuery(QSqlQuery &query,
|
||
|
|
QVector<SessionStatisticsDTO> &sessions) const;
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif // SESSION_INFO_REPOSITORY_H
|