Added basic CRUD operations
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user