Skip to content
Snippets Groups Projects
Commit f7e3cfd6 authored by Dominika Zemanovičová's avatar Dominika Zemanovičová
Browse files

Add forgotten validation

parent 328d3fe2
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
......@@ -40,7 +40,7 @@ public class UserCreateDto {
@NotNull
private UserType userType;
@NotNull
@Valid
private Map<LanguageTypeDto, ProficiencyLevelDto> languageProficiency;
}
......@@ -28,7 +28,8 @@ public class UserDto extends DomainObjectDto {
@NotBlank
private String lastName;
@Valid
private AddressDto address;
@NotNull
......
......@@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import org.fuseri.model.dto.common.Result;
import org.fuseri.model.dto.course.CourseDto;
......@@ -40,7 +41,7 @@ public class UserController {
@ApiResponse(responseCode = "404", description = "User with the specified ID was not found.")
})
@GetMapping("/{id}")
public ResponseEntity<UserDto> find(@PathVariable Long id) {
public ResponseEntity<UserDto> find(@PathVariable @NotNull Long id) {
try {
return ResponseEntity.ok(facade.find(id));
} catch (EntityNotFoundException e) {
......@@ -48,7 +49,6 @@ public class UserController {
}
}
@Operation(summary = "Create a User", description = "Creates a new User.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "User created successfully."),
......@@ -65,10 +65,9 @@ public class UserController {
@ApiResponse(responseCode = "204", description = "User with the specified ID deleted successfully."),
})
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
public ResponseEntity<Void> deleteUser(@PathVariable @NotNull Long id) {
facade.delete(id);
return ResponseEntity.noContent().build();
}
@Operation(summary = "Update a User", description = "Updates a User with the specified ID.")
......@@ -78,8 +77,7 @@ public class UserController {
@ApiResponse(responseCode = "404", description = "User with the specified ID was not found.")
})
@PutMapping("/{id}")
public ResponseEntity<UserDto> update(@PositiveOrZero @PathVariable Long id, @Valid @RequestBody UserCreateDto dto) {
public ResponseEntity<UserDto> update(@NotNull @PathVariable Long id, @Valid @RequestBody UserCreateDto dto) {
try {
return ResponseEntity.ok(facade.update(id, dto));
} catch (EntityNotFoundException e) {
......@@ -99,13 +97,13 @@ public class UserController {
//TODO: add authentication M3?
@PostMapping("/login")
public ResponseEntity<String> login(@RequestBody UserLoginDto dto) {
public ResponseEntity<String> login(@RequestBody @Valid UserLoginDto dto) {
return ResponseEntity.ok(String.format("User %s has spawned", dto.getUsername()));
}
//TODO: add authentication M3?
@PostMapping("/logout/{id}")
public ResponseEntity<String> logout(@PathVariable Long id) {
@PostMapping("/{id}/logout")
public ResponseEntity<String> logout(@PathVariable @NotNull Long id) {
return ResponseEntity.ok("user has logged out");
}
......@@ -116,7 +114,7 @@ public class UserController {
@ApiResponse(responseCode = "400", description = "Invalid input")
})
@GetMapping("/{id}/finished-courses")
public ResponseEntity<List<CourseDto>> getFinished(@PathVariable Long id) {
public ResponseEntity<List<CourseDto>> getFinished(@PathVariable @NotNull Long id) {
return ResponseEntity.ok(facade.getFinished(id));
}
......@@ -126,7 +124,7 @@ public class UserController {
@ApiResponse(responseCode = "400", description = "Invalid input")
})
@GetMapping("/{id}/courses")
public ResponseEntity<List<CourseDto>> getEnrolled(@PathVariable Long id) {
public ResponseEntity<List<CourseDto>> getEnrolled(@PathVariable @NotNull Long id) {
return ResponseEntity.ok(facade.getEnrolled(id));
}
......@@ -137,7 +135,7 @@ public class UserController {
@ApiResponse(responseCode = "400", description = "Invalid input")
})
@PutMapping("/{id}/languages")
public ResponseEntity<UserDto> addLanguage(@PathVariable Long id, @Valid @RequestBody UserAddLanguageDto body) {
public ResponseEntity<UserDto> addLanguage(@PathVariable @NotNull Long id, @Valid @RequestBody UserAddLanguageDto body) {
try {
return ResponseEntity.ok(facade.addLanguage(id, body));
} catch (EntityNotFoundException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment