Skip to content
Snippets Groups Projects
Commit 806d0e64 authored by Jan Tymel's avatar Jan Tymel
Browse files

Change REST API retrieving phases according to the new design

Related to #10
parent 50ee66ca
No related branches found
No related tags found
No related merge requests found
package com.example.demo.controller;
import com.example.demo.dto.BaseLevelDto;
import com.example.demo.dto.InfoLevelUpdateDto;
import com.example.demo.dto.PhaseLevelUpdateDto;
import com.example.demo.dto.QuestionChoiceDto;
import com.example.demo.dto.QuestionChoiceUpdateDto;
......@@ -8,7 +9,6 @@ import com.example.demo.dto.QuestionDto;
import com.example.demo.dto.QuestionUpdateDto;
import com.example.demo.dto.QuestionnaireUpdateDto;
import com.example.demo.dto.TaskUpdateDto;
import com.example.demo.dto.InfoLevelUpdateDto;
import com.example.demo.enums.QuestionType;
import com.example.demo.service.LevelOperationsService;
import io.swagger.annotations.Api;
......@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
......@@ -99,22 +98,22 @@ public class AdaptiveTrainingDefinitionsRestController {
// return levelOperationsService.createLevel(definitionId, levelType);
// }
@ApiOperation(httpMethod = "GET",
value = "Get level by ID",
response = BaseLevelDto.class,
nickname = "getLevel",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Level returned"),
@ApiResponse(code = 500, message = "Unexpected application error")
})
@GetMapping(path = "/levels/{levelId}")
public BaseLevelDto getLevel(
@ApiParam(value = "Level ID", required = true) @PathVariable("levelId") Long levelId) {
return levelOperationsService.getLevel(levelId);
}
// @ApiOperation(httpMethod = "GET",
// value = "Get level by ID",
// response = BaseLevelDto.class,
// nickname = "getLevel",
// produces = MediaType.APPLICATION_JSON_VALUE
// )
// @ApiResponses(value = {
// @ApiResponse(code = 200, message = "Level returned"),
// @ApiResponse(code = 500, message = "Unexpected application error")
// })
// @GetMapping(path = "/levels/{levelId}")
// public BaseLevelDto getLevel(
// @ApiParam(value = "Level ID", required = true) @PathVariable("levelId") Long levelId) {
//
// return levelOperationsService.getLevel(levelId);
// }
@ApiOperation(httpMethod = "PUT",
value = "Update info level",
......
......@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
@RestController
@RequestMapping(value = "/training-definitions/{definitionId}/phases", produces = MediaType.APPLICATION_JSON_VALUE)
......@@ -54,4 +56,45 @@ public class PhasesController {
return new ResponseEntity<>(createdPhase, HttpStatus.CREATED);
}
@ApiOperation(httpMethod = "GET",
value = "Get all phases",
notes = "Get all phases associated with specified training definition",
response = Object.class,
nickname = "getPhases",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Phases returned"),
@ApiResponse(code = 500, message = "Unexpected application error")
})
@GetMapping
public ResponseEntity<List<BaseLevelDto>> getPhases(
@ApiParam(value = "Training definition ID", required = true)
@PathVariable(name = "definitionId") Long definitionId) {
List<BaseLevelDto> phases = levelOperationsService.getPhases(definitionId);
return new ResponseEntity<>(phases, HttpStatus.OK);
}
@ApiOperation(httpMethod = "GET",
value = "Get phase by ID",
response = BaseLevelDto.class,
nickname = "getPhase",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Phase returned"),
@ApiResponse(code = 500, message = "Unexpected application error")
})
@GetMapping(path = "/levels/{levelId}")
public ResponseEntity<BaseLevelDto> getPhase(
@ApiParam(value = "Level ID", required = true) @PathVariable("levelId") Long levelId) {
BaseLevelDto phase = levelOperationsService.getLevel(levelId);
return new ResponseEntity<>(phase, HttpStatus.OK);
}
}
......@@ -34,6 +34,8 @@ import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface BeanMapper {
......@@ -59,6 +61,8 @@ public interface BeanMapper {
return baseLevelDto;
}
List<BaseLevelDto> toDtoList(List<BaseLevel> baseLevel);
AssessmentLevelDto toDto(AssessmentLevel assessmentLevel);
AssessmentLevel toEntity(AssessmentLevelDto assessmentLevel);
......
......@@ -6,8 +6,12 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface BaseLevelRepository extends JpaRepository<BaseLevel, Long> {
List<BaseLevel> findAllByTrainingDefinitionIdOrderByOrder(long trainingDefinitionId);
@Query("SELECT COALESCE(MAX(l.order), -1) FROM BaseLevel l WHERE l.trainingDefinitionId = :trainingDefinitionId")
Integer getCurrentMaxOrder(@Param("trainingDefinitionId") Long trainingDefinitionId);
......
......@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@Service
......@@ -128,6 +129,12 @@ public class LevelOperationsService {
// return createdTask;
// }
public List<BaseLevelDto> getPhases(Long trainingDefinitionId) {
List<BaseLevel> phases = baseLevelRepository.findAllByTrainingDefinitionIdOrderByOrder(trainingDefinitionId);
return BeanMapper.INSTANCE.toDtoList(phases);
}
public BaseLevelDto getLevel(Long levelId) {
Optional<BaseLevel> level = baseLevelRepository.findById(levelId);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment