Search in sources :

Example 6 with Adventure

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;
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) ArrayList(java.util.ArrayList)

Example 7 with Adventure

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);
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) Developer(com.viadee.sonarQuest.entities.Developer) World(com.viadee.sonarQuest.entities.World)

Example 8 with Adventure

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);
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) Quest(com.viadee.sonarQuest.entities.Quest)

Example 9 with 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;
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure)

Example 10 with 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;
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) Developer(com.viadee.sonarQuest.entities.Developer)

Aggregations

Adventure (com.viadee.sonarQuest.entities.Adventure)10 Developer (com.viadee.sonarQuest.entities.Developer)5 World (com.viadee.sonarQuest.entities.World)3 Quest (com.viadee.sonarQuest.entities.Quest)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)1 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1