Skip to content

Commit

Permalink
Refactor: project struct
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonhsporto committed Oct 11, 2024
1 parent 79634f8 commit 630575d
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.anderson.emprestimoapi.controller;
package dev.anderson.emprestimoapi.client;

import dev.anderson.emprestimoapi.dto.ClientDto;
import dev.anderson.emprestimoapi.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.service.ClientService;
import dev.anderson.emprestimoapi.common.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.common.handler.GlobalExceptionHandler;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
Expand All @@ -13,9 +12,9 @@

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/api/v1/clientes")
@RequestMapping("/clientes")
@AllArgsConstructor
public class ClientController {
public class ClientController extends GlobalExceptionHandler {

private ClientService clientService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.dto;
package dev.anderson.emprestimoapi.client;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.anderson.emprestimoapi.entities;
package dev.anderson.emprestimoapi.client;

import dev.anderson.emprestimoapi.common.entities.AddressEntity;
import dev.anderson.emprestimoapi.loan.LoanEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.anderson.emprestimoapi.mapper;
package dev.anderson.emprestimoapi.client;

import dev.anderson.emprestimoapi.dto.ClientDto;
import dev.anderson.emprestimoapi.entities.ClientEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.anderson.emprestimoapi.repositories;
package dev.anderson.emprestimoapi.client;

import dev.anderson.emprestimoapi.entities.ClientEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ClientRepository extends JpaRepository<ClientEntity, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package dev.anderson.emprestimoapi.service;

import dev.anderson.emprestimoapi.dto.ClientDto;
import dev.anderson.emprestimoapi.entities.ClientEntity;
import dev.anderson.emprestimoapi.entities.LoanEntity;
import dev.anderson.emprestimoapi.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.mapper.ClientMapper;
import dev.anderson.emprestimoapi.repositories.ClientRepository;
package dev.anderson.emprestimoapi.client;

import dev.anderson.emprestimoapi.loan.LoanEntity;
import dev.anderson.emprestimoapi.common.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.anderson.emprestimoapi.common.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggerAspect {


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.entities;
package dev.anderson.emprestimoapi.common.entities;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.exceptions;
package dev.anderson.emprestimoapi.common.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.exceptions;
package dev.anderson.emprestimoapi.common.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.exceptions;
package dev.anderson.emprestimoapi.common.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.exceptions;
package dev.anderson.emprestimoapi.common.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.anderson.emprestimoapi.exceptions.handler;
package dev.anderson.emprestimoapi.common.handler;

import dev.anderson.emprestimoapi.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.common.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.MaxLoanException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.anderson.emprestimoapi.types;
package dev.anderson.emprestimoapi.common.types;

import com.fasterxml.jackson.annotation.JsonCreator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package dev.anderson.emprestimoapi.controller;
package dev.anderson.emprestimoapi.loan;

import dev.anderson.emprestimoapi.dto.LoanDto;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.service.LoanService;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.common.handler.GlobalExceptionHandler;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
Expand All @@ -14,9 +13,9 @@

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/api/v1/clientes/{cpf}/emprestimos")
@RequestMapping("/clientes/{cpf}/emprestimos")
@AllArgsConstructor
public class LoanController {
public class LoanController extends GlobalExceptionHandler {

private LoanService loanService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.anderson.emprestimoapi.dto;
package dev.anderson.emprestimoapi.loan;

import com.fasterxml.jackson.annotation.JsonProperty;
import dev.anderson.emprestimoapi.types.Membership;
import dev.anderson.emprestimoapi.common.types.Membership;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.anderson.emprestimoapi.entities;
package dev.anderson.emprestimoapi.loan;

import dev.anderson.emprestimoapi.types.Membership;
import dev.anderson.emprestimoapi.client.ClientEntity;
import dev.anderson.emprestimoapi.common.types.Membership;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.anderson.emprestimoapi.mapper;
package dev.anderson.emprestimoapi.loan;

import dev.anderson.emprestimoapi.dto.LoanDto;
import dev.anderson.emprestimoapi.entities.LoanEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.anderson.emprestimoapi.repositories;
package dev.anderson.emprestimoapi.loan;

import dev.anderson.emprestimoapi.entities.LoanEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LoanRepository extends JpaRepository<LoanEntity, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package dev.anderson.emprestimoapi.service;

import dev.anderson.emprestimoapi.dto.LoanDto;
import dev.anderson.emprestimoapi.entities.ClientEntity;
import dev.anderson.emprestimoapi.entities.LoanEntity;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.mapper.LoanMapper;
import dev.anderson.emprestimoapi.repositories.ClientRepository;
import dev.anderson.emprestimoapi.repositories.LoanRepository;
package dev.anderson.emprestimoapi.loan;

import dev.anderson.emprestimoapi.client.ClientEntity;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.client.ClientRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

server.servlet.context-path: /api/v1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.anderson.emprestimoapi;

import dev.anderson.emprestimoapi.controller.ClientController;
import dev.anderson.emprestimoapi.controller.LoanController;
import dev.anderson.emprestimoapi.client.ClientController;
import dev.anderson.emprestimoapi.loan.LoanController;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.anderson.emprestimoapi.service;

import dev.anderson.emprestimoapi.dto.ClientDto;
import dev.anderson.emprestimoapi.entities.ClientEntity;
import dev.anderson.emprestimoapi.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.mapper.ClientMapper;
import dev.anderson.emprestimoapi.repositories.ClientRepository;
import dev.anderson.emprestimoapi.client.ClientService;
import dev.anderson.emprestimoapi.client.ClientDto;
import dev.anderson.emprestimoapi.client.ClientEntity;
import dev.anderson.emprestimoapi.common.exceptions.ClientDuplicatedException;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.client.ClientMapper;
import dev.anderson.emprestimoapi.client.ClientRepository;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package dev.anderson.emprestimoapi.service;

import dev.anderson.emprestimoapi.dto.ClientDto;
import dev.anderson.emprestimoapi.dto.LoanDto;
import dev.anderson.emprestimoapi.entities.ClientEntity;
import dev.anderson.emprestimoapi.entities.LoanEntity;
import dev.anderson.emprestimoapi.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.mapper.ClientMapper;
import dev.anderson.emprestimoapi.mapper.LoanMapper;
import dev.anderson.emprestimoapi.repositories.ClientRepository;
import dev.anderson.emprestimoapi.repositories.LoanRepository;
import dev.anderson.emprestimoapi.types.Membership;
import dev.anderson.emprestimoapi.client.ClientDto;
import dev.anderson.emprestimoapi.loan.*;
import dev.anderson.emprestimoapi.client.ClientEntity;
import dev.anderson.emprestimoapi.common.exceptions.ClientNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.LoanNotFoundException;
import dev.anderson.emprestimoapi.common.exceptions.MaxLoanException;
import dev.anderson.emprestimoapi.client.ClientMapper;
import dev.anderson.emprestimoapi.client.ClientRepository;
import dev.anderson.emprestimoapi.common.types.Membership;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -104,7 +101,7 @@ void makeLoanOfClientThatDoesExist() throws Exception {

@Test
@DisplayName("Create a loan of a client that does exist but is not eligible for loan")
void makeLoanOfClientNotEligibleForLoan() throws Exception {
void makeLoanOfClientNotEligibleForLoan() {
ClientDto clientDto = new ClientDto();
clientDto.setCpf("12345678901");
clientDto.setName("Bilbo Baggins");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.anderson.emprestimoapi.types;

import dev.anderson.emprestimoapi.common.types.Membership;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down

0 comments on commit 630575d

Please sign in to comment.