use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.
the class AdventureDto method toAdventuresDto.
/**
* Converts a list of adventures to a list of adventuresDto
* @param adventures
* @return adventuresDto
*/
public static List<AdventureDto> toAdventuresDto(List<Adventure> adventures) {
final List<AdventureDto> adventuresDto = new ArrayList<>();
final Iterator<Adventure> it = adventures.iterator();
while (it.hasNext()) {
final Adventure adventure = it.next();
adventuresDto.add(toAdventureDto(adventure));
}
return adventuresDto;
}
use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.
the class AdventureController method getFreeAdventures.
@RequestMapping(value = "/getFree/{developer_id}/{world_id}", method = RequestMethod.GET)
public List<AdventureDto> getFreeAdventures(@PathVariable(value = "developer_id") Long developer_id, @PathVariable(value = "world_id") Long world_id) {
World w = worldRepository.findOne(world_id);
Developer d = developerRepository.findOne(developer_id);
List<Adventure> adventures = this.adventureService.getFreeAdventuresForDeveloperInWorld(w, d);
return AdventureDto.toAdventuresDto(adventures);
}
use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.
the class AdventureController method addQuest.
@CrossOrigin
@RequestMapping(value = "/{adventureId}/addQuest/{questId}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public AdventureDto addQuest(@PathVariable(value = "adventureId") Long adventureId, @PathVariable(value = "questId") Long questId) {
Adventure adventure = this.adventureRepository.findOne(adventureId);
if (adventure != null) {
Quest quest = this.questRepository.findOne(questId);
quest.setAdventure(adventure);
this.questRepository.save(quest);
if (adventure.getWorld() == null) {
adventure.setWorld(quest.getWorld());
this.adventureRepository.save(adventure);
}
adventure = this.adventureRepository.findOne(adventureId);
}
return toAdventureDto(adventure);
}
use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.
the class AdventureController method updateAdventure.
@CrossOrigin
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Adventure updateAdventure(@PathVariable(value = "id") Long id, @RequestBody AdventureDto adventureDto) {
Adventure adventure = this.adventureRepository.findOne(id);
if (adventure != null) {
adventure.setTitle(adventureDto.getTitle());
adventure.setGold(adventureDto.getGold());
adventure.setXp(adventureDto.getXp());
adventure.setStory(adventureDto.getStory());
adventure = this.adventureRepository.save(adventure);
}
return adventure;
}
use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.
the class AdventureService method removeDeveloperFromAdventure.
/**
* Removes the developer from adventure
* @param adventureId
* @param developerId
* @return adventure
*/
public Adventure removeDeveloperFromAdventure(long adventureId, long developerId) {
Adventure adventure = adventureRepository.findOne(adventureId);
final Developer developer = developerRepository.findOne(developerId);
if (adventure != null && developer != null) {
final List<Developer> developerList = adventure.getDevelopers();
if (developerList.contains(developer)) {
developerList.remove(developer);
}
adventure.setDevelopers(developerList);
adventure = adventureRepository.save(adventure);
}
return adventure;
}
Aggregations