From f7e3cfd6173edc80e8d36d6c9da4aaea1b0577f0 Mon Sep 17 00:00:00 2001
From: Dominika Zemanovicova <xzemanov@fi.muni.cz>
Date: Sun, 16 Apr 2023 06:27:28 +0200
Subject: [PATCH] Add forgotten validation

---
 .../fuseri/model/dto/user/UserCreateDto.java  |  2 +-
 .../org/fuseri/model/dto/user/UserDto.java    |  3 ++-
 .../user/UserController.java                  | 22 +++++++++----------
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/application/model/src/main/java/org/fuseri/model/dto/user/UserCreateDto.java b/application/model/src/main/java/org/fuseri/model/dto/user/UserCreateDto.java
index 936ed6c1..2336e937 100644
--- a/application/model/src/main/java/org/fuseri/model/dto/user/UserCreateDto.java
+++ b/application/model/src/main/java/org/fuseri/model/dto/user/UserCreateDto.java
@@ -40,7 +40,7 @@ public class UserCreateDto {
     @NotNull
     private UserType userType;
 
+    @NotNull
     @Valid
     private Map<LanguageTypeDto, ProficiencyLevelDto> languageProficiency;
-
 }
diff --git a/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java b/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java
index 1edaeeae..0eb2abc2 100644
--- a/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java
+++ b/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java
@@ -28,7 +28,8 @@ public class UserDto extends DomainObjectDto {
 
     @NotBlank
     private String lastName;
-
+    
+    @Valid
     private AddressDto address;
 
     @NotNull
diff --git a/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/user/UserController.java b/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/user/UserController.java
index 11d1775d..14fa089d 100644
--- a/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/user/UserController.java
+++ b/application/module-language-school/src/main/java/org/fuseri/modulelanguageschool/user/UserController.java
@@ -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) {
-- 
GitLab