Checkpoint: return all exchanges works

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2021-01-07 16:51:35 +01:00
parent 56120c4724
commit 842e38898a
6 changed files with 109 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package com.plannaplan.controllers;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -9,6 +10,8 @@ import com.plannaplan.entities.Exchange;
import com.plannaplan.entities.Groups;
import com.plannaplan.entities.User;
import com.plannaplan.exceptions.UserNotFoundException;
import com.plannaplan.responses.mappers.ExchangeResponseMappers;
import com.plannaplan.responses.models.ExchangeResponse;
import com.plannaplan.services.AssignmentService;
import com.plannaplan.services.ExchangeService;
import com.plannaplan.services.GroupService;
@ -19,6 +22,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -104,4 +108,18 @@ public class ExchangeController extends TokenBasedController{
this.exchangeService.deleteExchange(exchangeToDelete);
return new ResponseEntity<>("Success", HttpStatus.OK);
}
@GetMapping("/exchange/all")
@ApiOperation(value = "Get exchange offers")
public ResponseEntity<List<ExchangeResponse>> getExchange()
throws UserNotFoundException {
final User asker = this.getCurrentUser()
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
final List<Exchange> response = exchangeService.getByUserId(asker.getId());
final List<ExchangeResponse> listOfResponses = ExchangeResponseMappers.mapToDefaultResponse(response);
return new ResponseEntity<>(listOfResponses, HttpStatus.OK);
}
}