Last active
August 15, 2017 10:37
-
-
Save AlbertFX91/7dba72f615440f9e96ec4468d608465c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.albertfx.games.service; | |
import org.springframework.data.domain.Page; | |
import org.springframework.data.domain.Pageable; | |
import com.albertfx.games.domain.Game; | |
public interface GameService { | |
/** | |
* Save a game. | |
* | |
* @param game | |
* the entity to save | |
* @return the persisted entity | |
*/ | |
Game save(Game game); | |
/** | |
* Get all the games. | |
* | |
* @param pageable | |
* the pagination information | |
* @return the list of entities | |
*/ | |
Page<Game> findAll(Pageable pageable); | |
/** | |
* Get the "id" game. | |
* | |
* @param id | |
* the id of the entity | |
* @return the entity | |
*/ | |
Game findOne(String id); | |
/** | |
* Delete the "id" game. | |
* | |
* @param id | |
* the id of the entity | |
*/ | |
void delete(String id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.albertfx.games.service.impl; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.data.domain.Page; | |
import org.springframework.data.domain.Pageable; | |
import org.springframework.stereotype.Service; | |
import com.albertfx.games.domain.Game; | |
import com.albertfx.games.repository.GameRepository; | |
import com.albertfx.games.service.GameService; | |
@Service | |
public class GameServiceImpl implements GameService{ | |
// This is our log tools to register the track of our app | |
private final Logger log = LoggerFactory.getLogger(GameService.class); | |
private final GameRepository gameRepository; | |
public GameServiceImpl(GameRepository gameRepository) { | |
this.gameRepository = gameRepository; | |
} | |
public Game save(Game game) { | |
log.debug("Request to save Acme : {}", game); | |
// We return our game object with the ID generated | |
return gameRepository.save(game); | |
} | |
/* | |
* Pageable | |
* ---------- | |
* Pageable its a type which allow us to access to our data with a pagination. | |
* It takes a track of the page number, the page's size, sorting parameters, etc. | |
* https://docs.spring.io/spring-data/data-commons/docs/current/api/org/springframework/data/domain/Pageable.html | |
* | |
* Page | |
* --------- | |
* Its a sublist of a list of objects. One of its superinterface are Iterable<T>, so we can access to its data. | |
* It has a track of the total elements or the total pages. | |
* https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html | |
*/ | |
public Page<Game> findAll(Pageable pageable){ | |
log.debug("Request to get all games"); | |
return gameRepository.findAll(pageable); | |
} | |
public Game findOne(String id) { | |
log.debug("Request to get game : {}", id); | |
return gameRepository.findOne(id); | |
} | |
public void delete(String id) { | |
log.debug("Request to delete game : {}", id); | |
gameRepository.delete(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment