Search in sources :

Example 1 with Adventure

use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.

the class AdventureService method addDeveloperToAdventure.

/**
 * Add a developer to adventure
 * @param adventureId
 * @param developerId
 * @return adventure
 */
public Adventure addDeveloperToAdventure(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.add(developer);
        }
        adventure.setDevelopers(developerList);
        adventure = adventureRepository.save(adventure);
    }
    return adventure;
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) Developer(com.viadee.sonarQuest.entities.Developer)

Example 2 with Adventure

use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.

the class AdventureServiceTest method testGetAllAdventuresForWorldAndDeveloper.

@Test
public void testGetAllAdventuresForWorldAndDeveloper() {
    // create mock developer
    final Developer mockDeveloper1 = new Developer();
    mockDeveloper1.setUsername("mockUserAdventureServiceTest1");
    // create mock world
    final World mockWorld = new World();
    // create mock Adventure
    final Adventure mockAdventure1 = new Adventure();
    final Adventure mockAdventure2 = new Adventure();
    final Adventure mockAdventure3 = new Adventure();
    mockAdventure1.setTitle("mockAdventure1");
    mockAdventure2.setTitle("mockAdventure2");
    mockAdventure3.setTitle("mockAdventure3");
    mockAdventure1.setWorld(mockWorld);
    mockAdventure2.setWorld(mockWorld);
    mockAdventure3.setWorld(mockWorld);
    // a Adventure has a Developers
    mockAdventure1.addDeveloper(mockDeveloper1);
    mockAdventure2.addDeveloper(mockDeveloper1);
    // init mock repos
    final List<Adventure> adventuresByDeveloperAndWorld = new ArrayList<>();
    adventuresByDeveloperAndWorld.add(mockAdventure1);
    adventuresByDeveloperAndWorld.add(mockAdventure2);
    final List<Adventure> adventuresByWorld = new ArrayList<>();
    adventuresByWorld.add(mockAdventure1);
    adventuresByWorld.add(mockAdventure2);
    adventuresByWorld.add(mockAdventure3);
    final List<Developer> developers = new ArrayList<>();
    developers.add(mockDeveloper1);
    when(adventureRepository.findByDevelopersAndWorld(developers, mockWorld)).thenReturn(adventuresByDeveloperAndWorld);
    when(adventureRepository.findByWorld(mockWorld)).thenReturn(adventuresByWorld);
    // call method to be tested
    final List<Adventure> joinedAdventures = adventureService.getJoinedAdventuresForDeveloperInWorld(mockWorld, mockDeveloper1);
    final List<Adventure> freeAdventures = adventureService.getFreeAdventuresForDeveloperInWorld(mockWorld, mockDeveloper1);
    // verify result
    assertTrue(joinedAdventures.contains(mockAdventure1));
    assertTrue(joinedAdventures.contains(mockAdventure2));
    assertTrue(freeAdventures.contains(mockAdventure3));
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) ArrayList(java.util.ArrayList) Developer(com.viadee.sonarQuest.entities.Developer) World(com.viadee.sonarQuest.entities.World) Test(org.junit.Test)

Example 3 with Adventure

use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.

the class AdventureController method getJoinedAdventures.

@RequestMapping(value = "/getJoined/{developer_id}/{world_id}", method = RequestMethod.GET)
public List<AdventureDto> getJoinedAdventures(@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.getJoinedAdventuresForDeveloperInWorld(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 4 with Adventure

use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.

the class AdventureController method solveAdventure.

@RequestMapping(value = "/{adventureId}/solveAdventure/", method = RequestMethod.PUT)
public void solveAdventure(@PathVariable(value = "adventureId") Long adventureId) {
    Adventure adventure = this.adventureRepository.findOne(adventureId);
    if (adventure != null) {
        adventure.setStatus(AdventureStates.SOLVED);
        adventureRepository.save(adventure);
        gratificationService.rewardDevelopersForSolvingAdventure(adventure);
    }
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure)

Example 5 with Adventure

use of com.viadee.sonarQuest.entities.Adventure in project sonarQuest by viadee.

the class QuestController method addAdventure.

@CrossOrigin
@RequestMapping(value = "/{questId}/addAdventure/{adventureId}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public QuestDto addAdventure(@PathVariable(value = "questId") final Long questId, @PathVariable(value = "adventureId") final Long adventureId) {
    Quest quest = this.questRepository.findOne(questId);
    if (quest != null) {
        final Adventure adventure = this.adventureRepository.findOne(adventureId);
        quest.setAdventure(adventure);
        quest = this.questRepository.save(quest);
    }
    return toQuestDto(quest);
}
Also used : Adventure(com.viadee.sonarQuest.entities.Adventure) Quest(com.viadee.sonarQuest.entities.Quest) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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