diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/constant/Enumerations.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/constant/Enumerations.kt index 4d790a39..12cd213a 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/constant/Enumerations.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/constant/Enumerations.kt @@ -1,46 +1,52 @@ package com.gamelounge.backend.constant enum class GameGenre { - RPG, - STRATEGY, - SHOOTER, - SPORTS_AND_RACING, - FIGHTING, + RGP, + Strategy, + Shooter, + Sports, + Fighting, MOBA, - EMPTY + Action, + Adventure, + Simulation, + Horror, + Empty } enum class GamePlatform { XBOX, - COMPUTER, + Computer, PS, // PlayStation - ONBOARD, - EMPTY + Onboard, + Mobile, + Empty } enum class NumberOfPlayers { - SINGLE, - TEAMS, - MULTIPLE, + Single, + Teams, + Multiplayer, MMO, // Massively Multiplayer Online - EMPTY + Empty } enum class UniverseInfo { - MEDIEVAL, - FANTASY, - SCIFI, - CYBERPUNK, - HISTORICAL, - CONTEMPORARY, - POST_APOCALYPTIC, - ALTERNATE_REALITY, - EMPTY + Medieval, + Fantasy, + SciFi, + Cyberpunk, + Historical, + Contemporary, + PostApocalyptic, + AlternateReality, + Empty } enum class GameMechanics { - TURN_BASED, - CHANCE_BASED, - EMPTY + TurnBased, + ChangeBased, + RealTime, + Empty // Add more mechanics as needed } diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/constant/S3Constants.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/constant/S3Constants.kt index 79fe7a90..9f72afe4 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/constant/S3Constants.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/constant/S3Constants.kt @@ -3,4 +3,5 @@ package com.gamelounge.backend.constant object S3Constants { const val PROFILE_PICTURE_DIRECTORY = "https://game-lounge-storage.s3.eu-north-1.amazonaws.com/profile-pictures/" const val GAME_PICTURE_DIRECTORY = "https://game-lounge-storage.s3.eu-north-1.amazonaws.com/game-pictures/" + const val EDITED_GAME_PICTURE_DIRECTORY = "https://game-lounge-storage.s3.eu-north-1.amazonaws.com/edited-game-pictures/" } \ No newline at end of file diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/controller/GameController.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/controller/GameController.kt index 15154bbf..e03d055f 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/controller/GameController.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/controller/GameController.kt @@ -1,5 +1,7 @@ package com.gamelounge.backend.controller + +import com.gamelounge.backend.entity.UserGameRating import com.gamelounge.backend.middleware.SessionAuth import com.gamelounge.backend.model.DTO.GameDTO import com.gamelounge.backend.model.request.CreateGameRequest @@ -10,6 +12,7 @@ import com.gamelounge.backend.model.request.* import com.gamelounge.backend.model.response.ResponseMessage import com.gamelounge.backend.service.GameService import com.gamelounge.backend.util.ConverterDTO +import io.swagger.v3.core.util.Json import com.gamelounge.backend.util.ConverterDTO.convertBulkToGameDTO import org.springframework.http.HttpStatus import org.springframework.http.MediaType @@ -67,6 +70,13 @@ class GameController( return ResponseEntity.ok(gameDTO) } + @GetMapping("/{id}/getRating") + fun getRating(@CookieValue("SESSIONID") sessionId: UUID, @PathVariable id: Long): ResponseEntity { + val userGameRating = gameService.getRating(sessionId, id) + val userGameRatingDTO = ConverterDTO.convertToUserInfoGameRatingDTO(userGameRating) + return ResponseEntity.ok(userGameRatingDTO) + } + @GetMapping("/rated") fun getGamesRatedByUser(@CookieValue("SESSIONID") sessionId: UUID): ResponseEntity> { val userGameRatingDTOs = gameService.getRatedGamesByUser(sessionId) @@ -83,10 +93,10 @@ class GameController( @ResponseStatus(HttpStatus.CREATED) fun createEditingRequest(@CookieValue("SESSIONID") sessionId: UUID, @RequestPart("request") editedGame: CreateEditingRequest, - @RequestPart("image") image: MultipartFile?, + @RequestPart("image") editedImage: MultipartFile?, @PathVariable id: Long ): ResponseEntity { - gameService.createEditingRequest(sessionId, editedGame, image, id) + gameService.createEditingRequest(sessionId, editedGame, editedImage, id) return ResponseEntity.ok(ResponseMessage(message = "Editing game was requested successfully.")) } diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/entity/Game.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/entity/Game.kt index 4d2bd9c1..5da288af 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/entity/Game.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/entity/Game.kt @@ -33,17 +33,24 @@ class Game( var title: String = "", var description: String = "", + + @ElementCollection(targetClass = GameGenre::class) @Enumerated(EnumType.STRING) - var genre: GameGenre = GameGenre.EMPTY, + @CollectionTable(name = "game_genres", joinColumns = [JoinColumn(name = "gameId")]) + var genres: Set = emptySet(), + + @ElementCollection(targetClass = GamePlatform::class) @Enumerated(EnumType.STRING) - var platform: GamePlatform = GamePlatform.EMPTY, + @CollectionTable(name = "game_platforms", joinColumns = [JoinColumn(name = "gameId")]) + var platforms: Set = emptySet(), + @Enumerated(EnumType.STRING) - var playerNumber: NumberOfPlayers = NumberOfPlayers.EMPTY, + var playerNumber: NumberOfPlayers = NumberOfPlayers.Empty, var releaseYear: Int = 0, @Enumerated(EnumType.STRING) - var universe: UniverseInfo = UniverseInfo.EMPTY, + var universe: UniverseInfo = UniverseInfo.Empty, @Enumerated(EnumType.STRING) - var mechanics: GameMechanics = GameMechanics.EMPTY, + var mechanics: GameMechanics = GameMechanics.Empty, var playtime: String = "", var totalRating: Int = 0, var countRating: Int = 0, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/entity/RequestedEditingGame.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/entity/RequestedEditingGame.kt index 5177c99f..3cad27b8 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/entity/RequestedEditingGame.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/entity/RequestedEditingGame.kt @@ -27,17 +27,24 @@ class RequestedEditingGame( val gameId: Long = 0, var title: String = "", var description: String = "", + + @ElementCollection(targetClass = GameGenre::class) @Enumerated(EnumType.STRING) - var genre: GameGenre = GameGenre.EMPTY, + @CollectionTable(name = "edited_game_genres", joinColumns = [JoinColumn(name = "gameId")]) + var genres: Set = emptySet(), + + @ElementCollection(targetClass = GamePlatform::class) @Enumerated(EnumType.STRING) - var platform: GamePlatform = GamePlatform.EMPTY, + @CollectionTable(name = "edited_game_platforms", joinColumns = [JoinColumn(name = "gameId")]) + var platforms: Set = emptySet(), + @Enumerated(EnumType.STRING) - var playerNumber: NumberOfPlayers = NumberOfPlayers.EMPTY, + var playerNumber: NumberOfPlayers = NumberOfPlayers.Empty, var releaseYear: Int = 0, @Enumerated(EnumType.STRING) - var universe: UniverseInfo = UniverseInfo.EMPTY, + var universe: UniverseInfo = UniverseInfo.Empty, @Enumerated(EnumType.STRING) - var mechanics: GameMechanics = GameMechanics.EMPTY, + var mechanics: GameMechanics = GameMechanics.Empty, var playtime: String = "", var creationDate: Instant = Instant.now(), var gamePicture: String? = null, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/EditedGameDTO.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/EditedGameDTO.kt index 2c1d62bb..c7a1ea4f 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/EditedGameDTO.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/EditedGameDTO.kt @@ -12,12 +12,12 @@ data class EditedGameDTO( var gameId: Long = 0, var title: String = "", var description: String = "", - var genre: GameGenre = GameGenre.EMPTY, - var platform: GamePlatform = GamePlatform.EMPTY, - var playerNumber: NumberOfPlayers = NumberOfPlayers.EMPTY, + val genres: List, + val platforms: List, + var playerNumber: NumberOfPlayers = NumberOfPlayers.Empty, var releaseYear: Int = 0, - var universe: UniverseInfo = UniverseInfo.EMPTY, - var mechanics: GameMechanics = GameMechanics.EMPTY, + var universe: UniverseInfo = UniverseInfo.Empty, + var mechanics: GameMechanics = GameMechanics.Empty, var playtime: String = "", var creationDate: Instant? = null, var gamePicture: String? = null, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/GameDTO.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/GameDTO.kt index 6a7015a5..d030a634 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/GameDTO.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/GameDTO.kt @@ -12,13 +12,13 @@ data class GameDTO( var gameId: Long = 0, var title: String = "", var description: String = "", - var genre: GameGenre = GameGenre.EMPTY, - var platform: GamePlatform = GamePlatform.EMPTY, + val genres: List, + val platforms: List, var characters: List, - var playerNumber: NumberOfPlayers = NumberOfPlayers.EMPTY, + var playerNumber: NumberOfPlayers = NumberOfPlayers.Empty, var releaseYear: Int = 0, - var universe: UniverseInfo = UniverseInfo.EMPTY, - var mechanics: GameMechanics = GameMechanics.EMPTY, + var universe: UniverseInfo = UniverseInfo.Empty, + var mechanics: GameMechanics = GameMechanics.Empty, var playtime: String = "", var totalRating: Int, var countRating: Int, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserDTO.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserDTO.kt index 8566cfad..1755929c 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserDTO.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserDTO.kt @@ -11,4 +11,6 @@ data class UserDTO( var tags: List? = null, var followers: List? = null, var isVisible: Boolean = false, + var isDeleted: Boolean = false, + var isAdmin: Boolean = false ) \ No newline at end of file diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserGameRatingDTO.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserGameRatingDTO.kt index e75a2517..0958d8e0 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserGameRatingDTO.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/DTO/UserGameRatingDTO.kt @@ -1,6 +1,13 @@ package com.gamelounge.backend.model.DTO +class UserGameRatingDTO ( + var user: UserDTO, + var game: GameDTO, + var rating: Int +) + data class UserGameRatingDTO( var gameDTO: GameDTO, var score: Int ) + diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateEditingRequest.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateEditingRequest.kt index 5544ff7d..e9fc1eb5 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateEditingRequest.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateEditingRequest.kt @@ -9,8 +9,8 @@ class CreateEditingRequest( val gameId: Long = 0, val title: String, val description: String, - val genre: GameGenre, - val platform: GamePlatform, + val genres: List, + val platforms: List, val playerNumber: NumberOfPlayers, val releaseYear: Int, val universe: UniverseInfo, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateGameRequest.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateGameRequest.kt index 64ca7afe..6f501c5a 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateGameRequest.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/CreateGameRequest.kt @@ -8,8 +8,8 @@ import com.gamelounge.backend.constant.GameMechanics class CreateGameRequest( val title: String, val description: String, - val genre: GameGenre, - val platform: GamePlatform, + val genres: List, + val platforms: List, val playerNumber: NumberOfPlayers, val releaseYear: Int, val universe: UniverseInfo, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/UpdateGameRequest.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/UpdateGameRequest.kt index 99da766b..86a1bd9e 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/UpdateGameRequest.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/request/UpdateGameRequest.kt @@ -8,8 +8,8 @@ import com.gamelounge.backend.constant.GameMechanics class UpdateGameRequest( val title: String, val description: String, - val genre: GameGenre, - val platform: GamePlatform, + val genres: List, + val platforms: List, val playerNumber: NumberOfPlayers, val releaseYear: Int, val universe: UniverseInfo, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/model/response/GetUserInfoResponse.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/model/response/GetUserInfoResponse.kt index 964613f4..a1524c95 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/model/response/GetUserInfoResponse.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/model/response/GetUserInfoResponse.kt @@ -9,6 +9,8 @@ data class GetUserInfoResponse( val profilePicture: String? = null, val about: String? = null, val isAdmin: Boolean = false, + val isVisible: Boolean = false, + val isDeleted: Boolean = false, val tags: List? = null, val title: String? = null, val company: String? = null, diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/service/GameService.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/service/GameService.kt index 5c68927a..1e52c8b2 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/service/GameService.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/service/GameService.kt @@ -1,5 +1,7 @@ package com.gamelounge.backend.service +import com.gamelounge.backend.constant.GameGenre +import com.gamelounge.backend.constant.GamePlatform import com.gamelounge.backend.entity.* import com.gamelounge.backend.exception.* import com.gamelounge.backend.middleware.SessionAuth @@ -32,25 +34,32 @@ class GameService( fun createGame(sessionId: UUID, game: CreateGameRequest, image: MultipartFile?): Game { val userId = sessionAuth.getUserIdFromSession(sessionId) val user = userRepository.findById(userId).orElseThrow { UsernameNotFoundException("User not found") } + + // Convert genre strings to GameGenre enum values + val genres = game.genres.map { GameGenre.valueOf(it) }.toSet() + + // Convert platform strings to GamePlatform enum values + val platforms = game.platforms.map { GamePlatform.valueOf(it) }.toSet() + val newGame = Game( title = game.title, description = game.description, - genre = game.genre, - platform = game.platform, + genres = genres, + platforms = platforms, playerNumber = game.playerNumber, releaseYear = game.releaseYear, universe = game.universe, mechanics = game.mechanics, playtime = game.playtime, user = user, - status = GameStatus.PENDING_APPROVAL + status = GameStatus.PENDING_APPROVAL, ) gameRepository.save(newGame) // save to get gameId for image name image?.let { saveImageInS3AndImageURLInDBForGame(image, newGame) } return gameRepository.save(newGame) } - fun createEditingRequest(sessionId: UUID, editedGame: CreateEditingRequest, image: MultipartFile?, gameId: Long): RequestedEditingGame { + fun createEditingRequest(sessionId: UUID, editedGame: CreateEditingRequest, editedImage: MultipartFile?, gameId: Long) { val userId = sessionAuth.getUserIdFromSession(sessionId) val user = userRepository.findById(userId).orElseThrow { UsernameNotFoundException("User not found") } val game = getGame(gameId) @@ -69,21 +78,27 @@ class GameService( throw DuplicatedEditingRequestException("Not allowed to edit more than once") } + // Convert genre strings to GameGenre enum values + val genres = editedGame.genres.map { GameGenre.valueOf(it) }.toSet() + + // Convert platform strings to GamePlatform enum values + val platforms = editedGame.platforms.map { GamePlatform.valueOf(it) }.toSet() + val requestEditingGame = RequestedEditingGame( gameId = gameId, title = editedGame.title, description = editedGame.description, - genre = editedGame.genre, - platform = editedGame.platform, + genres = genres, + platforms = platforms, playerNumber = editedGame.playerNumber, releaseYear = editedGame.releaseYear, universe = editedGame.universe, mechanics = editedGame.mechanics, playtime = editedGame.playtime, ) - editedGameRepository.save(requestEditingGame) // save to get gameId for image name - image?.let { saveImageInS3AndImageURLInDBForEditedGame(image, requestEditingGame) } - return editedGameRepository.save(requestEditingGame) + //editedGameRepository.save(requestEditingGame) // save to get gameId for image name + editedImage?.let { saveImageInS3AndImageURLInDBForEditedGame(editedImage, requestEditingGame) } + editedGameRepository.save(requestEditingGame) } private fun saveImageInS3AndImageURLInDBForGame(image: MultipartFile, game: Game) { @@ -91,9 +106,9 @@ class GameService( gameRepository.save(game) } - private fun saveImageInS3AndImageURLInDBForEditedGame(image: MultipartFile, editedGame: RequestedEditingGame) { - editedGame.gamePicture = s3Service.uploadGamePictureAndReturnURL(image, editedGame.gameId) - editedGameRepository.save(editedGame) + private fun saveImageInS3AndImageURLInDBForEditedGame(editedImage: MultipartFile, editedGame: RequestedEditingGame) { + editedGame.gamePicture = s3Service.uploadEditedGamePictureAndReturnURL(editedImage, editedGame.gameId) + //editedGameRepository.save(editedGame) } fun getGame(gameId: Long): Game { @@ -101,7 +116,11 @@ class GameService( } fun getEditingGame(editingGameId: Long): RequestedEditingGame { - return editedGameRepository.findById(editingGameId).orElseThrow { GameNotFoundException("Requested editing game not found with ID: $editingGameId") } + if (editedGameRepository.findByGameId(editingGameId).isEmpty()) { + throw GameNotFoundException("Game not found with GameId: $editingGameId") + } + return editedGameRepository.findByGameId(editingGameId).first() + } fun updateGame(sessionId: UUID, gameId: Long, updatedGame: UpdateGameRequest): Game { @@ -117,10 +136,16 @@ class GameService( throw DeletedGameException("Game with ID: $gameId is deleted") } + // Convert genre strings to GameGenre enum values + val genres = updatedGame.genres.map { GameGenre.valueOf(it) }.toSet() + + // Convert platform strings to GamePlatform enum values + val platforms = updatedGame.platforms.map { GamePlatform.valueOf(it) }.toSet() + game.title = updatedGame.title game.description = updatedGame.description - game.genre = updatedGame.genre - game.platform = updatedGame.platform + game.genres = genres + game.platforms = platforms game.playerNumber = updatedGame.playerNumber game.releaseYear = updatedGame.releaseYear game.universe = updatedGame.universe @@ -175,17 +200,43 @@ class GameService( //val alreadyRated = game.ratedUsers.contains(user) val alreadyRated = userGameRatingRepository.findByUserAndGame(user, game) if (alreadyRated.isNotEmpty()){ - throw DuplicatedRatingGameException("Not allowed to rate more than once") + // change rate if already rated + val userGameRating = alreadyRated.first() + game.totalRating -= userGameRating.score + game.totalRating += score.toInt() + game.averageRating = game.totalRating.toDouble() / game.countRating.toDouble() + userGameRating.score = score.toInt() + userGameRatingRepository.save(userGameRating) + return gameRepository.save(game) + }else{ + val userGameRating = UserGameRating(user = user, game = game, score = score.toInt()) + //game.ratedUsers.add(user) + game.countRating += 1 + game.totalRating += score.toInt() + game.averageRating = game.totalRating.toDouble() / game.countRating.toDouble() + + userGameRatingRepository.save(userGameRating) + return gameRepository.save(game) } - val userGameRating = UserGameRating(user = user, game = game, score = score.toInt()) - //game.ratedUsers.add(user) - game.countRating += 1 - game.totalRating += score.toInt() - game.averageRating = game.totalRating.toDouble() / game.countRating.toDouble() - userGameRatingRepository.save(userGameRating) - return gameRepository.save(game) + } + + fun getRating(sessionId: UUID, gameId: Long): UserGameRating { + val userId = sessionAuth.getUserIdFromSession(sessionId) + val user = userRepository.findById(userId).orElseThrow { UsernameNotFoundException("User not found") } + val game = getGame(gameId) + + if (game.isDeleted) { + throw DeletedGameException("Game with ID: $gameId is deleted") + } + + val alreadyRated = userGameRatingRepository.findByUserAndGame(user, game) + if (alreadyRated.isNotEmpty()){ + return alreadyRated.first() + }else{ + throw WrongRatingGameException("User with ID: $userId has not rated the game with ID: $gameId") + } } fun getPendingGames(sessionId: UUID): List { @@ -228,8 +279,8 @@ class GameService( game.title = requestedEditingGame.title game.description = requestedEditingGame.description - game.genre = requestedEditingGame.genre - game.platform = requestedEditingGame.platform + game.genres = requestedEditingGame.genres + game.platforms = requestedEditingGame.platforms game.playerNumber = requestedEditingGame.playerNumber game.releaseYear = requestedEditingGame.releaseYear game.universe = requestedEditingGame.universe @@ -351,5 +402,4 @@ class GameService( val reportedGameIds = reportedGames.map { it.reportedGame?.gameId } return gameRepository.findAllById(reportedGameIds).filter { !it.isDeleted } } - } \ No newline at end of file diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/service/S3service.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/service/S3service.kt index dd8bd160..cf2c635c 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/service/S3service.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/service/S3service.kt @@ -1,5 +1,6 @@ package com.gamelounge.backend.service +import com.gamelounge.backend.constant.S3Constants.EDITED_GAME_PICTURE_DIRECTORY import com.gamelounge.backend.constant.S3Constants.GAME_PICTURE_DIRECTORY import com.gamelounge.backend.constant.S3Constants.PROFILE_PICTURE_DIRECTORY import org.springframework.beans.factory.annotation.Value @@ -37,6 +38,14 @@ class S3Service( return createGamePicturesURL(gameId) } + fun uploadEditedGamePictureAndReturnURL(editedImage: MultipartFile, gameId: Long): String{ + val s3 = createS3Client() + + putImageToS3Bucket(s3, editedImage, "edited-game-pictures/$gameId") + + return createEditedGamePicturesURL(gameId) + } + private fun createS3Client(): S3Client{ return S3Client.builder() .region(Region.EU_NORTH_1) @@ -64,4 +73,8 @@ class S3Service( private fun createGamePicturesURL(gameId: Long): String{ return GAME_PICTURE_DIRECTORY + gameId } + + private fun createEditedGamePicturesURL(gameId: Long): String{ + return EDITED_GAME_PICTURE_DIRECTORY + gameId + } } \ No newline at end of file diff --git a/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt b/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt index b9ad3d41..f1cb35d2 100644 --- a/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt +++ b/app/backend/src/main/kotlin/com/gamelounge/backend/util/ConverterDTO.kt @@ -46,7 +46,9 @@ object ConverterDTO { title = user.title, company = user.company, tags = convertBulkToTagDTO(user.tags), - isVisible = user.isVisible + isVisible = user.isVisible, + isDeleted = user.isDeleted, + isAdmin = user.isAdmin ) } fun convertBulkToUserDTO(users: List): List { @@ -89,8 +91,8 @@ object ConverterDTO { game.gameId, game.title, game.description, - game.genre, - game.platform, + game.genres.toList(), + game.platforms.toList(), convertBulkToCharacterDTO(game.characters), game.playerNumber, game.releaseYear, @@ -162,8 +164,8 @@ object ConverterDTO { requestedEditingGame.gameId, requestedEditingGame.title, requestedEditingGame.description, - requestedEditingGame.genre, - requestedEditingGame.platform, + requestedEditingGame.genres.toList(), + requestedEditingGame.platforms.toList(), requestedEditingGame.playerNumber, requestedEditingGame.releaseYear, requestedEditingGame.universe, @@ -173,4 +175,13 @@ object ConverterDTO { requestedEditingGame.gamePicture, ) } + + fun convertToUserInfoGameRatingDTO(userGameRating: UserGameRating): UserGameRatingDTO{ + return UserGameRatingDTO( + convertToUserDTO(userGameRating.user), + convertToGameDTO(userGameRating.game), + userGameRating.score + ) + } +} }