Checkpoint: return per ID works
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
842e38898a
commit
e24938dfce
@ -122,4 +122,26 @@ public class ExchangeController extends TokenBasedController{
|
|||||||
|
|
||||||
return new ResponseEntity<>(listOfResponses, HttpStatus.OK);
|
return new ResponseEntity<>(listOfResponses, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/exchange/{id}")
|
||||||
|
@ApiOperation(value = "Get exchange offers")
|
||||||
|
public ResponseEntity<ExchangeResponse> getExchangeById(@PathVariable(name = "id", required = false) Long offerId)
|
||||||
|
throws UserNotFoundException {
|
||||||
|
|
||||||
|
final User asker = this.getCurrentUser()
|
||||||
|
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||||
|
|
||||||
|
final Optional<Exchange> exchange = this.exchangeService.getById(offerId);
|
||||||
|
|
||||||
|
if(exchange.isEmpty()){
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Exchange exchangeInstance = exchange.get();
|
||||||
|
if(!exchangeInstance.getOwnerId().equals(asker.getId())){
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(new ExchangeResponse(exchangeInstance), HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user