Commit 5ee39d5d authored by Jiri Novotny's avatar Jiri Novotny
Browse files

Finish facade upgrade

parent b4859414
Pipeline #140289 passed with stage
in 1 minute and 33 seconds
......@@ -6,6 +6,8 @@ import cz.muni.fi.pa165.dto.AgentListDto;
import cz.muni.fi.pa165.dto.SkillDto;
import org.springframework.data.domain.Page;
import java.util.List;
public interface AgentFacade {
Page<AgentListDto> getMissionAgents(Long missionId, int page, int pageSize);
AgentDetailDto getAgent(Long agentId);
......@@ -14,4 +16,5 @@ public interface AgentFacade {
Page<AgentListDto> getAgentWithCountryXp(Long countryId, int page, int pageSize);
Page<AgentListDto> getAllAgents(int page, int pageSize);
Page<SkillDto> getAllSkills(int page, int pageSize);
List<SkillDto> getAllSkills();
}
......@@ -4,8 +4,11 @@ import cz.muni.fi.pa165.dto.CountryDetailDto;
import cz.muni.fi.pa165.dto.CountryNameDto;
import org.springframework.data.domain.Page;
import java.util.List;
public interface CountryFacade {
CountryNameDto getCountryName(Long missionId);
CountryDetailDto getCountryDetail(Long missionId);
Page<CountryNameDto> getAllCountries(int page, int pageSize);
List<CountryNameDto> getAllCountries();
}
......@@ -3,6 +3,7 @@ package cz.muni.fi.pa165.rest.controller;
import cz.muni.fi.pa165.dto.AgentCountDto;
import cz.muni.fi.pa165.dto.AgentDetailDto;
import cz.muni.fi.pa165.dto.AgentListDto;
import cz.muni.fi.pa165.dto.SkillDto;
import cz.muni.fi.pa165.facade.AgentFacade;
import cz.muni.fi.pa165.rest.ApiUris;
import io.swagger.v3.oas.annotations.Operation;
......@@ -89,4 +90,36 @@ public class AgentController {
return ResponseEntity.notFound().build();
}
}
@Operation(description = "Retrieves all agents in the archive")
@GetMapping("/allAgents")
public final ResponseEntity<List<AgentListDto>> getAllAgents(int page, int pageSize) {
//TODO logged in user logic
try {
return ResponseEntity.ok().body(agentFacade.getAllAgents(page, pageSize).getContent());
} catch (Exception e) {
LOGGER.error("Could not retrieve all agents", e);
return ResponseEntity.notFound().build();
}
}
@Operation(description = "Retrieves all skills of all agents in the archive")
@GetMapping("/allSkills")
public final ResponseEntity<List<SkillDto>> getAllSkills(int page, int pageSize) {
//TODO logged in user logic
if (pageSize == 0) {
try {
return ResponseEntity.ok().body(agentFacade.getAllSkills());
} catch (Exception e) {
LOGGER.error("Could not retrieve all skills", e);
return ResponseEntity.notFound().build();
}
}
try {
return ResponseEntity.ok().body(agentFacade.getAllSkills(page, pageSize).getContent());
} catch (Exception e) {
LOGGER.error("Could not retrieve all skills", e);
return ResponseEntity.notFound().build();
}
}
}
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.rest.controller;
import cz.muni.fi.pa165.dto.CountryDetailDto;
import cz.muni.fi.pa165.dto.CountryNameDto;
import cz.muni.fi.pa165.dto.MissionListDto;
import cz.muni.fi.pa165.facade.CountryFacade;
import cz.muni.fi.pa165.rest.ApiUris;
import io.swagger.v3.oas.annotations.Operation;
......@@ -15,6 +16,8 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(ApiUris.URI_COUNTRIES)
@Tag(name = "Countries", description = "Management of countries")
......@@ -50,4 +53,24 @@ public class CountryController {
return ResponseEntity.notFound().build();
}
}
@Operation(description = "Retrieves all countries in the archive")
@GetMapping("/allCountries")
public final ResponseEntity<List<CountryNameDto>> getAllCountries(int page, int pageSize) {
//TODO logged in user logic
if (pageSize == 0) {
try {
return ResponseEntity.ok().body(countryFacade.getAllCountries());
} catch (Exception e) {
LOGGER.error("Could not retrieve all countries", e);
return ResponseEntity.notFound().build();
}
}
try {
return ResponseEntity.ok().body(countryFacade.getAllCountries(page, pageSize).getContent());
} catch (Exception e) {
LOGGER.error("Could not retrieve all countries", e);
return ResponseEntity.notFound().build();
}
}
}
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.rest.controller;
import cz.muni.fi.pa165.dto.MissionDetailDto;
import cz.muni.fi.pa165.dto.MissionListDto;
import cz.muni.fi.pa165.dto.SkillDto;
import cz.muni.fi.pa165.facade.MissionFacade;
import cz.muni.fi.pa165.rest.ApiUris;
import io.swagger.v3.oas.annotations.Operation;
......@@ -53,4 +54,16 @@ public class MissionController {
}
}
@Operation(description = "Retrieves all missions in the archive")
@GetMapping("/allMissions")
public final ResponseEntity<List<MissionListDto>> getAllMissions(int page, int pageSize) {
//TODO logged in user logic
try {
return ResponseEntity.ok().body(missionFacade.getAllMissions(page, pageSize).getContent());
} catch (Exception e) {
LOGGER.error("Could not retrieve all missions", e);
return ResponseEntity.notFound().build();
}
}
}
......@@ -132,6 +132,12 @@ public class AgentFacadeImpl implements AgentFacade {
return skills.map(skillMapper::map);
}
@Override
public List<SkillDto> getAllSkills() {
List<Skill> skills = skillService.findAll();
return skills.stream().map(skillMapper::map).collect(Collectors.toList());
}
private Page<AgentListDto> createPage(List<Agent> agents, Pageable pageable) {
List<AgentListDto> mappedAgents = agents.stream().map(agentListMapper::map).collect(Collectors.toList());
final int start = (int) pageable.getOffset();
......
......@@ -5,6 +5,7 @@ import cz.muni.fi.pa165.config.CountryNameMapper;
import cz.muni.fi.pa165.dto.CountryDetailDto;
import cz.muni.fi.pa165.dto.CountryNameDto;
import cz.muni.fi.pa165.entity.Country;
import cz.muni.fi.pa165.entity.Skill;
import cz.muni.fi.pa165.service.CountryService;
import cz.muni.fi.pa165.service.MissionService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,6 +14,9 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Samuel Kulisek, 485087
*/
......@@ -53,4 +57,10 @@ public class CountryFacadeImpl implements CountryFacade {
Page<Country> countries = countryService.findAll(pageable);
return countries.map(countryNameMapper::map);
}
@Override
public List<CountryNameDto> getAllCountries() {
List<Country> skills = countryService.findAll();
return skills.stream().map(countryNameMapper::map).collect(Collectors.toList());
}
}
package cz.muni.fi.pa165.service;
import cz.muni.fi.pa165.entity.Country;
import cz.muni.fi.pa165.entity.Skill;
import cz.muni.fi.pa165.repository.CountryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Samuel Kulisek, 485087
*/
......@@ -27,6 +30,10 @@ public class CountryService {
return countryRepository.findAll(page);
}
public List<Country> findAll() {
return countryRepository.findAll();
}
public Long create(Country country) {
return countryRepository.save(country).getId();
}
......
......@@ -8,6 +8,8 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Samuel Kulisek, 485087
*/
......@@ -28,6 +30,10 @@ public class SkillService {
return skillRepository.findAll(page);
}
public List<Skill> findAll() {
return skillRepository.findAll();
}
public Page<Skill> findByType(SkillType type, Pageable page) {
return skillRepository.findAllByType(type, page);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment