Compare commits

..

No commits in common. "5950dec099137143197a4a2e128117923c783489" and "a37f1c28341823f6029b8a49498fe19ec0b674a4" have entirely different histories.

5 changed files with 5 additions and 21 deletions

View file

@ -79,6 +79,7 @@ Prosty mikroserwis stworzony na potrzeby rekrutacji
"type": "string" "type": "string"
}, },
"currencies": { "currencies": {
"$comment": "TODO: Map -> List",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/def/currency" "$ref": "#/def/currency"

View file

@ -4,7 +4,6 @@ import eu.ztsh.wymiana.data.entity.CurrencyEntity;
import eu.ztsh.wymiana.data.entity.UserEntity; import eu.ztsh.wymiana.data.entity.UserEntity;
import eu.ztsh.wymiana.model.User; import eu.ztsh.wymiana.model.User;
import eu.ztsh.wymiana.web.model.UserCreateRequest; import eu.ztsh.wymiana.web.model.UserCreateRequest;
import eu.ztsh.wymiana.web.model.UserResponse;
import java.util.List; import java.util.List;
@ -20,10 +19,6 @@ public class UserMapper {
CurrencyMapper.pojoMapToEntities(pojo.currencies(), pojo.pesel())); CurrencyMapper.pojoMapToEntities(pojo.currencies(), pojo.pesel()));
} }
public static UserResponse pojoToResponse(User pojo) {
return new UserResponse(pojo.name(), pojo.surname(), pojo.pesel(), pojo.currencies().values().stream().toList());
}
public static UserEntity requestToEntity(UserCreateRequest request) { public static UserEntity requestToEntity(UserCreateRequest request) {
return new UserEntity(request.pesel(), request.name(), request.surname(), return new UserEntity(request.pesel(), request.name(), request.surname(),
List.of(new CurrencyEntity(request.pesel(), "PLN", request.initial()))); List.of(new CurrencyEntity(request.pesel(), "PLN", request.initial())));

View file

@ -2,9 +2,9 @@ package eu.ztsh.wymiana.web.controller;
import eu.ztsh.wymiana.exception.InsufficientFundsException; import eu.ztsh.wymiana.exception.InsufficientFundsException;
import eu.ztsh.wymiana.exception.UserNotFoundException; import eu.ztsh.wymiana.exception.UserNotFoundException;
import eu.ztsh.wymiana.model.User;
import eu.ztsh.wymiana.service.CurrencyService; import eu.ztsh.wymiana.service.CurrencyService;
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest; import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
import eu.ztsh.wymiana.web.model.UserResponse;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -33,8 +33,7 @@ public class ExchangeController {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "200", @ApiResponse(responseCode = "200",
description = "Exchange performed successfully", description = "Exchange performed successfully",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = User.class))),
schema = @Schema(implementation = UserResponse.class))),
@ApiResponse(responseCode = "400", @ApiResponse(responseCode = "400",
description = "Insufficient funds", description = "Insufficient funds",
content = @Content(mediaType = MediaType.TEXT_PLAIN_VALUE)), content = @Content(mediaType = MediaType.TEXT_PLAIN_VALUE)),

View file

@ -2,11 +2,10 @@ package eu.ztsh.wymiana.web.controller;
import eu.ztsh.wymiana.exception.UserAlreadyExistsException; import eu.ztsh.wymiana.exception.UserAlreadyExistsException;
import eu.ztsh.wymiana.exception.UserNotFoundException; import eu.ztsh.wymiana.exception.UserNotFoundException;
import eu.ztsh.wymiana.model.User;
import eu.ztsh.wymiana.service.UserService; import eu.ztsh.wymiana.service.UserService;
import eu.ztsh.wymiana.util.UserMapper;
import eu.ztsh.wymiana.validation.ValidationFailedException; import eu.ztsh.wymiana.validation.ValidationFailedException;
import eu.ztsh.wymiana.web.model.UserCreateRequest; import eu.ztsh.wymiana.web.model.UserCreateRequest;
import eu.ztsh.wymiana.web.model.UserResponse;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
@ -43,10 +42,9 @@ public class UserController {
@ApiResponse(responseCode = "500", description = "Another error has occurred", content = @Content) @ApiResponse(responseCode = "500", description = "Another error has occurred", content = @Content)
}) })
@GetMapping("{pesel}") @GetMapping("{pesel}")
public ResponseEntity<UserResponse> get(@PathVariable("pesel") String pesel) { public ResponseEntity<User> get(@PathVariable("pesel") String pesel) {
try { try {
return userService.get(pesel) return userService.get(pesel)
.map(UserMapper::pojoToResponse)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElseThrow(() -> new UserNotFoundException(pesel)); .orElseThrow(() -> new UserNotFoundException(pesel));
} catch (Exception e) { } catch (Exception e) {

View file

@ -1,9 +0,0 @@
package eu.ztsh.wymiana.web.model;
import eu.ztsh.wymiana.model.Currency;
import java.util.List;
public record UserResponse(String name, String surname, String pesel, List<Currency> currencies) {
}