diff --git a/openapi.yaml b/openapi.yaml index 9381955..f7e91a7 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -44,6 +44,43 @@ paths: description: Ungültige Eingabedaten content: application/json: {} + /user/setProfilePicture/{id}: + put: + tags: + - user-controller + summary: Add a profile Picture to the user. + description: A user can add or update a profile picture to be displayed on his + profile. + operationId: setProfilePicture + parameters: + - name: base64ProfilePicture + in: query + required: true + schema: + type: string + - name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Profile picture successfully added/updated + content: + application/json: {} + "400": + description: Invalid input data + content: + application/json: {} + "403": + description: Only authorized persons may add/update the profile picture + content: + application/json: {} + "404": + description: The user does not exist + content: + application/json: {} /user/setPrivateName/{id}: put: tags: @@ -227,6 +264,73 @@ paths: responses: "200": description: OK + /challenges/modifyChallenge: + put: + tags: + - challenge-controller + summary: Modify a challenge by ID + operationId: modifyChallengeById + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ChallengeDTO" + required: true + responses: + "200": + description: Challenge modified successfully + content: + application/json: + schema: + $ref: "#/components/schemas/ChallengeDTO" + "404": + description: Challenge not found + content: + '*/*': + schema: + $ref: "#/components/schemas/ChallengeDTO" + "400": + description: Invalid input data + content: + '*/*': + schema: + $ref: "#/components/schemas/ChallengeDTO" + /challenges/deactivateChallenge/{challengeId}: + put: + tags: + - challenge-controller + summary: Deactivate a challenge by ID + operationId: deactivateChallengeById + parameters: + - name: challengeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Challenge deactivated successfully + "404": + description: Challenge not found + /challenges/activateChallenge/{challengeId}: + put: + tags: + - challenge-controller + summary: Activate a challenge by ID + operationId: activateChallengeById + parameters: + - name: challengeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Challenge activated successfully + "404": + description: Challenge not found /badges/modifyBadge: put: tags: @@ -237,27 +341,27 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" required: true responses: "200": description: Badge modified successfully content: - '*/*': + application/json: schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" "404": description: Badge not found content: '*/*': schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" "400": description: Invalid input data content: '*/*': schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" /user/stats/add: post: tags: @@ -298,10 +402,35 @@ paths: responses: "200": description: OK + content: + '*/*': + schema: + type: integer + format: int64 + /routing/directions/request: + post: + tags: + - routing-directions-controller + operationId: requestDirections + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/RoutingDirectionsRequestDTO" + required: true + responses: + "200": + description: OK + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/RouteDTO" /routing/alternative/request: post: tags: - - routing-controller + - routing-alternative-controller operationId: requestAlternativeRoutes requestBody: content: @@ -430,6 +559,39 @@ paths: responses: "200": description: OK + /dev/test-detection-and-notification-regular-trips: + post: + tags: + - dev-controller + operationId: testDetectionAndNotificationOfRegularTrips + responses: + "200": + description: OK + /challenges/createChallenge: + post: + tags: + - challenge-controller + summary: Create a new challenge + operationId: createChallenge + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ChallengeDTO" + required: true + responses: + "201": + description: Challenge created successfully + content: + application/json: + schema: + $ref: "#/components/schemas/ChallengeDTO" + "400": + description: Invalid input data + content: + '*/*': + schema: + $ref: "#/components/schemas/ChallengeDTO" /badges/createBadge: post: tags: @@ -440,27 +602,27 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" required: true responses: "201": description: Badge created successfully content: - '*/*': + application/json: schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" "400": description: Invalid input data content: '*/*': schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" "409": description: Badge already exists content: '*/*': schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" /badges/checkBadgeAndAward: post: tags: @@ -518,6 +680,22 @@ paths: description: Ungültiger Benutzername oder Passwort content: application/json: {} + /user/stats: + get: + tags: + - user-controller + summary: get stats of current user + description: Returns all stats of a user + operationId: getStats + responses: + "200": + description: Stats were found + content: + application/json: {} + "403": + description: Not authorized + content: + application/json: {} /user/profile: get: tags: @@ -533,6 +711,10 @@ paths: application/json: schema: $ref: "#/components/schemas/MaximalUserDTO" + "304": + description: Nutzerprofil wurde seit dem letzten Abruf nicht verändert + content: + application/json: {} "404": description: Der Nutzer existiert nicht content: @@ -567,6 +749,63 @@ paths: description: Nutzerprofil nicht gefunden content: application/json: {} + /user/getTotalXP: + get: + tags: + - user-controller + summary: Get the users own xp + description: A user can get their own xp. + operationId: getTotalXP + responses: + "200": + description: XP successfully retrieved + content: + application/json: {} + "403": + description: Not authorized + content: + application/json: {} + "404": + description: The user does not exist + content: + application/json: {} + /user/getProfilePicture/{id}: + get: + tags: + - user-controller + summary: Get the profile Picture of the user. + description: A user can get their displayed profile picture. + operationId: getProfilePicture + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Profile picture successfully retrieved + content: + application/json: {} + "304": + description: Profile picture not modified since last request + content: + '*/*': + schema: + type: string + "403": + description: Only authorized persons may see the profiles picture + content: + '*/*': + schema: + type: string + "404": + description: The user does not exist + content: + '*/*': + schema: + type: string /trip/getAllUserTrips: get: tags: @@ -620,6 +859,12 @@ paths: responses: "200": description: Successfully retrieved global score table + content: + application/json: + schema: + $ref: "#/components/schemas/Leaderboard" + "304": + description: Not modified content: '*/*': schema: @@ -654,6 +899,12 @@ paths: responses: "200": description: Successfully retrieved friend score table + content: + application/json: + schema: + $ref: "#/components/schemas/Leaderboard" + "304": + description: Not modified content: '*/*': schema: @@ -810,6 +1061,26 @@ paths: '*/*': schema: type: string + /dev/test-firebase-friendship-request-notification/{fcm_token}: + get: + tags: + - dev-controller + description: Immediately sends a test notification of type FRIENDSHIP_REQUEST_RECEIVED + to the provided FCM token. + operationId: SendTestRFriendshipRequestReceivedNotificationFirebase + parameters: + - name: fcm_token + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + '*/*': + schema: + type: string /dev/test-firebase-adhoc-route-notification/{fcm_token}: get: tags: @@ -853,6 +1124,100 @@ paths: '*/*': schema: type: string + /challenges/getChallenge/{challengeId}: + get: + tags: + - challenge-controller + summary: Get a challenge by ID + operationId: getChallengeById + parameters: + - name: challengeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Challenge retrieved successfully + content: + application/json: + schema: + $ref: "#/components/schemas/ChallengeDTO" + "304": + description: Not modified since last request + content: + '*/*': + schema: + $ref: "#/components/schemas/ChallengeDTO" + "404": + description: Challenge not found + content: + '*/*': + schema: + $ref: "#/components/schemas/ChallengeDTO" + /challenges/getAvailableChallenges: + get: + tags: + - challenge-controller + summary: Get all available challenges + operationId: getAvailableChallenges + responses: + "200": + description: Available challenges retrieved successfully + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/ChallengeDTO" + "304": + description: Not modified since last request + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/ChallengeDTO" + "404": + description: No available challenges found + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/ChallengeDTO" + /challenges/getAllChallenges: + get: + tags: + - challenge-controller + summary: Get all challenges + operationId: getAllChallenges + responses: + "200": + description: Challenges retrieved successfully + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/ChallengeDTO" + "304": + description: Not modified since last request + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/ChallengeDTO" + "404": + description: No challenges found + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/ChallengeDTO" /badges/getBadges/{userId}: get: tags: @@ -899,16 +1264,22 @@ paths: responses: "200": description: Badge retrieved successfully + content: + application/json: + schema: + $ref: "#/components/schemas/BadgeDTO" + "304": + description: Not modified since last request content: '*/*': schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" "404": description: Badge not found content: '*/*': schema: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" /badges/getAllBadges: get: tags: @@ -918,12 +1289,20 @@ paths: responses: "200": description: Badges retrieved successfully + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/BadgeDTO" + "304": + description: Not modified since last request content: '*/*': schema: type: array items: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" "404": description: No badges found content: @@ -931,7 +1310,7 @@ paths: schema: type: array items: - $ref: "#/components/schemas/Badge" + $ref: "#/components/schemas/BadgeDTO" /user/delete/{id}: delete: tags: @@ -984,6 +1363,24 @@ paths: responses: "200": description: OK + /challenges/deleteChallenge/{challengeId}: + delete: + tags: + - challenge-controller + summary: Delete a challenge by ID + operationId: deleteChallengeById + parameters: + - name: challengeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: Challenge deleted successfully + "404": + description: Challenge not found /badges/deleteBadge/{badgeId}: delete: tags: @@ -1029,6 +1426,8 @@ components: - USER - ADMIN uniqueItems: true + friendCode: + type: string id: type: integer format: int64 @@ -1039,8 +1438,12 @@ components: properties: preferPhysicalActivity: type: boolean + description: "Whether to prefer alternative routes that involve physical\ + \ activity (walking, cycling) when suggestin alternative routes." considerWeatherConditions: type: boolean + description: Whether to consider current weather conditions when suggesting + alternative routes. modalitiesToConsider: type: array items: @@ -1065,7 +1468,7 @@ components: type: string enum: - FIREBASE - Badge: + ChallengeDTO: type: object properties: id: @@ -1075,11 +1478,50 @@ components: type: string description: type: string + base64image: + type: string criteria: type: object additionalProperties: type: integer format: int32 + reward: + type: integer + format: int32 + BadgeDTO: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + description: + type: string + category: + type: string + enum: + - XP + - MOBILITY_SCORE + - CO2 + - IDLE + - WALKING + - BICYCLE + - ESCOOTER + - BUS + - TRAM + - TRAIN + - CAR + - OPNV + - MONTHLY + - HIDDEN + criteria: + type: object + additionalProperties: + type: integer + format: int32 + imageBase64: + type: string AddStatRequestDTO: type: object properties: @@ -1098,6 +1540,8 @@ components: - ALL awardBadges: type: boolean + awardChallenges: + type: boolean required: - stat - value @@ -1166,10 +1610,11 @@ components: distanceMeters: type: number format: float - RoutingAlternativeRequestDTO: + RoutingDirectionsRequestDTO: type: object - description: This DTO represents a request for alternative routes between an - origin and a destination. + description: "DTO representing a request for routing directions between two\ + \ points. Points can be specified either by coordinates or addresses.If both\ + \ provided, coordinates are preferred." properties: originLat: type: number @@ -1183,6 +1628,10 @@ components: destinationLon: type: number format: double + originAddress: + type: string + destinationAddress: + type: string arrivalTime: type: string format: date-time @@ -1191,13 +1640,8 @@ components: format: date-time routingPreferencesDTO: $ref: "#/components/schemas/RoutingPreferencesDTO" - required: - - arrivalTime - - departureTime - - destinationLat - - destinationLon - - originLat - - originLon + description: "Routing preferences to customize the routing behavior. If\ + \ null, will search for stored user preferences, if not found, use default." AddressDTO: type: object properties: @@ -1284,16 +1728,17 @@ components: type: number format: double description: The temporal difference in minutes compared to the original - route the user requested alternatives for. + route (in case alternative was requested) / the car route (when simply + directions requested) . durationSeconds: type: integer format: int64 - physicalActivity: - type: boolean cyclingRoute: type: boolean walkingRoute: type: boolean + physicalActivity: + type: boolean StepDTO: type: object description: A single step within a suggested alternative route. @@ -1311,11 +1756,41 @@ components: - CAR - MOTORCYCLE - TAXI - lineNumber: - type: string distanceMeters: type: number format: double + RoutingAlternativeRequestDTO: + type: object + description: This DTO represents a request for alternative routes between an + origin and a destination. + properties: + originLat: + type: number + format: double + originLon: + type: number + format: double + destinationLat: + type: number + format: double + destinationLon: + type: number + format: double + arrivalTime: + type: string + format: date-time + departureTime: + type: string + format: date-time + routingPreferencesDTO: + $ref: "#/components/schemas/RoutingPreferencesDTO" + required: + - arrivalTime + - departureTime + - destinationLat + - destinationLon + - originLat + - originLon UserRegistrationDTO: type: object properties: @@ -1358,6 +1833,51 @@ components: required: - email - password + Badge: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + description: + type: string + category: + type: string + enum: + - XP + - MOBILITY_SCORE + - CO2 + - IDLE + - WALKING + - BICYCLE + - ESCOOTER + - BUS + - TRAM + - TRAIN + - CAR + - OPNV + - MONTHLY + - HIDDEN + image: + $ref: "#/components/schemas/BadgeImageEntity" + criteria: + type: object + additionalProperties: + type: integer + format: int32 + BadgeImageEntity: + type: object + properties: + id: + type: integer + format: int32 + imageData: + type: string + format: byte + badge: + $ref: "#/components/schemas/Badge" Friendship: type: object properties: @@ -1407,6 +1927,10 @@ components: items: $ref: "#/components/schemas/Friendship" uniqueItems: true + base64ProfilePicture: + type: string + friendCode: + type: string NotificationToken: type: object properties: @@ -1419,6 +1943,17 @@ components: - FIREBASE token: type: string + ProfileImageEntity: + type: object + properties: + id: + type: integer + format: int32 + imageData: + type: string + format: byte + user: + $ref: "#/components/schemas/User" RoutingPreferences: type: object properties: @@ -1449,9 +1984,6 @@ components: Stats: type: object properties: - statsList: - $ref: "#/components/schemas/StatsList" - description: The StatsList to which these stats belong. xp: type: integer format: int64 @@ -1464,17 +1996,15 @@ components: km_WALKED: type: integer format: int64 - km_PUBLIC_TRANSPORT: + km_DRIVEN: type: integer format: int64 - km_DRIVEN: + km_PUBLIC_TRANSPORT: type: integer format: int64 mobility_SCORE: type: integer format: int64 - required: - - statsList StatsList: type: object properties: @@ -1483,9 +2013,6 @@ components: format: int64 description: Unique identifier of the StatsList. example: 1 - user: - $ref: "#/components/schemas/User" - description: The User to whom this StatsList belongs. totalStats: $ref: "#/components/schemas/Stats" description: Total stats of the user. @@ -1635,6 +2162,8 @@ components: uniqueItems: true routingPreferences: $ref: "#/components/schemas/RoutingPreferences" + profileImage: + $ref: "#/components/schemas/ProfileImageEntity" stats: $ref: "#/components/schemas/StatsList" UserBadge: @@ -1763,6 +2292,8 @@ components: score: type: integer format: int64 + base64ProfilePicture: + type: string FriendshipDTO: type: object properties: @@ -1795,6 +2326,23 @@ components: type: string description: type: string + category: + type: string + enum: + - XP + - MOBILITY_SCORE + - CO2 + - IDLE + - WALKING + - BICYCLE + - ESCOOTER + - BUS + - TRAM + - TRAIN + - CAR + - OPNV + - MONTHLY + - HIDDEN criteria: type: object additionalProperties: @@ -1803,6 +2351,8 @@ components: awardedAt: type: string format: date-time + imageBase64: + type: string securitySchemes: bearerAuth: type: http diff --git a/src/main/java/SuMoC/backend/gamification/challenges/ChallengeMapper.java b/src/main/java/SuMoC/backend/gamification/challenges/ChallengeMapper.java index 7119482..fa951b3 100644 --- a/src/main/java/SuMoC/backend/gamification/challenges/ChallengeMapper.java +++ b/src/main/java/SuMoC/backend/gamification/challenges/ChallengeMapper.java @@ -5,6 +5,8 @@ import SuMoC.backend.gamification.challenges.Models.ChallengeDTO; import SuMoC.backend.images.ImageBase64Util; import org.mapstruct.Mapper; +import java.util.Optional; + @Mapper public interface ChallengeMapper { @@ -15,8 +17,12 @@ public interface ChallengeMapper { dto.setDescription(challenge.getDescription()); dto.setCriteria(challenge.getCriteria()); dto.setReward(challenge.getReward()); - dto.setBase64image(challenge.getImage() != null && challenge.getImage().getImageData() != null ? - ImageBase64Util.encode(challenge.getImage().getImageData()) : null); + dto.setBase64image( + Optional.ofNullable(challenge.getImage()) + .map(ChallengeImageEntity::getImageData) + .map(ImageBase64Util::encode) + .orElse(null) + ); return dto; } @@ -27,10 +33,14 @@ public interface ChallengeMapper { challenge.setDescription(dto.getDescription()); challenge.setCriteria(dto.getCriteria()); challenge.setReward(dto.getReward()); - challenge.setImage(new ChallengeImageEntity( - challenge, - ImageBase64Util.decode(dto.getBase64image()) - )); + + if (dto.getBase64image() != null && !dto.getBase64image().isEmpty()) { + challenge.setImage(new ChallengeImageEntity( + challenge, + ImageBase64Util.decode(dto.getBase64image()) + )); + } + return challenge; } @@ -40,7 +50,6 @@ public interface ChallengeMapper { challenge.setCriteria(dto.getCriteria()); challenge.setReward(dto.getReward()); - // Bild aktualisieren if (dto.getBase64image() != null && !dto.getBase64image().isEmpty()) { byte[] imageData = ImageBase64Util.decode(dto.getBase64image()); if (challenge.getImage() == null) { diff --git a/src/test/java/SuMoC/backend/user/service/ChallengeServiceTest.java b/src/test/java/SuMoC/backend/user/service/ChallengeServiceTest.java index f17a919..2f03dfa 100644 --- a/src/test/java/SuMoC/backend/user/service/ChallengeServiceTest.java +++ b/src/test/java/SuMoC/backend/user/service/ChallengeServiceTest.java @@ -57,13 +57,15 @@ public class ChallengeServiceTest { challengeDTOList.add(created); } - // with criteria + // with criteria and image + String dummyBase64 = ImageBase64Util.encode(new byte[]{1, 2, 3, 4, 5}); for(int i = 5; i < 10; i++) { ChallengeDTO challengeDTO = new ChallengeDTO(); challengeDTO.setName("badgeName" + i); challengeDTO.setDescription("badgeDescription" + i); challengeDTO.setCriteria(new HashMap<>(Map.of("XP", (i * 10)))); challengeDTO.setReward(i); + challengeDTO.setBase64image(dummyBase64); ChallengeDTO created = challengeService.createChallenge(challengeDTO); challengeDTOList.add(created); @@ -89,7 +91,14 @@ public class ChallengeServiceTest { assertEquals(dto.getDescription(), challenge.getDescription()); assertEquals(dto.getCriteria(), challenge.getCriteria()); assertEquals(dto.getReward(), challenge.getReward()); - assertEquals(dto.getBase64image(), ImageBase64Util.encode(challenge.getImage().getImageData())); + + if (dto.getBase64image() != null) { + assertNotNull(challenge.getImage()); + assertEquals(dto.getBase64image(), + ImageBase64Util.encode(challenge.getImage().getImageData())); + } else { + assertNull(challenge.getImage()); + } });