From b4fa718be67da9982b7351d4ec7b3c50b1e08e32 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 10 Aug 2025 12:08:49 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 38 ++++++++++++------------- src/model/books/author_s.h | 12 ++------ src/model/books/book_s.h | 48 -------------------------------- src/model/books/genre_book_s.h | 45 ++++++++++++++++++++++++++++++ src/model/books/manutomanybase.h | 10 +++++++ src/model/books/series_book_s.h | 45 ++++++++++++++++++++++++++++++ src/model/books/series_s.h | 4 +-- 7 files changed, 124 insertions(+), 78 deletions(-) create mode 100644 src/model/books/genre_book_s.h create mode 100644 src/model/books/manutomanybase.h create mode 100644 src/model/books/series_book_s.h diff --git a/src/main.cpp b/src/main.cpp index 68626cb..6c61dee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,25 +23,25 @@ void fillBooksBD(uDBase& db) try { QVector authors = { - Author_S("George Orwell", "en"), - Author_S("J.K. Rowling", "en"), - Author_S("J.R.R. Tolkien", "en"), - Author_S("Leo Tolstoy", "ru"), - Author_S("Fyodor Dostoevsky", "ru"), - Author_S("Mark Twain", "en"), - Author_S("Charles Dickens", "en"), - Author_S("Virginia Woolf", "en"), - Author_S("Ernest Hemingway", "en"), - Author_S("Gabriel García Márquez", "en"), - Author_S("Franz Kafka", "de"), - Author_S("Harper Lee", "en"), - Author_S("William Shakespeare", "en"), - Author_S("Oscar Wilde", "en"), - Author_S("Aldous Huxley", "en"), - Author_S("Jane Austen", "en"), - Author_S("John Steinbeck", "en"), - Author_S("Agatha Christie", "en"), - Author_S("Isaac Asimov", "ru"), + Author_S("George Orwell"), + Author_S("J.K. Rowling"), + Author_S("J.R.R. Tolkien"), + Author_S("Leo Tolstoy"), + Author_S("Fyodor Dostoevsky"), + Author_S("Mark Twain"), + Author_S("Charles Dickens"), + Author_S("Virginia Woolf"), + Author_S("Ernest Hemingway"), + Author_S("Gabriel García Márquez"), + Author_S("Franz Kafka"), + Author_S("Harper Lee"), + Author_S("William Shakespeare"), + Author_S("Oscar Wilde"), + Author_S("Aldous Huxley"), + Author_S("Jane Austen"), + Author_S("John Steinbeck"), + Author_S("Agatha Christie"), + Author_S("Isaac Asimov"), }; addBook(*db, "Очень странная книжка", { "Автор 1", "Автор 2", "Авторк 3" }); diff --git a/src/model/books/author_s.h b/src/model/books/author_s.h index e8d6355..1cd5d3c 100644 --- a/src/model/books/author_s.h +++ b/src/model/books/author_s.h @@ -3,19 +3,13 @@ #include -// @JsonSerializer -class Author_S; - #pragma db object class MODEL_EXPORT Author_S { public: Author_S() = default; - Author_S(const QString& fullName, - const QString& langCode) : - m_fullName(fullName), - m_langCode(langCode) - {} + Author_S(const QString& fullName) : + m_fullName(fullName) {} quint64 id() const { return m_id; } void setId(quint64 newId) { m_id = newId; } @@ -29,7 +23,7 @@ public: private: friend class odb::access; -public: // for Redkit-gen +private: #pragma db id auto quint64 m_id; diff --git a/src/model/books/book_s.h b/src/model/books/book_s.h index 9622e5e..47d4cf9 100644 --- a/src/model/books/book_s.h +++ b/src/model/books/book_s.h @@ -5,34 +5,11 @@ #include -#include "author_s.h" -#include "genre_s.h" -#include "series_s.h" - -struct Book_SZ -{ - QString title; - SH series; - quint8 year; - SH genre; - QDateTime lastModified = QDateTime::currentDateTime(); - QString lang; -}; - #pragma db object class MODEL_EXPORT Book_S { public: Book_S() = default; - Book_S(const Book_SZ& book) - { - m_title = book.title; - m_series = book.series; - m_year = book.year; - m_genre = book.genre; - m_lastModified = book.lastModified; - m_lang = book.lang; - } quint64 id() const { return m_id; } void setId(const quint64& newId) { m_id = newId; } @@ -40,15 +17,9 @@ public: QString title() const { return m_title; } void setTitle(const QString& newTitle) { m_title = newTitle; } - SH series() const { return m_series; } - void setSeries(const SH& newSeries) { m_series = newSeries; } - quint8 year() const { return m_year; } void setYear(const quint8& newYear) { m_year = newYear; } - SH genre() const { return m_genre; } - void setGenre(const SH& newGenre) { m_genre = newGenre; } - QDateTime lastModified() const { return m_lastModified; } void setLastModified(const QDateTime& newLastModified) { m_lastModified = newLastModified; } @@ -58,33 +29,14 @@ public: private: friend class odb::access; - // public: // for Redkit-gen private: #pragma db id auto quint64 m_id; QString m_title; - SH m_series; quint8 m_year; - SH m_genre; QDateTime m_lastModified; QString m_lang; }; -// #pragma db view object(Book_S) object(Author_S = author:Book_S::m_author) -// struct BookByAuthorView -// { -// #pragma db column(Book_S::m_id) -// quint64 book_id; - -// #pragma db column(Book_S::m_name) -// QString book_name; - -// #pragma db column(Book_S::m_year) -// qint8 year; - -// #pragma db column(Author_S::m_first + " " + Author_S::m_last) -// QString author_full_name; -// }; - #endif // BOOK_S_H diff --git a/src/model/books/genre_book_s.h b/src/model/books/genre_book_s.h new file mode 100644 index 0000000..e04bbc7 --- /dev/null +++ b/src/model/books/genre_book_s.h @@ -0,0 +1,45 @@ +#ifndef GENRE_BOOK_S_H +#define GENRE_BOOK_S_H + +#include + +#include "book_s.h" +#include "genre_s.h" + +#pragma db object +class GenreBook_S +{ +private: + GenreBook_S() = default; + +public: + GenreBook_S(const SH& genreId, const SH& bookId) : + m_genreId(genreId), + m_bookId(bookId) {} + + quint64 id() const { return m_id; } + void setId(quint64 newId) { m_id = newId; } + + SH genreId() const { return m_genreId; } + void setGenreId(const SH& newGenreId) { m_genreId = newGenreId; } + + SH bookId() const { return m_bookId; } + void setBookId(const SH& newBookId) { m_bookId = newBookId; } + +private: + friend class odb::access; + +private: +#pragma db id auto + quint64 m_id; + +#pragma db not_null + SH m_genreId; + +#pragma db not_null + SH m_bookId; + +#pragma db index("genre_book_unique") member(m_genreId) member(m_bookId) unique +}; + +#endif // GENRE_BOOK_S_H diff --git a/src/model/books/manutomanybase.h b/src/model/books/manutomanybase.h new file mode 100644 index 0000000..c894e70 --- /dev/null +++ b/src/model/books/manutomanybase.h @@ -0,0 +1,10 @@ +#ifndef MANUTOMANYBASE_H +#define MANUTOMANYBASE_H + +class ManuToManyBase +{ +public: + ManuToManyBase(); +}; + +#endif // MANUTOMANYBASE_H diff --git a/src/model/books/series_book_s.h b/src/model/books/series_book_s.h new file mode 100644 index 0000000..96ca570 --- /dev/null +++ b/src/model/books/series_book_s.h @@ -0,0 +1,45 @@ +#ifndef SERIES_BOOK_S_H +#define SERIES_BOOK_S_H + +#include + +#include "book_s.h" +#include "series_s.h" + +#pragma db object +class MODEL_EXPORT SeriesBook_S +{ +private: + SeriesBook_S() = default; + +public: + SeriesBook_S(const SH& serieId, const SH& bookId) : + m_serieId(serieId), + m_bookId(bookId) {} + + quint64 id() const { return m_id; } + void setId(quint64 newId) { m_id = newId; } + + SH serieId() const { return m_serieId; } + void setSerieId(const SH& newSerieId) { m_serieId = newSerieId; } + + SH bookId() const { return m_bookId; } + void setBookId(const SH& newBookId) { m_bookId = newBookId; } + +private: + friend class odb::access; + +private: +#pragma db id auto + quint64 m_id; + +#pragma db not_null + SH m_serieId; + +#pragma db not_null + SH m_bookId; + +#pragma db index("series_book_unique") member(m_serieId) member(m_bookId) unique +}; + +#endif // SERIES_BOOK_S_H diff --git a/src/model/books/series_s.h b/src/model/books/series_s.h index 62b2c91..83e92d2 100644 --- a/src/model/books/series_s.h +++ b/src/model/books/series_s.h @@ -12,8 +12,8 @@ public: quint64 id() const { return m_id; } void setId(const quint64& newId) { m_id = newId; } - QString serName() const { return m_serName; } - void setSerName(const QString& newSerName) { m_serName = newSerName; } + QString name() const { return m_serName; } + void setName(const QString& newSerName) { m_serName = newSerName; } private: friend class odb::access;