Skip to content

Commit

Permalink
rename repositories' removeInCascade to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquetc committed Sep 28, 2024
1 parent 0b659f6 commit 6bcd1ee
Show file tree
Hide file tree
Showing 65 changed files with 930 additions and 888 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ install(FILES LICENSE DESTINATION share/qleany)
install(
EXPORT qleanyTargets
FILE qleanyTargets.cmake
DESTINATION lib/cmake/qleany)
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/qleany)

# Create and install qleanyConfig.cmake
message(STATUS "Creating and installing qleanyConfig.cmake")
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ Prerequisites:
- QCoro (dev packages)
- Cmake and extra-cmake-modules

On Debian-based distribution, it would be packages like: qtbase6-dev qcoro-qt6-dev cmake extra-cmake-modules cmake-extras
Depending of your options: qt6-declarative-dev qt6-svg-dev libkf6*dev kirigami2-dev

Adapt the -j6 to your number of CPU minus one.

CMake options are:
Expand Down
2 changes: 1 addition & 1 deletion examples/front_ends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if(BUILD_KF6_KIRIGAMI OR BUILD_QT_QUICK)
endif()

if(BUILD_KF6_KIRIGAMI)
find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 CoreAddons
find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS Kirigami CoreAddons
Config I18n)

if(ANDROID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@ using namespace FrontEnds::Contracts::Repository;
using namespace FrontEnds::Contracts::CQRS::Brand::Validators;
using namespace FrontEnds::Application::Features::Brand::Commands;

CreateBrandCommandHandler::CreateBrandCommandHandler(InterfaceBrandRepository *repository) : m_repository(repository)
CreateBrandCommandHandler::CreateBrandCommandHandler(InterfaceBrandRepository *repository)
: m_repository(repository)
{
if (!s_mappingRegistered)
{
if (!s_mappingRegistered) {
registerMappings();
s_mappingRegistered = true;
}
}

Result<BrandDTO> CreateBrandCommandHandler::handle(QPromise<Result<void>> &progressPromise,
const CreateBrandCommand &request)
Result<BrandDTO> CreateBrandCommandHandler::handle(QPromise<Result<void>> &progressPromise, const CreateBrandCommand &request)
{
Result<BrandDTO> result;

try
{
try {
result = handleImpl(progressPromise, request);
}
catch (const std::exception &ex)
{
} catch (const std::exception &ex) {
result = Result<BrandDTO>(QLN_ERROR_2(Q_FUNC_INFO, Error::Critical, "Unknown error", ex.what()));
qDebug() << "Error handling CreateBrandCommand:" << ex.what();
}
Expand All @@ -44,20 +40,16 @@ Result<BrandDTO> CreateBrandCommandHandler::restore()
{
Result<BrandDTO> result;

try
{
try {
result = restoreImpl();
}
catch (const std::exception &ex)
{
} catch (const std::exception &ex) {
result = Result<BrandDTO>(QLN_ERROR_2(Q_FUNC_INFO, Error::Critical, "Unknown error", ex.what()));
qDebug() << "Error handling CreateBrandCommand restore:" << ex.what();
}
return result;
}

Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &progressPromise,
const CreateBrandCommand &request)
Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &progressPromise, const CreateBrandCommand &request)
{
qDebug() << "CreateBrandCommandHandler::handleImpl called";
FrontEnds::Entities::Brand brand;
Expand All @@ -69,8 +61,7 @@ Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &p
int ownerId = createDTO.carId();
m_ownerId = ownerId;

if (m_firstPass)
{
if (m_firstPass) {
// Validate the create Brand command using the validator
auto validator = CreateBrandCommandValidator(m_repository);
Result<void> validatorResult = validator.validate(createDTO);
Expand All @@ -82,17 +73,15 @@ Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &p
brand = Qleany::Tools::AutoMapper::AutoMapper::map<CreateBrandDTO, FrontEnds::Entities::Brand>(createDTO);

// allow for forcing the uuid
if (brand.uuid().isNull())
{
if (brand.uuid().isNull()) {
brand.setUuid(QUuid::createUuid());
}

// Set the creation and update timestamps to the current date and time
brand.setCreationDate(QDateTime::currentDateTime());
brand.setUpdateDate(QDateTime::currentDateTime());
}
else
{

} else {
brand = m_newEntity.value();
}

Expand All @@ -112,12 +101,9 @@ Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &p

int position = -1;

if (m_firstPass)
{

if (m_firstPass) {
auto originalOwnerBrandResult = m_repository->getEntityInRelationOf(Car::schema, ownerId, "brand"_L1);
if (Q_UNLIKELY(originalOwnerBrandResult.hasError()))
{
if (Q_UNLIKELY(originalOwnerBrandResult.hasError())) {
return Result<BrandDTO>(originalOwnerBrandResult.error());
}
auto originalOwnerBrand = originalOwnerBrandResult.value();
Expand All @@ -128,25 +114,21 @@ Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &p

m_ownerBrandNewState = originalOwnerBrand;
ownerEntityBrand = originalOwnerBrand;
}
else
{
} else {
ownerEntityBrand = m_ownerBrandNewState;
position = m_position;
}

// Add the brand to the owner entity
Result<FrontEnds::Entities::Brand> updateResult =
m_repository->updateEntityInRelationOf(Car::schema, ownerId, "brand"_L1, ownerEntityBrand);
Result<FrontEnds::Entities::Brand> updateResult = m_repository->updateEntityInRelationOf(Car::schema, ownerId, "brand"_L1, ownerEntityBrand);

QLN_RETURN_IF_ERROR_WITH_ACTION(BrandDTO, updateResult, m_repository->cancelChanges();)

m_repository->saveChanges();

m_newEntity = brandResult;

auto brandDTO =
Qleany::Tools::AutoMapper::AutoMapper::map<FrontEnds::Entities::Brand, BrandDTO>(brandResult.value());
auto brandDTO = Qleany::Tools::AutoMapper::AutoMapper::map<FrontEnds::Entities::Brand, BrandDTO>(brandResult.value());
Q_EMIT brandCreated(brandDTO);

// send an insertion signal
Expand All @@ -163,11 +145,11 @@ Result<BrandDTO> CreateBrandCommandHandler::handleImpl(QPromise<Result<void>> &p
Result<BrandDTO> CreateBrandCommandHandler::restoreImpl()
{
int entityId = m_newEntity.value().id();
auto deleteResult = m_repository->remove(entityId);
auto deleteResult = m_repository->remove(QList<int>() << entityId);

QLN_RETURN_IF_ERROR(BrandDTO, deleteResult)

Q_EMIT brandRemoved(deleteResult.value());
Q_EMIT brandRemoved(deleteResult.value().value(FrontEnds::Entities::Entities::EntityEnum::Brand).first());

qDebug() << "Brand removed:" << deleteResult.value();

Expand All @@ -180,8 +162,6 @@ bool CreateBrandCommandHandler::s_mappingRegistered = false;

void CreateBrandCommandHandler::registerMappings()
{
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<FrontEnds::Entities::Brand, Contracts::DTO::Brand::BrandDTO>(
true, true);
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<Contracts::DTO::Brand::CreateBrandDTO,
FrontEnds::Entities::Brand>();
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<FrontEnds::Entities::Brand, Contracts::DTO::Brand::BrandDTO>(true, true);
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<Contracts::DTO::Brand::CreateBrandDTO, FrontEnds::Entities::Brand>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ namespace FrontEnds::Application::Features::Brand::Commands
class FRONT_ENDS_EXAMPLE_APPLICATION_BRAND_EXPORT CreateBrandCommandHandler : public QObject
{
Q_OBJECT
public:
public:
CreateBrandCommandHandler(InterfaceBrandRepository *repository);

Result<BrandDTO> handle(QPromise<Result<void>> &progressPromise, const CreateBrandCommand &request);
Result<BrandDTO> restore();

Q_SIGNALS:
Q_SIGNALS:
void brandCreated(FrontEnds::Contracts::DTO::Brand::BrandDTO brandDto);
void brandRemoved(int id);

void relationWithOwnerInserted(int id, int ownerId, int position);
void relationWithOwnerRemoved(int id, int ownerId);

private:
private:
InterfaceBrandRepository *m_repository;
Result<BrandDTO> handleImpl(QPromise<Result<void>> &progressPromise, const CreateBrandCommand &request);
Result<BrandDTO> restoreImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ using namespace FrontEnds::Contracts::CQRS::Brand::Commands;
using namespace FrontEnds::Application::Features::Brand::Commands;
using namespace FrontEnds::Contracts::CQRS::Brand::Validators;

RemoveBrandCommandHandler::RemoveBrandCommandHandler(InterfaceBrandRepository *repository) : m_repository(repository)
RemoveBrandCommandHandler::RemoveBrandCommandHandler(InterfaceBrandRepository *repository)
: m_repository(repository)
{
if (!s_mappingRegistered)
{
if (!s_mappingRegistered) {
registerMappings();
s_mappingRegistered = true;
}
}

Result<int> RemoveBrandCommandHandler::handle(QPromise<Result<void>> &progressPromise,
const RemoveBrandCommand &request)
Result<int> RemoveBrandCommandHandler::handle(QPromise<Result<void>> &progressPromise, const RemoveBrandCommand &request)
{
Result<int> result;

try
{
try {
result = handleImpl(progressPromise, request);
}
catch (const std::exception &ex)
{
} catch (const std::exception &ex) {
result = Result<int>(QLN_ERROR_2(Q_FUNC_INFO, Error::Critical, "Unknown error", ex.what()));
qDebug() << "Error handling RemoveBrandCommand:" << ex.what();
}
Expand All @@ -43,20 +39,16 @@ Result<int> RemoveBrandCommandHandler::restore()
{
Result<int> result;

try
{
try {
result = restoreImpl();
}
catch (const std::exception &ex)
{
} catch (const std::exception &ex) {
result = Result<int>(QLN_ERROR_2(Q_FUNC_INFO, Error::Critical, "Unknown error", ex.what()));
qDebug() << "Error handling RemoveBrandCommand restore:" << ex.what();
}
return result;
}

Result<int> RemoveBrandCommandHandler::handleImpl(QPromise<Result<void>> &progressPromise,
const RemoveBrandCommand &request)
Result<int> RemoveBrandCommandHandler::handleImpl(QPromise<Result<void>> &progressPromise, const RemoveBrandCommand &request)
{
int brandId = request.id;

Expand All @@ -73,7 +65,7 @@ Result<int> RemoveBrandCommandHandler::handleImpl(QPromise<Result<void>> &progre
// save old entity
m_oldState = brandResult.value();

auto deleteResult = m_repository->removeInCascade(QList<int>() << brandId);
auto deleteResult = m_repository->remove(QList<int>() << brandId);

QLN_RETURN_IF_ERROR(int, deleteResult)

Expand All @@ -95,6 +87,5 @@ bool RemoveBrandCommandHandler::s_mappingRegistered = false;

void RemoveBrandCommandHandler::registerMappings()
{
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<FrontEnds::Entities::Brand, Contracts::DTO::Brand::BrandDTO>(
true, true);
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<FrontEnds::Entities::Brand, Contracts::DTO::Brand::BrandDTO>(true, true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ using namespace FrontEnds::Contracts::Repository;
using namespace FrontEnds::Contracts::CQRS::Car::Validators;
using namespace FrontEnds::Application::Features::Car::Commands;

CreateCarCommandHandler::CreateCarCommandHandler(InterfaceCarRepository *repository) : m_repository(repository)
CreateCarCommandHandler::CreateCarCommandHandler(InterfaceCarRepository *repository)
: m_repository(repository)
{
if (!s_mappingRegistered)
{
if (!s_mappingRegistered) {
registerMappings();
s_mappingRegistered = true;
}
Expand All @@ -24,12 +24,9 @@ Result<CarDTO> CreateCarCommandHandler::handle(QPromise<Result<void>> &progressP
{
Result<CarDTO> result;

try
{
try {
result = handleImpl(progressPromise, request);
}
catch (const std::exception &ex)
{
} catch (const std::exception &ex) {
result = Result<CarDTO>(QLN_ERROR_2(Q_FUNC_INFO, Error::Critical, "Unknown error", ex.what()));
qDebug() << "Error handling CreateCarCommand:" << ex.what();
}
Expand All @@ -41,27 +38,22 @@ Result<CarDTO> CreateCarCommandHandler::restore()
{
Result<CarDTO> result;

try
{
try {
result = restoreImpl();
}
catch (const std::exception &ex)
{
} catch (const std::exception &ex) {
result = Result<CarDTO>(QLN_ERROR_2(Q_FUNC_INFO, Error::Critical, "Unknown error", ex.what()));
qDebug() << "Error handling CreateCarCommand restore:" << ex.what();
}
return result;
}

Result<CarDTO> CreateCarCommandHandler::handleImpl(QPromise<Result<void>> &progressPromise,
const CreateCarCommand &request)
Result<CarDTO> CreateCarCommandHandler::handleImpl(QPromise<Result<void>> &progressPromise, const CreateCarCommand &request)
{
qDebug() << "CreateCarCommandHandler::handleImpl called";
FrontEnds::Entities::Car car;
CreateCarDTO createDTO = request.req;

if (m_firstPass)
{
if (m_firstPass) {
// Validate the create Car command using the validator
auto validator = CreateCarCommandValidator(m_repository);
Result<void> validatorResult = validator.validate(createDTO);
Expand All @@ -73,17 +65,15 @@ Result<CarDTO> CreateCarCommandHandler::handleImpl(QPromise<Result<void>> &progr
car = Qleany::Tools::AutoMapper::AutoMapper::map<CreateCarDTO, FrontEnds::Entities::Car>(createDTO);

// allow for forcing the uuid
if (car.uuid().isNull())
{
if (car.uuid().isNull()) {
car.setUuid(QUuid::createUuid());
}

// Set the creation and update timestamps to the current date and time
car.setCreationDate(QDateTime::currentDateTime());
car.setUpdateDate(QDateTime::currentDateTime());
}
else
{

} else {
car = m_newEntity.value();
}

Expand Down Expand Up @@ -119,11 +109,11 @@ Result<CarDTO> CreateCarCommandHandler::handleImpl(QPromise<Result<void>> &progr
Result<CarDTO> CreateCarCommandHandler::restoreImpl()
{
int entityId = m_newEntity.value().id();
auto deleteResult = m_repository->remove(entityId);
auto deleteResult = m_repository->remove(QList<int>() << entityId);

QLN_RETURN_IF_ERROR(CarDTO, deleteResult)

Q_EMIT carRemoved(deleteResult.value());
Q_EMIT carRemoved(deleteResult.value().value(FrontEnds::Entities::Entities::EntityEnum::Car).first());

qDebug() << "Car removed:" << deleteResult.value();

Expand All @@ -134,8 +124,6 @@ bool CreateCarCommandHandler::s_mappingRegistered = false;

void CreateCarCommandHandler::registerMappings()
{
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<FrontEnds::Entities::Car, Contracts::DTO::Car::CarDTO>(true,
true);
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<Contracts::DTO::Car::CreateCarDTO,
FrontEnds::Entities::Car>();
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<FrontEnds::Entities::Car, Contracts::DTO::Car::CarDTO>(true, true);
Qleany::Tools::AutoMapper::AutoMapper::registerMapping<Contracts::DTO::Car::CreateCarDTO, FrontEnds::Entities::Car>();
}
Loading

0 comments on commit 6bcd1ee

Please sign in to comment.