Checkpoint: return per ID works

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-07 17:02:12 +01:00
parent 842e38898a
commit e24938dfce
Signed by: y0rune
GPG Key ID: F204C385F57EB348
1 changed files with 22 additions and 0 deletions

View File

@ -122,4 +122,26 @@ public class ExchangeController extends TokenBasedController{
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);
}
}