Skip to content

Commit

Permalink
Fixed (not 100% sure) TenancyController with the last 2 GetMappings a…
Browse files Browse the repository at this point in the history
…nd improved 2 methods in TenancyService
  • Loading branch information
BerPGR committed Jun 18, 2021
1 parent 2ba42b8 commit 9f693a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ public ResponseEntity<Tenancy> getRandomTenancy(){
}
}

/*
Maybe i fixed the last 2 Gets
but i'm not a 100% sure of it because
i can't access the Data Base from
my notebook, so i think when i update
the project in the computer, i can fix it
*/

//GetMapping taking client
//TODO operation get by client
@ResponseStatus(HttpStatus.NOT_FOUND)
Expand All @@ -165,6 +173,7 @@ public ResponseEntity<Tenancy> getRandomTenancy(){
@GetMapping("/client/{id}")
public ResponseEntity<List<Tenancy>> getTenancyByClient(@PathVariable("id") int id){


ResponseEntity response;
logger.info("[ GET ] => { " + endPoint + "/client }");
long start = System.currentTimeMillis();
Expand All @@ -174,7 +183,7 @@ public ResponseEntity<List<Tenancy>> getTenancyByClient(@PathVariable("id") int

Optional<Tenancy> optionalTenancy = Optional.empty();

if (clientTenancy.size() >0){
if (clientTenancy.size() > 0){
optionalTenancy = Optional.of(clientTenancy.get(id));
}
if (optionalTenancy.isPresent()){
Expand All @@ -195,8 +204,6 @@ public ResponseEntity<List<Tenancy>> getTenancyByClient(@PathVariable("id") int
}
}

//todo fix the 2 getmappings below cause they're wrong af

//GetMapping taking car
//TODO operation get by car
@ResponseStatus(HttpStatus.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public interface TenancyRepository extends PagingAndSortingRepository<Tenancy, I

Page<Tenancy> findAll (Pageable pageable);

Page<Tenancy> findById (int id, Pageable pageable );
Page<Tenancy> findById (int id, Pageable pageable);

List<Tenancy> findByClient (Client client);
List<Tenancy> findByClient (int id);

List<Tenancy> findByClient (Car car);
List<Tenancy> findByCar (int id);

Optional<Tenancy> findById (Integer integer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

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

Expand Down Expand Up @@ -53,12 +54,25 @@ public Optional<Tenancy> getTenancy(int id){
return this.tenancyRepository.findById(id);
}

//That's just a test for TenancyController
public List<Tenancy> findByClient (int id){
return this.findByClient(id);
List<Tenancy> findClientTenancies = new ArrayList<>();
for (Tenancy t : tenancyRepository.findAll()){
if(t.getClient().getId() == id) {
findClientTenancies.add(t);
}
}
return findClientTenancies;
}

public List<Tenancy> findByCar (int id){
return this.findByCar(id);
List<Tenancy> findCarTenancies = new ArrayList<>();
for(Tenancy t : tenancyRepository.findAll()){
if (t.getCar().getId() == id){
findCarTenancies.add(t);
}
}
return findCarTenancies;
}

public List<Tenancy> getAll(){
Expand Down

0 comments on commit 9f693a2

Please sign in to comment.