diff --git a/openapi.yaml b/openapi.yaml index f7e91a7..9e607fb 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -53,17 +53,18 @@ paths: profile. operationId: setProfilePicture parameters: - - name: base64ProfilePicture - in: query - required: true - schema: - type: string - name: id in: path required: true schema: type: integer format: int64 + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ImageRequestDTO" + required: true responses: "200": description: Profile picture successfully added/updated @@ -793,19 +794,19 @@ paths: content: '*/*': schema: - type: string + $ref: "#/components/schemas/ImageRequestDTO" "403": description: Only authorized persons may see the profiles picture content: '*/*': schema: - type: string + $ref: "#/components/schemas/ImageRequestDTO" "404": description: The user does not exist content: '*/*': schema: - type: string + $ref: "#/components/schemas/ImageRequestDTO" /trip/getAllUserTrips: get: tags: @@ -835,6 +836,18 @@ paths: '*/*': schema: $ref: "#/components/schemas/RoutingPreferencesDTO" + /routing/alternative/carrousel/request: + get: + tags: + - routing-alternative-carrousel-controller + operationId: getAlternativeCarrousel + responses: + "200": + description: OK + content: + '*/*': + schema: + $ref: "#/components/schemas/AlternativeCarrouselDTO" /leaderboard/getLeaderboard: get: tags: @@ -1401,6 +1414,11 @@ paths: description: Badge not found components: schemas: + ImageRequestDTO: + type: object + properties: + base64ProfilePicture: + type: string LoginResponseDTO: type: object properties: @@ -1714,7 +1732,9 @@ components: type: array description: The steps the route consists of. items: - $ref: "#/components/schemas/StepDTO" + oneOf: + - $ref: "#/components/schemas/StepDTO" + - $ref: "#/components/schemas/TransitStepDTO" co2Savings: type: number format: double @@ -1730,18 +1750,20 @@ components: description: The temporal difference in minutes compared to the original route (in case alternative was requested) / the car route (when simply directions requested) . - durationSeconds: - type: integer - format: int64 cyclingRoute: type: boolean walkingRoute: type: boolean + durationSeconds: + type: integer + format: int64 physicalActivity: type: boolean StepDTO: type: object description: A single step within a suggested alternative route. + discriminator: + propertyName: type properties: modality: type: string @@ -1759,6 +1781,24 @@ components: distanceMeters: type: number format: double + type: + type: string + required: + - type + TransitStepDTO: + allOf: + - $ref: "#/components/schemas/StepDTO" + - type: object + properties: + lineNumber: + type: string + lineHeadsign: + type: string + startStop: + type: string + endStop: + type: string + description: A single transit step within a suggested alternative route. RoutingAlternativeRequestDTO: type: object description: This DTO represents a request for alternative routes between an @@ -1984,9 +2024,6 @@ components: Stats: type: object properties: - xp: - type: integer - format: int64 co2_SAVED: type: integer format: int64 @@ -1999,6 +2036,9 @@ components: km_DRIVEN: type: integer format: int64 + xp: + type: integer + format: int64 km_PUBLIC_TRANSPORT: type: integer format: int64 @@ -2260,6 +2300,24 @@ components: distanceMeters: type: number format: float + AlternativeCarrouselDTO: + type: object + properties: + alternatives: + type: array + items: + $ref: "#/components/schemas/RouteAlternativeContext" + RouteAlternativeContext: + type: object + description: Wrapper for alternative routes in the carousel. + properties: + carrouselCandidateType: + type: string + enum: + - ADHOC_ALTERNATIVE + - REGULAR_TRIP_ALTERNATIVE + alternative: + $ref: "#/components/schemas/RouteDTO" Leaderboard: type: object properties: diff --git a/src/main/java/SuMoC/backend/images/ImageRequestDTO.java b/src/main/java/SuMoC/backend/images/ImageRequestDTO.java new file mode 100644 index 0000000..8059e7c --- /dev/null +++ b/src/main/java/SuMoC/backend/images/ImageRequestDTO.java @@ -0,0 +1,21 @@ +package SuMoC.backend.images; + +public class ImageRequestDTO { + + private String base64ProfilePicture; + + public ImageRequestDTO(String base64ProfilePicture) { + this.base64ProfilePicture = base64ProfilePicture; + } + + public ImageRequestDTO() {} + + public String getBase64ProfilePicture() { + return base64ProfilePicture; + } + + public void setBase64ProfilePicture(String base64ProfilePicture) { + this.base64ProfilePicture = base64ProfilePicture; + } + +} diff --git a/src/main/java/SuMoC/backend/user/controller/UserController.java b/src/main/java/SuMoC/backend/user/controller/UserController.java index 31e1382..6c08114 100644 --- a/src/main/java/SuMoC/backend/user/controller/UserController.java +++ b/src/main/java/SuMoC/backend/user/controller/UserController.java @@ -1,5 +1,6 @@ package SuMoC.backend.user.controller; +import SuMoC.backend.images.ImageRequestDTO; import SuMoC.backend.security.dtos.LoginResponseDTO; import SuMoC.backend.user.dtos.*; import SuMoC.backend.user.enums.VisibilityPrivacy; @@ -214,9 +215,9 @@ public class UserController { content = @Content(mediaType = "application/json")) }) @PutMapping("/setProfilePicture/{id}") - public ResponseEntity setProfilePicture(@RequestBody String base64ProfilePicture, + public ResponseEntity setProfilePicture(@RequestBody ImageRequestDTO base64ProfilePicture, @PathVariable @NotNull Long id) { - this.userService.setProfilePicture(id, base64ProfilePicture); + this.userService.setProfilePicture(id, base64ProfilePicture.getBase64ProfilePicture()); return ResponseEntity.ok().build(); } @@ -229,8 +230,8 @@ public class UserController { @ApiResponse(responseCode = "404", description = "The user does not exist") }) @GetMapping("/getProfilePicture/{id}") - public ResponseEntity getProfilePicture(@PathVariable @NotNull Long id) { - String imageData = userService.getProfilePicture(id); + public ResponseEntity getProfilePicture(@PathVariable @NotNull Long id) { + ImageRequestDTO imageData = userService.getProfilePicture(id); return ResponseEntity.ok() .contentType(MediaType.IMAGE_JPEG) diff --git a/src/main/java/SuMoC/backend/user/service/UserService.java b/src/main/java/SuMoC/backend/user/service/UserService.java index ddb90dd..0d993c3 100644 --- a/src/main/java/SuMoC/backend/user/service/UserService.java +++ b/src/main/java/SuMoC/backend/user/service/UserService.java @@ -2,6 +2,7 @@ package SuMoC.backend.user.service; import SuMoC.backend.gamification.Timeframe; import SuMoC.backend.images.ImageBase64Util; +import SuMoC.backend.images.ImageRequestDTO; import SuMoC.backend.security.dtos.LoginResponseDTO; import SuMoC.backend.security.services.TokenService; import SuMoC.backend.trip.TripMapper; @@ -218,14 +219,6 @@ public class UserService { HttpStatus.NOT_FOUND, "Der Nutzer Existitert nicht.")); try { - - if (base64ProfilePicture.trim().startsWith("{")) { - base64ProfilePicture = base64ProfilePicture - .replaceAll("\\s", "") - .replaceAll(".*\"base64ProfilePicture\":\"", "") - .replaceAll("\".*", ""); - } - if (userToChange.getProfileImage() == null) { ProfileImageEntity profileImage = new ProfileImageEntity(); profileImage.setUser(userToChange); @@ -242,7 +235,7 @@ public class UserService { } - public String getProfilePicture(Long id) { + public ImageRequestDTO getProfilePicture(Long id) { User sender = currentUser.get(); User user = userRepository.findById(id) .orElseThrow(() -> new ResponseStatusException( @@ -258,7 +251,7 @@ public class UserService { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Kein Profilbild vorhanden."); } - return ImageBase64Util.encode(user.getProfileImage().getImageData()); + return new ImageRequestDTO(ImageBase64Util.encode(user.getProfileImage().getImageData())); } public Long getTotalXP() { @@ -266,3 +259,4 @@ public class UserService { return sender.getStats().getStatValue(Timeframe.TOTAL,"XP"); } } + diff --git a/src/test/java/SuMoC/backend/user/service/UserServiceTest.java b/src/test/java/SuMoC/backend/user/service/UserServiceTest.java index 9d977a1..06a5115 100644 --- a/src/test/java/SuMoC/backend/user/service/UserServiceTest.java +++ b/src/test/java/SuMoC/backend/user/service/UserServiceTest.java @@ -196,7 +196,7 @@ public class UserServiceTest { userService.setProfilePicture(sender.getId(), base64Image); // Get profile picture - String profilePicture = userService.getProfilePicture(sender.getId()); + String profilePicture = userService.getProfilePicture(sender.getId()).getBase64ProfilePicture(); assertNotNull(profilePicture); assertEquals(base64Image.getBytes().length, profilePicture.length()); assertEquals(base64Image, profilePicture); @@ -214,7 +214,7 @@ public class UserServiceTest { userRepository.save(anotherUser); byte[] secondImage = new byte[]{10,20,30,40,50}; anotherUser.getProfileImage().setImageData(secondImage); - byte[] profilePicture2 = ImageBase64Util.decode(userService.getProfilePicture(anotherUser.getId())); + byte[] profilePicture2 = ImageBase64Util.decode(userService.getProfilePicture(anotherUser.getId()).getBase64ProfilePicture()); assertNotNull(profilePicture2); assertEquals(secondImage.length, profilePicture2.length); assertArrayEquals(secondImage, profilePicture2);