Skip to content

Commit

Permalink
Took of comment to make a GetMapping taking client
Browse files Browse the repository at this point in the history
  • Loading branch information
BerPGR committed Jun 16, 2021
1 parent cfdb6a2 commit b3c6fd0
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 31 deletions.
378 changes: 366 additions & 12 deletions logs/spring-boot-logger.log

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import br.com.locadoracarros.carrental.entities.Car;
import br.com.locadoracarros.carrental.entities.Client;
import br.com.locadoracarros.carrental.entities.Tenancy;
import br.com.locadoracarros.carrental.service.CarService;
import br.com.locadoracarros.carrental.service.ClientService;
import br.com.locadoracarros.carrental.service.TenancyService;
import com.fasterxml.jackson.databind.util.JSONPObject;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -37,7 +39,11 @@ public class TenancyController {
@Autowired
TenancyService tenancyService;

//TODO put logger on requests
@Autowired
CarService carService;

@Autowired
ClientService clientService;

// Operation GetMapping
@ApiOperation(value = "Lista todas as locações.", notes = "Lista todas as locações.",
Expand Down Expand Up @@ -242,23 +248,21 @@ public ResponseEntity<Tenancy> editTenancy(@RequestBody Tenancy tenancy, @PathVa
}
}

//TODO fix last 2 operations and loggers

//GetMapping taking car
//TODO operation get by car
/*@ResponseStatus(HttpStatus.NOT_FOUND)
/* @ResponseStatus(HttpStatus.NOT_FOUND)
@ApiOperation(value = "Obtém uma locação por carro", notes = "Obtém uma locação por carro")
@ApiResponses({
@ApiResponse(code = 204, message = "Locação por carro obtida com sucesso.")
})
@GetMapping
public ResponseEntity<Tenancy> getTenancyByCar(@RequestBody Car car, Tenancy tenancy){
@GetMapping("/car")
public ResponseEntity<Tenancy> getTenancyByCar(Car car){
logger.info("[ GET ] => { " + endPoint + " }");
ResponseEntity response;
logger.info("[ GET ] => { " + endPoint + "/car }");
long start = System.currentTimeMillis();
try{
Optional<Tenancy> optionalTenancy = this.tenancyService.getTenancy(car.getId());
ResponseEntity response;
if (optionalTenancy.isPresent()){
response = ResponseEntity.ok(optionalTenancy.get());
Expand All @@ -280,19 +284,19 @@ public ResponseEntity<Tenancy> getTenancyByCar(@RequestBody Car car, Tenancy ten

//GetMapping taking client
//TODO operation get by client
/*@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ApiOperation(value = "Obtém uma locação por cliente", notes = "Obtém uma locação por cliente")
@ApiResponses({
@ApiResponse(code = 204, message = "Locação por cliente obtida com sucesso.")
})
@GetMapping
public ResponseEntity<Tenancy> getTenancyByClient(@RequestBody Client client, Tenancy tenancy){
@GetMapping("/client")
public ResponseEntity<Tenancy> getTenancyByClient(Client client){

logger.info("[ GET ] => { " + endPoint + " }");
ResponseEntity response;
logger.info("[ GET ] => { " + endPoint + "/client }");
long start = System.currentTimeMillis();
try{
Optional<Tenancy> optionalTenancy = this.tenancyService.getTenancy(client.getId());
ResponseEntity response;

if (optionalTenancy.isPresent()){
response = ResponseEntity.ok(optionalTenancy.get());
Expand All @@ -309,5 +313,5 @@ public ResponseEntity<Tenancy> getTenancyByClient(@RequestBody Client client, Te
e.printStackTrace();
return ResponseEntity.unprocessableEntity().build();
}
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class Client {
@ApiModelProperty(notes = "Identificador único de cliente", required = true)
private int id;

@ApiModelProperty(notes = "Nome do cliente", required = true)
@ApiModelProperty(notes = "Nome do cliente")
private String name;

@ApiModelProperty(notes = "Idade do cliente", required = true)
@ApiModelProperty(notes = "Idade do cliente")
private int age;

@ApiModelProperty(notes = "Sexo do cliente", required = true)
@ApiModelProperty(notes = "Sexo do cliente")
private String gender;

//Unique in CPF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ else if (lastDate.before(new Date())){
}
this.lastDate = lastDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface CategoryRepository extends PagingAndSortingRepository<Category,

@Query(value = "SELECT * FROM category "
+ "WHERE lower(carType) like :query ", nativeQuery = true)
public Page<Category> findCategories(@Param("query") String query, Pageable pageable);
Page<Category> findCategories(@Param("query") String query, Pageable pageable);

@Query(value = "SELECT count(*) FROM category", nativeQuery = true)
int getCountCategories();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.com.locadoracarros.carrental.repository;

import br.com.locadoracarros.carrental.entities.Client;
import br.com.locadoracarros.carrental.entities.Tenancy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -9,6 +8,7 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -28,4 +28,5 @@ public interface TenancyRepository extends PagingAndSortingRepository<Tenancy, I

@Query(value = "SELECT count(*) FROM tenancy", nativeQuery = true)
int getCountTenancies();

}

0 comments on commit b3c6fd0

Please sign in to comment.