Skip to content
Snippets Groups Projects

openAPI documentation for user WIP

Merged Marek Skácelík requested to merge issue-15 into milestone-1
5 files
+ 114
43
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -3,6 +3,7 @@ package cz.muni.fi.pa165.core.user;
import cz.muni.fi.pa165.model.dto.common.Result;
import cz.muni.fi.pa165.model.dto.user.UserCreateDto;
import cz.muni.fi.pa165.model.dto.user.UserDto;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -15,16 +16,12 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/user")
public class UserController {
private final UserFacade userFacade;
private final UserService service;
private final UserMapper mapper;
@Autowired
public UserController(UserService service, UserMapper mapper) {
this.service = service;
this.mapper = mapper;
}
@Autowired
public UserController(UserFacade userFacade) {
this.userFacade = userFacade;
}
@Operation(
summary = "Find user by ID",
@@ -43,9 +40,9 @@ public class UserController {
@ApiResponse(responseCode = "404", description = "User not found", content = @Content)
})
@GetMapping("/{id}")
public UserDto find(
public UserDto findById(
@Parameter(description = "ID of user to be searched") @PathVariable String id) {
return mapper.toDto(service.find(id));
return userFacade.findById(id);
}
@Operation(
@@ -70,8 +67,8 @@ public class UserController {
})
@PostMapping
public UserDto create(
@Parameter(description = "User to be created") @RequestBody UserCreateDto dto) {
return mapper.toDto(service.create(mapper.fromCreateDto(dto)));
@Parameter(description = "User to be created") @RequestBody UserCreateDto userCreateDto) {
return userFacade.create(userCreateDto);
}
@Operation(
@@ -92,29 +89,32 @@ public class UserController {
@GetMapping
public Result<UserDto> findAll(
@Parameter(description = "Page number of results to retrieve") @RequestParam int page) {
return mapper.toResult(service.findAllPageableInt(page));
return userFacade.findAll(page);
}
@Operation(
summary = "Update user",
description = "Updates an existing user",
tags = {"user"})
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "User updated",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = UserDto.class))
}),
@ApiResponse(responseCode = "400", description = "Invalid input", content = @Content),
@ApiResponse(responseCode = "404", description = "User not found", content = @Content)
})
@PutMapping
public UserDto update(
@Parameter(description = "User to be updated") @RequestBody UserCreateDto userCreateDto) {
return mapper.toDto(service.create(mapper.fromUpdateDto(userCreateDto)));
}
@PutMapping("/{id}")
@Operation(summary = "Update a user by ID")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "User updated successfully"),
@ApiResponse(responseCode = "400", description = "Invalid input"),
@ApiResponse(responseCode = "404", description = "User not found"),
@ApiResponse(responseCode = "500", description = "Internal server error")
})
public UserDto update(
@Parameter(description = "ID of the user to be updated") @PathVariable String id,
@RequestBody @Valid UserCreateDto userCreateDto) {
return userFacade.update(userCreateDto, id);
}
@DeleteMapping("/{id}")
@Operation(summary = "Delete a user by ID")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "User deleted successfully"),
@ApiResponse(responseCode = "404", description = "User not found"),
@ApiResponse(responseCode = "500", description = "Internal server error")
})
public UserDto delete(
@Parameter(description = "ID of the user to be deleted") @PathVariable String id) {
return userFacade.delete(id);
}
}
Loading