-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose REST API for deleting an income
- Loading branch information
Showing
10 changed files
with
246 additions
and
14 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
server/src/main/java/io/myfinbox/income/IncomeDeleted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.myfinbox.income; | ||
|
||
import io.myfinbox.shared.DomainEvent; | ||
import io.myfinbox.shared.PaymentType; | ||
import lombok.Builder; | ||
|
||
import javax.money.MonetaryAmount; | ||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
import static io.myfinbox.shared.Guards.notNull; | ||
|
||
@Builder | ||
public record IncomeDeleted(UUID incomeId, | ||
UUID accountId, | ||
UUID incomeSourceId, | ||
MonetaryAmount amount, | ||
LocalDate incomeDate, | ||
PaymentType paymentType) implements DomainEvent { | ||
|
||
public IncomeDeleted { | ||
notNull(incomeId, "incomeId cannot be null."); | ||
notNull(accountId, "accountId cannot be null."); | ||
notNull(incomeSourceId, "incomeSourceId cannot be null."); | ||
notNull(amount, "amount cannot be null."); | ||
notNull(incomeDate, "incomeDate cannot be null."); | ||
notNull(paymentType, "paymentType cannot be null."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
server/src/main/java/io/myfinbox/income/application/DeleteIncomeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.myfinbox.income.application; | ||
|
||
import io.myfinbox.income.domain.Income.IncomeIdentifier; | ||
import io.myfinbox.income.domain.Incomes; | ||
import io.myfinbox.shared.Failure; | ||
import io.vavr.control.Either; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
import static java.util.Objects.isNull; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
class DeleteIncomeService implements DeleteIncomeUseCase { | ||
|
||
static final String INCOME_NOT_FOUND_MESSAGE = "Income was not found."; | ||
|
||
private final Incomes incomes; | ||
|
||
@Override | ||
public Either<Failure, Void> delete(UUID incomeId) { | ||
if (isNull(incomeId)) { | ||
return Either.left(Failure.ofNotFound(INCOME_NOT_FOUND_MESSAGE)); | ||
} | ||
|
||
var income = incomes.findById(new IncomeIdentifier(incomeId)); | ||
if (income.isEmpty()) { | ||
return Either.left(Failure.ofNotFound(INCOME_NOT_FOUND_MESSAGE)); | ||
} | ||
|
||
income.get().delete(); | ||
|
||
incomes.delete(income.get()); | ||
|
||
return Either.right(null); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
server/src/main/java/io/myfinbox/income/application/DeleteIncomeUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.myfinbox.income.application; | ||
|
||
import io.myfinbox.shared.Failure; | ||
import io.vavr.control.Either; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Interface for deleting incomes. | ||
*/ | ||
public interface DeleteIncomeUseCase { | ||
|
||
/** | ||
* Deletes an income with the provided ID. | ||
* | ||
* @param incomeId The ID of the income to be deleted. | ||
* @return {@link Either} a {@link Failure} instance if the income deletion fails, or null if the deletion is successful. | ||
*/ | ||
Either<Failure, Void> delete(UUID incomeId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.