SudokuFX
Loading...
Searching...
No Matches
fr.softsf.sudokufx.service.business.GameService Class Reference

Service for managing Game entities. More...

Collaboration diagram for fr.softsf.sudokufx.service.business.GameService:

Public Member Functions

 GameService (GameRepository gameRepository, PlayerRepository playerRepository, GridRepository gridRepository, IGameMapper gameMapper, GridService gridService, GameLevelService gameLevelService, JakartaValidator jakartaValidator)
 Constructs a new GameService with the required infrastructure, service, and mapping dependencies.
void createNewGameWithCurrent (GameDto sourceDto, long playerId)
 Creates a new game by duplicating the grid of the source game.
void deleteGame (long gameId)
 Deletes a game entity.
Collection< GameDto > getGames (long playerId)
 Retrieves all non-selected games for a given player, sorted by update date in descending order.
void switchAndSelectNewGame (long oldGameId, long newGameId)
 Atomically switches the selected game status.

Static Public Attributes

static final String GAME_NOT_FOUND = "Game not found: "

Private Member Functions

Game getGameOrThrow (long gameId)
 Internal utility to retrieve a game entity by its identifier.
void updateGameSelection (long gameId, boolean selected)
 Internal utility to update game selection state and persist changes.

Private Attributes

final GameLevelService gameLevelService
final IGameMapper gameMapper
final GameRepository gameRepository
final GridRepository gridRepository
final GridService gridService
final JakartaValidator jakartaValidator
final PlayerRepository playerRepository

Detailed Description

Service for managing Game entities.

Constructor & Destructor Documentation

◆ GameService()

fr.softsf.sudokufx.service.business.GameService.GameService ( GameRepository gameRepository,
PlayerRepository playerRepository,
GridRepository gridRepository,
IGameMapper gameMapper,
GridService gridService,
GameLevelService gameLevelService,
JakartaValidator jakartaValidator )

Constructs a new GameService with the required infrastructure, service, and mapping dependencies.

Parameters
gameRepositorythe repository for Game entities
playerRepositorythe repository for Player entities
gridRepositorythe repository for Grid entities
gameMapperthe mapper used to convert Game entities to GameDto
gridServicethe service providing Grid duplication logic
gameLevelServicethe service providing GameLevel lookup logic
jakartaValidatorthe validator used to ensure data integrity of processed DTOs

Member Function Documentation

◆ createNewGameWithCurrent()

void fr.softsf.sudokufx.service.business.GameService.createNewGameWithCurrent ( GameDto sourceDto,
long playerId )

Creates a new game by duplicating the grid of the source game.

The process clones the Grid resource, associates it with the specified Player and GameLevel, and initializes a new game instance.

Business operations performed:

This method is fully transactional: all operations succeed or fail as a unit.

Parameters
sourceDtothe source game DTO; must not be null
playerIdthe identifier of the owner player
Exceptions
IllegalArgumentExceptionif required entities are not found in the database
jakarta.validation.ConstraintViolationExceptionif validation fails on the resulting entities
Here is the call graph for this function:

◆ deleteGame()

void fr.softsf.sudokufx.service.business.GameService.deleteGame ( long gameId)

Deletes a game entity.

Here is the call graph for this function:

◆ getGameOrThrow()

Game fr.softsf.sudokufx.service.business.GameService.getGameOrThrow ( long gameId)
private

Internal utility to retrieve a game entity by its identifier.

Parameters
gameIdthe identifier of the game to retrieve
Returns
the found game entity
Exceptions
IllegalArgumentExceptionif the game does not exist

◆ getGames()

Collection< GameDto > fr.softsf.sudokufx.service.business.GameService.getGames ( long playerId)

Retrieves all non-selected games for a given player, sorted by update date in descending order.

Parameters
playerIdthe unique identifier of the player.
Returns
a sorted, validated collection of GameDto.
Exceptions
jakarta.validation.ConstraintViolationExceptionif validation fails.
Here is the call graph for this function:

◆ switchAndSelectNewGame()

void fr.softsf.sudokufx.service.business.GameService.switchAndSelectNewGame ( long oldGameId,
long newGameId )

Atomically switches the selected game status.

Ensures data consistency by unselecting the previous game and selecting the new one within a single database transaction.

Parameters
oldGameIdthe identifier of the game to be unselected
newGameIdthe identifier of the game to be selected
Exceptions
IllegalArgumentExceptionif either game is not found
jakarta.validation.ConstraintViolationExceptionif validation fails
Here is the call graph for this function:

◆ updateGameSelection()

void fr.softsf.sudokufx.service.business.GameService.updateGameSelection ( long gameId,
boolean selected )
private

Internal utility to update game selection state and persist changes.

Parameters
gameIdthe identifier of the game to update
selectedthe new selection state
Here is the call graph for this function:

Member Data Documentation

◆ GAME_NOT_FOUND

final String fr.softsf.sudokufx.service.business.GameService.GAME_NOT_FOUND = "Game not found: "
static

◆ gameLevelService

final GameLevelService fr.softsf.sudokufx.service.business.GameService.gameLevelService
private

◆ gameMapper

final IGameMapper fr.softsf.sudokufx.service.business.GameService.gameMapper
private

◆ gameRepository

final GameRepository fr.softsf.sudokufx.service.business.GameService.gameRepository
private

◆ gridRepository

final GridRepository fr.softsf.sudokufx.service.business.GameService.gridRepository
private

◆ gridService

final GridService fr.softsf.sudokufx.service.business.GameService.gridService
private

◆ jakartaValidator

final JakartaValidator fr.softsf.sudokufx.service.business.GameService.jakartaValidator
private

◆ playerRepository

final PlayerRepository fr.softsf.sudokufx.service.business.GameService.playerRepository
private

The documentation for this class was generated from the following file: