Skip to content

Commit

Permalink
Merge branch 'main' into contracts-commands-cache-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kemosalamy committed May 9, 2024
2 parents 2b81ea6 + 1460819 commit 933ebad
Show file tree
Hide file tree
Showing 125 changed files with 3,066 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ build/

### VS Code ###
.vscode/

### Logs ###
logs/
74 changes: 47 additions & 27 deletions services/payments/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<relativePath /> <!-- lookup parent from repository -->
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.workup</groupId>
<artifactId>payments</artifactId>
Expand All @@ -18,64 +18,96 @@
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.workup</groupId>
<artifactId>shared</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>


<!-- Message queue dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>com.workup</groupId>
<artifactId>shared</artifactId>
<version>${project.version}</version>
</dependency>


<!-- Database dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>


<!-- Logging dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>


<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
Expand All @@ -89,18 +121,6 @@
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.redis.testcontainers</groupId>
<artifactId>testcontainers-redis-junit-jupiter</artifactId>
<version>1.4.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
23 changes: 23 additions & 0 deletions services/payments/src/main/java/com/workup/payments/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.workup.payments;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;

public class Test {
private static final Logger logger = LogManager.getLogger(Test.class);

public static void main(String[] args) {
// You can also set the root logger:
Configurator.setRootLevel(Level.ERROR);

logger.trace("Trace level log message: This shows more detailed information");
logger.debug("Debug level log message: This shows more detailed information");
logger.info("Info level log message: Greeting endpoint was called");
logger.warn("Warn level log message: Greeting endpoint was called");
logger.error("Error level log message: This shows more detailed information");

System.out.println("Hello");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest;
import com.workup.shared.commands.payments.paymentrequest.responses.CreatePaymentRequestResponse;
import com.workup.shared.enums.HttpStatusCode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class CreatePaymentRequestCommand
extends PaymentCommand<CreatePaymentRequestRequest, CreatePaymentRequestResponse> {
private static final Logger logger = LogManager.getLogger(CreatePaymentRequestCommand.class);

@Override
public CreatePaymentRequestResponse Run(CreatePaymentRequestRequest request) {
Expand All @@ -21,14 +24,14 @@ public CreatePaymentRequestResponse Run(CreatePaymentRequestRequest request) {
try {
PaymentRequest savedPaymentRequest = getPaymentRequestRepository().save(paymentRequest);

System.out.println("[x] Payment request created : " + savedPaymentRequest);
logger.info("[x] Payment request created : " + savedPaymentRequest);

return CreatePaymentRequestResponse.builder()
.withStatusCode(HttpStatusCode.CREATED)
.withPaymentRequestId(savedPaymentRequest.getId())
.build();
} catch (Exception e) {
System.out.println("[x] Payment request creation failed : " + e.getMessage());
logger.error("[x] Payment request creation failed : " + e.getMessage());

return CreatePaymentRequestResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import com.workup.shared.commands.payments.paymentrequest.responses.GetClientPaymentRequestsResponse;
import com.workup.shared.enums.HttpStatusCode;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetClientPaymentRequestsCommand
extends PaymentCommand<GetClientPaymentRequestsRequest, GetClientPaymentRequestsResponse> {
private static final Logger logger = LogManager.getLogger(GetClientPaymentRequestsCommand.class);

@Override
public GetClientPaymentRequestsResponse Run(GetClientPaymentRequestsRequest request) {
Expand All @@ -20,7 +23,7 @@ public GetClientPaymentRequestsResponse Run(GetClientPaymentRequestsRequest requ
List<PaymentRequestDTO> paymentRequestDTOS =
PaymentRequestMapper.mapToPaymentRequestDTOs(savedRequests);

System.out.println("[x] Payment requests fetched : " + paymentRequestDTOS);
logger.info("[x] Payment requests fetched : " + paymentRequestDTOS);

return GetClientPaymentRequestsResponse.builder()
.withStatusCode(HttpStatusCode.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import com.workup.shared.commands.payments.paymentrequest.responses.GetFreelancerPaymentRequestsResponse;
import com.workup.shared.enums.HttpStatusCode;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerPaymentRequestsCommand
extends PaymentCommand<
GetFreelancerPaymentRequestsRequest, GetFreelancerPaymentRequestsResponse> {
private static final Logger logger =
LogManager.getLogger(GetFreelancerPaymentRequestsCommand.class);

@Override
public GetFreelancerPaymentRequestsResponse Run(GetFreelancerPaymentRequestsRequest request) {
Expand All @@ -21,7 +25,7 @@ public GetFreelancerPaymentRequestsResponse Run(GetFreelancerPaymentRequestsRequ
List<PaymentRequestDTO> paymentRequestDTOS =
PaymentRequestMapper.mapToPaymentRequestDTOs(savedRequests);

System.out.println("[x] Payment requests fetched : " + paymentRequestDTOS);
logger.info("[x] Payment requests fetched : " + paymentRequestDTOS);

return GetFreelancerPaymentRequestsResponse.builder()
.withStatusCode(HttpStatusCode.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import com.workup.shared.enums.HttpStatusCode;
import com.workup.shared.redis.RedisService;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetPaymentRequestCommand
extends PaymentCommand<GetPaymentRequestRequest, GetPaymentRequestResponse> {
private static final Logger logger = LogManager.getLogger(GetPaymentRequestCommand.class);

@Override
public GetPaymentRequestResponse Run(GetPaymentRequestRequest request) {
Expand All @@ -21,7 +24,7 @@ public GetPaymentRequestResponse Run(GetPaymentRequestRequest request) {
(GetPaymentRequestResponse)
redisService.getValue(request.getPaymentRequestId(), GetPaymentRequestResponse.class);
if (cachedResponse != null) {
System.out.println(
logger.info(
"[x] Payment request response fetched from cache : " + cachedResponse.getRequest());

return cachedResponse;
Expand All @@ -38,7 +41,7 @@ public GetPaymentRequestResponse Run(GetPaymentRequestRequest request) {
.build();
}

System.out.println("[x] Payment request fetched : " + savedPaymentRequest.get());
logger.info("[x] Payment request fetched : " + savedPaymentRequest.get());

PaymentRequestDTO paymentRequestDTO =
PaymentRequestMapper.mapToPaymentRequestDTO(savedPaymentRequest.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import com.workup.shared.enums.payments.PaymentTransactionStatus;
import com.workup.shared.enums.payments.WalletTransactionType;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

public class PayPaymentRequestCommand
extends PaymentCommand<PayPaymentRequestRequest, PayPaymentRequestResponse> {
private static final Logger logger = LogManager.getLogger(PayPaymentRequestCommand.class);

@Override
@Transactional
Expand Down Expand Up @@ -43,8 +46,8 @@ public PayPaymentRequestResponse Run(PayPaymentRequestRequest request) {
paymentRequest.get().setStatus(PaymentRequestStatus.PAID);
PaymentRequest savedPaymentRequest = getPaymentRequestRepository().save(paymentRequest.get());

System.out.println("[x] Payment request paid : " + savedPaymentRequest);
System.out.println("[x] Payment transaction saved : " + savedPaymentTransaction);
logger.info("[x] Payment request paid : " + savedPaymentRequest);
logger.info("[x] Payment transaction saved : " + savedPaymentTransaction);

Optional<Wallet> freelancerWallet =
getWalletRepository().findById(paymentRequest.get().getFreelancerId());
Expand All @@ -56,7 +59,7 @@ public PayPaymentRequestResponse Run(PayPaymentRequestRequest request) {
.setBalance(freelancerWallet.get().getBalance() + paymentRequest.get().getAmount());
Wallet savedWallet = getWalletRepository().save(freelancerWallet.get());

System.out.println("[x] Wallet updated : " + savedWallet);
logger.info("[x] Wallet updated : " + savedWallet);

WalletTransaction walletTransaction =
WalletTransaction.builder()
Expand All @@ -69,14 +72,14 @@ public PayPaymentRequestResponse Run(PayPaymentRequestRequest request) {
WalletTransaction savedWalletTransaction =
getWalletTransactionRepository().save(walletTransaction);

System.out.println("[x] Wallet transaction saved : " + savedWalletTransaction);
logger.info("[x] Wallet transaction saved : " + savedWalletTransaction);
return PayPaymentRequestResponse.builder()
.withStatusCode(HttpStatusCode.OK)
.withTransactionId(savedPaymentTransaction.getId())
.withTransactionStatus(PaymentTransactionStatus.SUCCESS)
.build();
} catch (Exception e) {
System.out.println("[x] Payment request failed : " + e.getMessage());
logger.error("[x] Payment request failed : " + e.getMessage());
// TODO: Handle payment transaction failure (Retry mechanism ?)
return PayPaymentRequestResponse.builder()
.withStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import com.workup.shared.commands.payments.paymenttransaction.responses.GetClientPaymentTransactionsResponse;
import com.workup.shared.enums.HttpStatusCode;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetClientPaymentTransactionsCommand
extends PaymentCommand<
GetClientPaymentTransactionsRequest, GetClientPaymentTransactionsResponse> {
private static final Logger logger =
LogManager.getLogger(GetClientPaymentTransactionsCommand.class);

@Override
public GetClientPaymentTransactionsResponse Run(GetClientPaymentTransactionsRequest request) {
Expand All @@ -20,7 +24,7 @@ public GetClientPaymentTransactionsResponse Run(GetClientPaymentTransactionsRequ
List<PaymentTransactionDTO> paymentTransactionDTOS =
PaymentTransactionMapper.mapToPaymentTransactionDTOs(savedTransactions);

System.out.println("[x] Payment transactions fetched : " + paymentTransactionDTOS);
logger.info("[x] Payment transactions fetched : " + paymentTransactionDTOS);

return GetClientPaymentTransactionsResponse.builder()
.withStatusCode(HttpStatusCode.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import com.workup.shared.commands.payments.paymenttransaction.responses.GetFreelancerPaymentTransactionsResponse;
import com.workup.shared.enums.HttpStatusCode;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GetFreelancerPaymentTransactionsCommand
extends PaymentCommand<
GetFreelancerPaymentTransactionsRequest, GetFreelancerPaymentTransactionsResponse> {
private static final Logger logger =
LogManager.getLogger(GetFreelancerPaymentTransactionsCommand.class);

@Override
public GetFreelancerPaymentTransactionsResponse Run(
Expand All @@ -21,7 +25,7 @@ public GetFreelancerPaymentTransactionsResponse Run(
List<PaymentTransactionDTO> paymentTransactionDTOS =
PaymentTransactionMapper.mapToPaymentTransactionDTOs(savedTransactions);

System.out.println("[x] Payment transactions fetched : " + paymentTransactionDTOS);
logger.info("[x] Payment transactions fetched : " + paymentTransactionDTOS);

return GetFreelancerPaymentTransactionsResponse.builder()
.withStatusCode(HttpStatusCode.OK)
Expand Down
Loading

0 comments on commit 933ebad

Please sign in to comment.