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

Rename orderInTrainingDefinition field to order in BaseLevel entity, set...

Rename orderInTrainingDefinition field to order in BaseLevel entity, set trainingDefinitionId when creating a new entity
parent ba4eb276
No related branches found
No related tags found
No related merge requests found
package com.example.demo.domain; package com.example.demo.domain;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
...@@ -23,7 +24,9 @@ public abstract class BaseLevel { ...@@ -23,7 +24,9 @@ public abstract class BaseLevel {
private String title; private String title;
private String estimatedDuration; private String estimatedDuration;
private Long maxScore; private Long maxScore;
private Integer orderInTrainingDefinition;
@Column(name = "order_in_training_definition", nullable = false)
private Integer order;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private PhaseLevel phaseLevel; private PhaseLevel phaseLevel;
...@@ -54,12 +57,12 @@ public abstract class BaseLevel { ...@@ -54,12 +57,12 @@ public abstract class BaseLevel {
this.maxScore = maxScore; this.maxScore = maxScore;
} }
public Integer getOrderInTrainingDefinition() { public Integer getOrder() {
return orderInTrainingDefinition; return order;
} }
public void setOrderInTrainingDefinition(Integer orderInTrainingDefinition) { public void setOrder(Integer order) {
this.orderInTrainingDefinition = orderInTrainingDefinition; this.order = order;
} }
public Long getId() { public Long getId() {
......
...@@ -31,29 +31,22 @@ public interface BeanMapper { ...@@ -31,29 +31,22 @@ public interface BeanMapper {
AssessmentLevelDto toDto(AssessmentLevel assessmentLevel); AssessmentLevelDto toDto(AssessmentLevel assessmentLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
AssessmentLevel toEntity(AssessmentLevelDto assessmentLevel); AssessmentLevel toEntity(AssessmentLevelDto assessmentLevel);
GameLevelDto toDto(GameLevel gameLevel); GameLevelDto toDto(GameLevel gameLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
GameLevel toEntity(GameLevelDto gameLevel); GameLevel toEntity(GameLevelDto gameLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
GameLevel toEntity(GameLevelCreateDto gameLevel); GameLevel toEntity(GameLevelCreateDto gameLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
GameLevel toEntity(GameLevelUpdateDto gameLevel); GameLevel toEntity(GameLevelUpdateDto gameLevel);
InfoLevelDto toDto(InfoLevel infoLevel); InfoLevelDto toDto(InfoLevel infoLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
InfoLevel toEntity(InfoLevelDto infoLevel); InfoLevel toEntity(InfoLevelDto infoLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
InfoLevel toEntity(InfoLevelCreateDto gameLevel); InfoLevel toEntity(InfoLevelCreateDto gameLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
InfoLevel toEntity(InfoLevelUpdateDto gameLevel); InfoLevel toEntity(InfoLevelUpdateDto gameLevel);
AttachmentDto toDto(Attachment attachment); AttachmentDto toDto(Attachment attachment);
...@@ -62,33 +55,24 @@ public interface BeanMapper { ...@@ -62,33 +55,24 @@ public interface BeanMapper {
PhaseLevelDto toDto(PhaseLevel phaseLevel); PhaseLevelDto toDto(PhaseLevel phaseLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
PhaseLevel toEntity(PhaseLevelDto phaseLevel); PhaseLevel toEntity(PhaseLevelDto phaseLevel);
@Mapping(target = "orderInTrainingDefinition", source = "order")
AssessmentLevel toAssessmentLevel(GameDefinitionCreateDto gameDefinitionCreateDto); AssessmentLevel toAssessmentLevel(GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
InfoLevel toInfoLevel(GameDefinitionCreateDto gameDefinitionCreateDto); InfoLevel toInfoLevel(GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
GameLevel toGameLevel(GameDefinitionCreateDto gameDefinitionCreateDto); GameLevel toGameLevel(GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
PhaseLevel toPhaseLevel(GameDefinitionCreateDto gameDefinitionCreateDto); PhaseLevel toPhaseLevel(GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
AssessmentLevel updateAssessmentLevel(@MappingTarget AssessmentLevel assessmentLevel, GameDefinitionCreateDto gameDefinitionCreateDto); AssessmentLevel updateAssessmentLevel(@MappingTarget AssessmentLevel assessmentLevel, GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
InfoLevel updateInfoLevel(@MappingTarget InfoLevel infoLevel, GameDefinitionCreateDto gameDefinitionCreateDto); InfoLevel updateInfoLevel(@MappingTarget InfoLevel infoLevel, GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
@Mapping(target = "phaseLevel", ignore = true) @Mapping(target = "phaseLevel", ignore = true)
@Mapping(target = "attachments", ignore = true) // TODO not really sure about this @Mapping(target = "attachments", ignore = true) // TODO not really sure about this
GameLevel updateGameLevel(@MappingTarget GameLevel gameLevel, GameDefinitionCreateDto gameDefinitionCreateDto); GameLevel updateGameLevel(@MappingTarget GameLevel gameLevel, GameDefinitionCreateDto gameDefinitionCreateDto);
@Mapping(target = "orderInTrainingDefinition", source = "order")
@Mapping(target = "subLevels", ignore = true) @Mapping(target = "subLevels", ignore = true)
PhaseLevel updatePhaseLevel(@MappingTarget PhaseLevel phaseLevel, GameDefinitionCreateDto gameDefinitionCreateDto); PhaseLevel updatePhaseLevel(@MappingTarget PhaseLevel phaseLevel, GameDefinitionCreateDto gameDefinitionCreateDto);
......
...@@ -7,6 +7,6 @@ import org.springframework.data.repository.query.Param; ...@@ -7,6 +7,6 @@ import org.springframework.data.repository.query.Param;
public interface BaseLevelRepository extends JpaRepository<BaseLevel, Long> { public interface BaseLevelRepository extends JpaRepository<BaseLevel, Long> {
@Query("SELECT COALESCE(MAX(l.orderInTrainingDefinition), -1) FROM BaseLevel l WHERE l.trainingDefinitionId = :trainingDefinitionId") @Query("SELECT COALESCE(MAX(l.order), -1) FROM BaseLevel l WHERE l.trainingDefinitionId = :trainingDefinitionId")
Integer getCurrentMaxOrder(@Param("trainingDefinitionId") Long trainingDefinitionId); Integer getCurrentMaxOrder(@Param("trainingDefinitionId") Long trainingDefinitionId);
} }
...@@ -7,6 +7,6 @@ import org.springframework.data.repository.query.Param; ...@@ -7,6 +7,6 @@ import org.springframework.data.repository.query.Param;
public interface GameLevelRepository extends JpaRepository<GameLevel, Long> { public interface GameLevelRepository extends JpaRepository<GameLevel, Long> {
@Query("SELECT COALESCE(MAX(g.orderInTrainingDefinition), -1) FROM GameLevel g WHERE g.phaseLevel.id = :phaseId") @Query("SELECT COALESCE(MAX(g.order), -1) FROM GameLevel g WHERE g.phaseLevel.id = :phaseId")
Integer getCurrentMaxOrder(@Param("phaseId") Long phaseId); Integer getCurrentMaxOrder(@Param("phaseId") Long phaseId);
} }
package com.example.demo.service; package com.example.demo.service;
import com.example.demo.domain.AssessmentLevel; import com.example.demo.domain.AssessmentLevel;
import com.example.demo.domain.InfoLevel;
import com.example.demo.dto.AssessmentLevelDto; import com.example.demo.dto.AssessmentLevelDto;
import com.example.demo.dto.InfoLevelDto;
import com.example.demo.mapper.BeanMapper; import com.example.demo.mapper.BeanMapper;
import com.example.demo.repository.AssessmentLevelRepository; import com.example.demo.repository.AssessmentLevelRepository;
import com.example.demo.repository.BaseLevelRepository; import com.example.demo.repository.BaseLevelRepository;
...@@ -23,7 +21,8 @@ public class AssessmentLevelService { ...@@ -23,7 +21,8 @@ public class AssessmentLevelService {
AssessmentLevel assessmentLevel = new AssessmentLevel(); AssessmentLevel assessmentLevel = new AssessmentLevel();
assessmentLevel.setTitle("Title of assessment level"); assessmentLevel.setTitle("Title of assessment level");
assessmentLevel.setOrderInTrainingDefinition(baseLevelRepository.getCurrentMaxOrder(trainingDefinitionId) + 1); assessmentLevel.setTrainingDefinitionId(trainingDefinitionId);
assessmentLevel.setOrder(baseLevelRepository.getCurrentMaxOrder(trainingDefinitionId) + 1);
AssessmentLevel persistedEntity = assessmentLevelRepository.save(assessmentLevel); AssessmentLevel persistedEntity = assessmentLevelRepository.save(assessmentLevel);
......
...@@ -31,7 +31,7 @@ public class GameLevelService { ...@@ -31,7 +31,7 @@ public class GameLevelService {
public GameLevelDto createDefaultGameLevel(Long phaseId) { public GameLevelDto createDefaultGameLevel(Long phaseId) {
GameLevel gameLevel = new GameLevel(); GameLevel gameLevel = new GameLevel();
gameLevel.setTitle("Title of game"); gameLevel.setTitle("Title of game");
gameLevel.setOrderInTrainingDefinition(gameLevelRepository.getCurrentMaxOrder(phaseId) + 1); gameLevel.setOrder(gameLevelRepository.getCurrentMaxOrder(phaseId) + 1);
GameLevel persistedEntity = gameLevelRepository.save(gameLevel); GameLevel persistedEntity = gameLevelRepository.save(gameLevel);
......
...@@ -37,7 +37,8 @@ public class InfoLevelService { ...@@ -37,7 +37,8 @@ public class InfoLevelService {
InfoLevel infoLevel = new InfoLevel(); InfoLevel infoLevel = new InfoLevel();
infoLevel.setContent("Content of info level"); infoLevel.setContent("Content of info level");
infoLevel.setTitle("Title of info level"); infoLevel.setTitle("Title of info level");
infoLevel.setOrderInTrainingDefinition(baseLevelRepository.getCurrentMaxOrder(trainingDefinitionId) + 1); infoLevel.setTrainingDefinitionId(trainingDefinitionId);
infoLevel.setOrder(baseLevelRepository.getCurrentMaxOrder(trainingDefinitionId) + 1);
InfoLevel persistedEntity = infoLevelRepository.save(infoLevel); InfoLevel persistedEntity = infoLevelRepository.save(infoLevel);
......
...@@ -39,11 +39,11 @@ public class LevelOperationsService { ...@@ -39,11 +39,11 @@ public class LevelOperationsService {
return; return;
} }
int fromOrder = levelFrom.get().getOrderInTrainingDefinition(); int fromOrder = levelFrom.get().getOrder();
int toOrder = levelTo.get().getOrderInTrainingDefinition(); int toOrder = levelTo.get().getOrder();
levelFrom.get().setOrderInTrainingDefinition(toOrder); levelFrom.get().setOrder(toOrder);
levelTo.get().setOrderInTrainingDefinition(fromOrder); levelTo.get().setOrder(fromOrder);
baseLevelRepository.save(levelFrom.get()); baseLevelRepository.save(levelFrom.get());
baseLevelRepository.save(levelTo.get()); baseLevelRepository.save(levelTo.get());
......
...@@ -21,7 +21,8 @@ public class PhaseLevelService { ...@@ -21,7 +21,8 @@ public class PhaseLevelService {
PhaseLevel phaseLevel = new PhaseLevel(); PhaseLevel phaseLevel = new PhaseLevel();
phaseLevel.setTitle("Title of assessment level"); phaseLevel.setTitle("Title of assessment level");
phaseLevel.setOrderInTrainingDefinition(baseLevelRepository.getCurrentMaxOrder(trainingDefinitionId) + 1); phaseLevel.setTrainingDefinitionId(trainingDefinitionId);
phaseLevel.setOrder(baseLevelRepository.getCurrentMaxOrder(trainingDefinitionId) + 1);
PhaseLevel persistedEntity = phaseLevelRepository.save(phaseLevel); PhaseLevel persistedEntity = phaseLevelRepository.save(phaseLevel);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment