Added basic CRUD operations

This commit is contained in:
2025-12-11 19:07:30 +01:00
parent 7c93577132
commit 46f2cf2d55
30 changed files with 615 additions and 139 deletions

View File

@@ -0,0 +1,47 @@
package be.naaturel.boardmateapi.services;
import be.naaturel.boardmateapi.common.models.Game;
import be.naaturel.boardmateapi.common.models.Move;
import be.naaturel.boardmateapi.repository.GameRepo;
import be.naaturel.boardmateapi.repository.dtos.GameDto;
import be.naaturel.boardmateapi.repository.mappings.GameMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Collection;
import java.util.Optional;
@Service
public class GameService {
private final GameRepo repo;
@Autowired
public GameService(GameRepo repo){
this.repo = repo;
}
public void save(Game game){
GameDto gameDto = GameMapper.toDto(game);
repo.save(gameDto);
}
public Game retrieveGame(String id){
Optional<GameDto> dtoOpt = repo.findById(id);
return dtoOpt.map(GameMapper::toModel).orElse(null);
}
public String create(Game game){
GameDto gameDto = GameMapper.toDto(game);
repo.save(gameDto);
return gameDto.getId();
}
public String addMove(@RequestBody String gameId, @RequestBody Move move) throws Exception {
Game g = retrieveGame(gameId);
g.addMove(move);
save(g);
return move.toString();
}
}

View File

@@ -1,30 +0,0 @@
package be.naaturel.boardmateapi.services;
import be.naaturel.boardmateapi.models.Party;
import be.naaturel.boardmateapi.repository.CustomPartyRepoImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PartyService {
private final CustomPartyRepoImpl repo;
@Autowired
public PartyService(CustomPartyRepoImpl repo){
this.repo = repo;
}
public Party retrieveParty(String id){
return null;
}
public String create(){
return null;
}
public String addMove(){
return null;
}
}