Skip to content

Commit 75b33a8

Browse files
Improved naming and comments
1 parent 7fa5522 commit 75b33a8

8 files changed

Lines changed: 110 additions & 104 deletions

File tree

src/adapters/controllers/book_controller.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ int BookController::addTag(const QString& bookUuid, const QString& tagName,
174174
}
175175

176176
Tag tag(tagName, tagUuid);
177-
auto result = m_bookService->addTag(bookUuid, tag);
177+
auto result = m_bookService->addTagToBook(bookUuid, tag);
178178

179179
return static_cast<int>(result);
180180
}
@@ -189,7 +189,7 @@ void BookController::removeAllTagsWithUuid(const QString& tagUuid)
189189
{
190190
if(vectorContainsTag(book.getTags(), tagUuid))
191191
{
192-
m_bookService->removeTag(book.getUuid(), tagUuid);
192+
m_bookService->removeTagFromBook(book.getUuid(), tagUuid);
193193
}
194194
}
195195
}
@@ -201,13 +201,13 @@ void BookController::renameTags(const QString& oldName, const QString& newName)
201201
{
202202
auto tagUuid = getTagUuidByName(book, oldName);
203203
if(!tagUuid.isNull())
204-
m_bookService->renameTag(book.getUuid(), tagUuid, newName);
204+
m_bookService->renameTagOfBook(book.getUuid(), tagUuid, newName);
205205
}
206206
}
207207

208208
int BookController::removeTag(const QString& bookUuid, const QString& tagUuid)
209209
{
210-
auto result = m_bookService->removeTag(bookUuid, tagUuid);
210+
auto result = m_bookService->removeTagFromBook(bookUuid, tagUuid);
211211
return static_cast<int>(result);
212212
}
213213

@@ -242,7 +242,7 @@ int BookController::saveBookToFile(const QString& uuid, const QUrl& path)
242242

243243
void BookController::refreshLastOpenedFlag(const QString& uuid)
244244
{
245-
m_bookService->refreshLastOpened(uuid);
245+
m_bookService->refreshLastOpenedDateOfBook(uuid);
246246
}
247247

248248
QImage BookController::getCorrectlySizedBookCover(const QString& pathToCover)

src/application/interfaces/services/i_book_service.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ class IBookService : public QObject
3333
virtual int getBookIndex(const QUuid& uuid) const = 0;
3434
virtual int getBookCount() const = 0;
3535

36-
virtual BookOperationStatus addTag(const QUuid& uuid,
36+
virtual BookOperationStatus addTagToBook(const QUuid& uuid,
3737
const domain::entities::Tag& tag) = 0;
38-
virtual BookOperationStatus removeTag(const QUuid& bookUuid,
38+
virtual BookOperationStatus removeTagFromBook(const QUuid& bookUuid,
3939
const QUuid& tagUuid) = 0;
40-
virtual BookOperationStatus renameTag(const QUuid& bookUuid,
40+
virtual BookOperationStatus renameTagOfBook(const QUuid& bookUuid,
4141
const QUuid& tagUuid,
4242
const QString& newName) = 0;
4343

4444
virtual BookOperationStatus saveBookToFile(const QUuid& uuid,
4545
const QUrl& path) = 0;
4646

4747
public slots:
48-
virtual bool refreshLastOpened(const QUuid& uuid) = 0;
48+
virtual bool refreshLastOpenedDateOfBook(const QUuid& uuid) = 0;
4949
virtual void setupUserData(const QString& token, const QString& email) = 0;
5050
virtual void clearUserData() = 0;
5151

src/application/services/book_service.cpp

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BookService::BookService(IBookMetadataHelper* bookMetadataHelper,
2222
{
2323
// Book cover generated
2424
connect(m_bookMetadataHelper, &IBookMetadataHelper::bookCoverGenerated,
25-
this, &BookService::storeBookCover);
25+
this, &BookService::assignBookCoverToBook);
2626

2727
// Fetch changes timer
2828
m_fetchChangesTimer.setInterval(m_fetchChangedInterval);
@@ -32,11 +32,11 @@ BookService::BookService(IBookMetadataHelper* bookMetadataHelper,
3232
// Getting books finished
3333
connect(m_bookStorageManager,
3434
&IBookStorageManager::loadingRemoteBooksFinished, this,
35-
&BookService::mergeLibraries);
35+
&BookService::updateLibrary);
3636

3737
// Downloading book finished
3838
connect(m_bookStorageManager, &IBookStorageManager::finishedDownloadingBook,
39-
this, &BookService::updateDownloadedBook);
39+
this, &BookService::processDownloadedBook);
4040
}
4141

4242
BookOperationStatus BookService::addBook(const QString& filePath)
@@ -146,8 +146,9 @@ BookOperationStatus BookService::updateBook(const Book& newBook)
146146
return BookOperationStatus::BookDoesNotExist;
147147
}
148148

149-
// Manually handle changes to current page to prevent "lastModified" being
150-
// updated on a simple page update
149+
// Manually handle changes to "current page" because we don't want
150+
// "lastModified" to be updated on a "current page" change, since this would
151+
// break the whole updating mechanism.
151152
book->setCurrentPage(newBook.getCurrentPage());
152153

153154
if(*book != newBook)
@@ -164,8 +165,8 @@ BookOperationStatus BookService::updateBook(const Book& newBook)
164165
return BookOperationStatus::Success;
165166
}
166167

167-
BookOperationStatus BookService::addTag(const QUuid& uuid,
168-
const domain::entities::Tag& tag)
168+
BookOperationStatus BookService::addTagToBook(const QUuid& uuid,
169+
const domain::entities::Tag& tag)
169170
{
170171
auto* book = getBook(uuid);
171172
if(book == nullptr)
@@ -193,8 +194,8 @@ BookOperationStatus BookService::addTag(const QUuid& uuid,
193194
return BookOperationStatus::Success;
194195
}
195196

196-
BookOperationStatus BookService::removeTag(const QUuid& bookUuid,
197-
const QUuid& tagUuid)
197+
BookOperationStatus BookService::removeTagFromBook(const QUuid& bookUuid,
198+
const QUuid& tagUuid)
198199
{
199200
auto* book = getBook(bookUuid);
200201
if(book == nullptr)
@@ -222,9 +223,9 @@ BookOperationStatus BookService::removeTag(const QUuid& bookUuid,
222223
return BookOperationStatus::Success;
223224
}
224225

225-
BookOperationStatus BookService::renameTag(const QUuid& bookUuid,
226-
const QUuid& tagUuid,
227-
const QString& newName)
226+
BookOperationStatus BookService::renameTagOfBook(const QUuid& bookUuid,
227+
const QUuid& tagUuid,
228+
const QString& newName)
228229
{
229230
auto* book = getBook(bookUuid);
230231
if(book == nullptr)
@@ -327,7 +328,7 @@ BookOperationStatus BookService::saveBookToFile(const QUuid& uuid,
327328
return BookOperationStatus::Success;
328329
}
329330

330-
bool BookService::refreshLastOpened(const QUuid& uuid)
331+
bool BookService::refreshLastOpenedDateOfBook(const QUuid& uuid)
331332
{
332333
auto* book = getBook(uuid);
333334
if(book == nullptr)
@@ -342,8 +343,8 @@ bool BookService::refreshLastOpened(const QUuid& uuid)
342343
return true;
343344
}
344345

345-
void BookService::updateDownloadedBook(const QUuid& uuid,
346-
const QString& filePath)
346+
void BookService::processDownloadedBook(const QUuid& uuid,
347+
const QString& filePath)
347348
{
348349
auto* book = getBook(uuid);
349350

@@ -388,7 +389,7 @@ void BookService::clearUserData()
388389
emit bookClearingEnded();
389390
}
390391

391-
void BookService::storeBookCover(const QPixmap* pixmap)
392+
void BookService::assignBookCoverToBook(const QPixmap* pixmap)
392393
{
393394
int index = m_books.size() - 1;
394395
auto& book = m_books.at(index);
@@ -397,9 +398,11 @@ void BookService::storeBookCover(const QPixmap* pixmap)
397398
emit bookCoverGenerated(index);
398399
}
399400

400-
void BookService::mergeLibraries(
401-
const std::vector<domain::entities::Book>& books)
401+
void BookService::updateLibrary(const std::vector<Book>& books)
402402
{
403+
// The remote library is the library fetched from the server and the local
404+
// library is the library on the client's PC. On startup we need to make
405+
// sure that both libraries are synchronized.
403406
mergeRemoteLibraryIntoLocalLibrary(books);
404407
mergeLocalLibraryIntoRemoteLibrary(books);
405408
}
@@ -416,6 +419,7 @@ void BookService::mergeRemoteLibraryIntoLocalLibrary(
416419
continue;
417420
}
418421

422+
// Add the remote book to the local library if it does not exist
419423
emit bookInsertionStarted(m_books.size());
420424
m_books.emplace_back(remoteBook);
421425
emit bookInsertionEnded();
@@ -439,71 +443,73 @@ void BookService::mergeLocalLibraryIntoRemoteLibrary(
439443
}
440444
}
441445

442-
void BookService::mergeBooks(Book& original, const Book& mergee)
446+
void BookService::mergeBooks(Book& localBook, const Book& remoteBook)
443447
{
444-
auto lastOpenedStatus = mergeCurrentPage(original, mergee);
445-
auto lastModifiedStatus = mergeBookData(original, mergee);
448+
auto lastOpenedStatus = mergeCurrentPage(localBook, remoteBook);
449+
auto lastModifiedStatus = mergeBookData(localBook, remoteBook);
446450

447451

448-
if(lastOpenedStatus.updateLocalLibrary ||
449-
lastModifiedStatus.updateLocalLibrary)
452+
if(lastOpenedStatus.localLibraryOutdated ||
453+
lastModifiedStatus.localLibraryOutdated)
450454
{
451-
m_bookStorageManager->updateBookLocally(original);
455+
m_bookStorageManager->updateBookLocally(localBook);
452456

453457
// Update UI
454-
auto index = getBookIndex(original.getUuid());
458+
auto index = getBookIndex(localBook.getUuid());
455459
emit dataChanged(index);
456460
}
457461

458-
if(lastOpenedStatus.updateDatabase || lastModifiedStatus.updateDatabase)
462+
if(lastOpenedStatus.remoteLibraryOutdated ||
463+
lastModifiedStatus.remoteLibraryOutdated)
459464
{
460-
m_bookStorageManager->updateBookRemotely(original);
465+
m_bookStorageManager->updateBookRemotely(localBook);
461466
}
462467
}
463468

464-
MergeStatus BookService::mergeCurrentPage(domain::entities::Book& original,
465-
const domain::entities::Book& mergee)
469+
MergeStatus BookService::mergeCurrentPage(Book& localBook,
470+
const Book& remoteBook)
466471
{
467-
// Take the current time in seconds, so there are no ms mismatches
468-
auto mergeeLastOpened = mergee.getLastOpened().toSecsSinceEpoch();
469-
auto originalLastOpened = original.getLastOpened().toSecsSinceEpoch();
472+
// Take the current time in seconds, so that there are no ms mismatches
473+
auto localLastOpened = localBook.getLastOpened().toSecsSinceEpoch();
474+
auto remoteLastOpened = remoteBook.getLastOpened().toSecsSinceEpoch();
470475

471-
if(mergeeLastOpened == originalLastOpened)
476+
// There are no "current page" differences between the local and remote book
477+
if(remoteLastOpened == localLastOpened)
472478
return {};
473479

474-
if(mergeeLastOpened > originalLastOpened)
480+
if(remoteLastOpened > localLastOpened)
475481
{
476-
original.setCurrentPage(mergee.getCurrentPage());
477-
original.setLastOpened(mergee.getLastOpened());
482+
localBook.setCurrentPage(remoteBook.getCurrentPage());
483+
localBook.setLastOpened(remoteBook.getLastOpened());
478484

479-
return MergeStatus { .updateLocalLibrary = true };
485+
return MergeStatus { .localLibraryOutdated = true };
480486
}
481487

482-
return MergeStatus { .updateDatabase = true };
488+
return MergeStatus { .remoteLibraryOutdated = true };
483489
}
484490

485-
MergeStatus BookService::mergeBookData(domain::entities::Book& original,
486-
const domain::entities::Book& mergee)
491+
MergeStatus BookService::mergeBookData(Book& localBook, const Book& remoteBook)
487492
{
488-
// Take the current time in seconds, so there are no ms mismatches
489-
auto mergeeLastModified = mergee.getLastModified().toSecsSinceEpoch();
490-
auto originalLastModified = original.getLastModified().toSecsSinceEpoch();
493+
// Take the current time in seconds, so that there are no ms mismatches
494+
auto localLastModified = localBook.getLastModified().toSecsSinceEpoch();
495+
auto remoteLastModified = remoteBook.getLastModified().toSecsSinceEpoch();
491496

492-
if(mergeeLastModified == originalLastModified)
497+
// There are no data differences between the local and remote book
498+
if(remoteLastModified == localLastModified)
493499
return {};
494500

495-
if(mergeeLastModified > originalLastModified)
501+
if(remoteLastModified > localLastModified)
496502
{
497503
// Save the file path since its overwritten during the update
498504
// operation
499-
auto localBookFilePath = original.getFilePath();
500-
original.update(mergee);
501-
original.setFilePath(localBookFilePath);
505+
auto localBookFilePath = localBook.getFilePath();
506+
localBook.update(remoteBook);
507+
localBook.setFilePath(localBookFilePath);
502508

503-
return MergeStatus { .updateLocalLibrary = true };
509+
return MergeStatus { .localLibraryOutdated = true };
504510
}
505511

506-
return MergeStatus { .updateDatabase = true };
512+
return MergeStatus { .remoteLibraryOutdated = true };
507513
}
508514

509515
} // namespace application::services

src/application/services/book_service.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ class BookService : public IBookService
2525
BookOperationStatus downloadBook(const QUuid& uuid) override;
2626
BookOperationStatus updateBook(
2727
const domain::entities::Book& newBook) override;
28+
BookOperationStatus saveBookToFile(const QUuid& uuid,
29+
const QUrl& path) override;
2830

29-
BookOperationStatus addTag(const QUuid& uuid,
30-
const domain::entities::Tag& tag) override;
31-
BookOperationStatus removeTag(const QUuid& bookUuid,
32-
const QUuid& tagUuid) override;
33-
BookOperationStatus renameTag(const QUuid& bookUuid, const QUuid& tagUuid,
34-
const QString& newName) override;
31+
BookOperationStatus addTagToBook(const QUuid& uuid,
32+
const domain::entities::Tag& tag) override;
33+
BookOperationStatus removeTagFromBook(const QUuid& bookUuid,
34+
const QUuid& tagUuid) override;
35+
BookOperationStatus renameTagOfBook(const QUuid& bookUuid,
36+
const QUuid& tagUuid,
37+
const QString& newName) override;
3538

3639
const std::vector<domain::entities::Book>& getBooks() const override;
3740
const domain::entities::Book* getBook(const QUuid& uuid) const override;
3841
domain::entities::Book* getBook(const QUuid& uuid) override;
3942
int getBookIndex(const QUuid& uuid) const override;
4043
int getBookCount() const override;
4144

42-
BookOperationStatus saveBookToFile(const QUuid& uuid,
43-
const QUrl& path) override;
44-
4545
public slots:
46-
bool refreshLastOpened(const QUuid& uuid) override;
47-
void updateDownloadedBook(const QUuid& uuid, const QString& filePath);
46+
bool refreshLastOpenedDateOfBook(const QUuid& uuid) override;
4847
void setupUserData(const QString& token, const QString& email) override;
4948
void clearUserData() override;
5049

5150
private slots:
52-
void storeBookCover(const QPixmap* pixmap);
53-
void mergeLibraries(const std::vector<domain::entities::Book>& books);
51+
void assignBookCoverToBook(const QPixmap* pixmap);
52+
void updateLibrary(const std::vector<domain::entities::Book>& books);
53+
void processDownloadedBook(const QUuid& uuid, const QString& filePath);
5454

5555
private:
5656
auto getBookPosition(const QUuid& uuid);

src/application/utility/merge_status.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace application::utility
44
{
55

6-
// A status struct used to hold information about whether the database or the
7-
// local library needs to be updated after merging two books
6+
// A status struct used to hold information about whether the remote or the
7+
// local library is outdated.
88
struct MergeStatus
99
{
10-
bool updateLocalLibrary = false;
11-
bool updateDatabase = false;
10+
bool localLibraryOutdated = false;
11+
bool remoteLibraryOutdated = false;
1212
};
1313

1414
} // namespace application::utility

src/infrastructure/data/endpoints.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace infrastructure::data
55
{
66

7-
inline const QString baseUrl { "https://librum-dev.azurewebsites.net" };
7+
inline const QString baseUrl { "https://localhost:7084" };
88

99
// Authentication
1010
inline const QString authenticationEndpoint { baseUrl + "/api/login" };

0 commit comments

Comments
 (0)