|
| 1 | +package prod.oldboy.controllers; |
| 2 | + |
| 3 | +import io.swagger.v3.oas.annotations.Operation; |
| 4 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 5 | +import lombok.RequiredArgsConstructor; |
| 6 | +import lombok.extern.slf4j.Slf4j; |
| 7 | +import org.springframework.http.ResponseEntity; |
| 8 | +import org.springframework.validation.annotation.Validated; |
| 9 | +import org.springframework.web.bind.annotation.*; |
| 10 | +import prod.oldboy.dto.amount_dto.AmountTransferDto; |
| 11 | +import prod.oldboy.service.AmountService; |
| 12 | +import prod.oldboy.validation.group.UpdateAction; |
| 13 | + |
| 14 | +@Slf4j |
| 15 | +@RestController |
| 16 | +@RequestMapping("/api/v1/users/amounts") |
| 17 | +@RequiredArgsConstructor |
| 18 | +@Tag(name = "Money transfer", description = "Method for transfer money from logged in user to another") |
| 19 | +public class AmountController { |
| 20 | + |
| 21 | + private final AmountService amountService; |
| 22 | + |
| 23 | + @PutMapping("/transfer") |
| 24 | + @Operation(summary = "Transfer money simulator", |
| 25 | + description = "Transfer from authenticated user to another user (amount format: ***.**)") |
| 26 | + public ResponseEntity<?> transferMoney(@Validated(UpdateAction.class) |
| 27 | + @RequestBody |
| 28 | + AmountTransferDto amountTransferDto) { |
| 29 | + |
| 30 | + log.info("AmountController: method transferMoney is start"); |
| 31 | + |
| 32 | + ResponseEntity<?> mayBeTransfer = amountService.transferMoney(amountTransferDto) |
| 33 | + .map(content -> ResponseEntity.ok().body(content)) |
| 34 | + .orElseGet(() -> ResponseEntity.noContent().build()); |
| 35 | + |
| 36 | + log.info("AmountController: method transferMoney is finished"); |
| 37 | + |
| 38 | + return mayBeTransfer; |
| 39 | + } |
| 40 | +} |
0 commit comments