Skip to content

Inclusão do Swagger e outros endpoints #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties>
<dependencies>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tech/buildrun/picpay/PicpayApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;

@EnableFeignClients
@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "Swagger OpenApi", version = "1", description = "API de integração Rest-Client"))
public class PicpayApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package tech.buildrun.picpay.controller;

import feign.Response;
import jakarta.validation.Valid;

import java.util.List;
import java.util.UUID;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -21,9 +25,16 @@ public TransferController(TransferService transferService) {

@PostMapping("/transfer")
public ResponseEntity<Transfer> transfer(@RequestBody @Valid TransferDto dto) {
return ResponseEntity.ok(transferService.transfer(dto));
}

var resp = transferService.transfer(dto);
@GetMapping("/transfer/{uuid}")
public ResponseEntity<Transfer> getTransfer( UUID uuid) {
return ResponseEntity.ok(transferService.getTransfer(uuid));
}

return ResponseEntity.ok(resp);
@GetMapping("/transfer")
public ResponseEntity<List<Transfer>> getListTransfer() {
return ResponseEntity.ok(transferService.getListTransfer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class InsufficientBalanceException extends PicPayException{

@Override
public ProblemDetail toProblemDetail() {

var pb = ProblemDetail.forStatus(HttpStatus.UNPROCESSABLE_ENTITY);

pb.setTitle("Insufficient balance.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class TransferNotAllowedForWalletTypeException extends PicPayException {

@Override
public ProblemDetail toProblemDetail() {

var pb = ProblemDetail.forStatus(HttpStatus.UNPROCESSABLE_ENTITY);

pb.setTitle("This wallet type is not allowed to transfer.");

return pb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class TransferNotAuthorizedException extends PicPayException{

@Override
public ProblemDetail toProblemDetail() {

var pb = ProblemDetail.forStatus(HttpStatus.UNPROCESSABLE_ENTITY);

pb.setTitle("Transfer not authorized.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tech.buildrun.picpay.exception;

import java.util.UUID;

import org.springframework.http.HttpStatus;
import org.springframework.http.ProblemDetail;

public class TransferNotFoundException extends PicPayException{

private UUID uuid;

public TransferNotFoundException(UUID uuid) {
this.uuid = uuid;
}

@Override
public ProblemDetail toProblemDetail() {

var pb = ProblemDetail.forStatus(HttpStatus.UNPROCESSABLE_ENTITY);

pb.setTitle("Transfer not found");
pb.setDetail("There is no Transfer with id " + uuid + ".");

return pb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public WalletDataAlreadyExistsException(String detail) {

@Override
public ProblemDetail toProblemDetail() {

var pb = ProblemDetail.forStatus(HttpStatus.UNPROCESSABLE_ENTITY);

pb.setTitle("Wallet data already exists");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public WalletNotFoundException(Long walletId) {

@Override
public ProblemDetail toProblemDetail() {

var pb = ProblemDetail.forStatus(HttpStatus.UNPROCESSABLE_ENTITY);

pb.setTitle("Wallet not found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import org.springframework.data.jpa.repository.JpaRepository;
import tech.buildrun.picpay.entity.Transfer;

import java.util.Optional;
import java.util.UUID;

public interface TransferRepository extends JpaRepository<Transfer, UUID> {

Transfer findFirstByOrderByIdDesc();

Optional<Transfer> findById(UUID uuid);
}
12 changes: 12 additions & 0 deletions src/main/java/tech/buildrun/picpay/service/TransferService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import tech.buildrun.picpay.exception.InsufficientBalanceException;
import tech.buildrun.picpay.exception.TransferNotAllowedForWalletTypeException;
import tech.buildrun.picpay.exception.TransferNotAuthorizedException;
import tech.buildrun.picpay.exception.TransferNotFoundException;
import tech.buildrun.picpay.exception.WalletNotFoundException;
import tech.buildrun.picpay.repository.TransferRepository;
import tech.buildrun.picpay.repository.WalletRepository;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

@Service
Expand Down Expand Up @@ -72,4 +75,13 @@ private void validateTransfer(TransferDto transferDto, Wallet sender) {
}

}

public Transfer getTransfer( UUID uuid) {
return transferRepository.findById(uuid)
.orElseThrow(() -> new TransferNotFoundException(uuid));
}

public List<Transfer> getListTransfer() {
return transferRepository.findAll();
}
}
2 changes: 0 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ spring.jpa.show-sql=true

client.authorization-service.url=https://run.mocky.io/v3/94b33905-b531-44b5-900d-0bbff13cbaa0
client.notification-service.url=https://run.mocky.io/v3/0a8ce973-1f03-44f1-bfe3-21544c300ed0