diff --git a/src/main/java/at/fh/joanneum/irfc/service/EventInfoService.java b/src/main/java/at/fh/joanneum/irfc/service/EventInfoService.java index c1b1b70..eb7e236 100644 --- a/src/main/java/at/fh/joanneum/irfc/service/EventInfoService.java +++ b/src/main/java/at/fh/joanneum/irfc/service/EventInfoService.java @@ -76,19 +76,18 @@ public EventInfoDTO update(Long id, EventInfoDTO eventInfoDTO) { private void setValues(EventInfoDTO eventInfoDTO, EventInfoEntity newEntity) { newEntity.setInfoText(eventInfoDTO.getInfoText()); - Set pictures; - if(newEntity.getPictures() != null) { - pictures = newEntity.getPictures(); - } else { + Set pictures = newEntity.getPictures(); + if (pictures == null) { pictures = new HashSet<>(); } - for(PictureDTO picture : eventInfoDTO.getPictures()) { + for (PictureDTO picture : eventInfoDTO.getPictures()) { Optional pictureOptional = this.pictureRepository.findByIdOptional(picture.getPictureId()); - if(pictureOptional.isEmpty()){ - throw new RuntimeException("no Picture with id "+ picture.getPictureId()); + if (pictureOptional.isEmpty()) { + throw new RuntimeException("No Picture with id " + picture.getPictureId()); } else { - PictureEntity pictureEntity = PictureMapper.INSTANCE.toEntity(picture); + PictureEntity pictureEntity = pictureOptional.get(); + pictureEntity.setEventInfo(newEntity); pictures.add(pictureEntity); } } diff --git a/src/main/java/at/fh/joanneum/irfc/service/EventService.java b/src/main/java/at/fh/joanneum/irfc/service/EventService.java index cfebe10..a20e1c7 100644 --- a/src/main/java/at/fh/joanneum/irfc/service/EventService.java +++ b/src/main/java/at/fh/joanneum/irfc/service/EventService.java @@ -2,6 +2,7 @@ import at.fh.joanneum.irfc.model.event.EventDTO; import at.fh.joanneum.irfc.model.event.EventMapper; +import at.fh.joanneum.irfc.model.eventInfo.EventInfoDTO; import at.fh.joanneum.irfc.persistence.entiy.*; import at.fh.joanneum.irfc.persistence.repository.*; @@ -31,8 +32,10 @@ public class EventService { EventInfoRepository eventInfoRepository; @Inject EventCategoryRepository eventCategoryRepository; + @Inject + EventInfoService eventInfoService; - public List getAll() { + public List getAll() { //TODO throws exception (pls fix) return eventRepository.listAll().stream() .map(EventMapper.INSTANCE::toDto) .collect(Collectors.toUnmodifiableList()); @@ -47,7 +50,6 @@ public EventDTO get(Long id) { @Transactional public EventDTO create(EventDTO eventDTO) { - checkDTOvalues(eventDTO); EventEntity newEntity = new EventEntity(); @@ -126,12 +128,16 @@ private void setValues(EventDTO eventDTOCreate, EventEntity newEntity) { } if(eventDTOCreate.getEventInfo() != null) { - Optional eventInfoOptional = this.eventInfoRepository.findByIdOptional(eventDTOCreate.getEventInfo().getEventInfoId()); + Long eventInfoId = eventDTOCreate.getEventInfo().getEventInfoId(); + if(isNull(eventInfoId)) { + eventInfoId = 0l; + } + Optional eventInfoOptional = this.eventInfoRepository.findByIdOptional(eventInfoId); if (eventInfoOptional.isEmpty()) { - throw new RuntimeException("no EventInfo with id " + eventDTOCreate.getEventInfo().getEventInfoId()); - } else { - newEntity.setEventInfo(eventInfoOptional.get()); + EventInfoDTO eventInfoDto= this.eventInfoService.create(eventDTOCreate.getEventInfo()); + eventInfoOptional = this.eventInfoRepository.findByIdOptional(eventInfoDto.getEventInfoId()); } + newEntity.setEventInfo(eventInfoOptional.get()); } else { throw new RuntimeException("no EventInfo"); } diff --git a/src/main/java/at/fh/joanneum/irfc/service/PictureService.java b/src/main/java/at/fh/joanneum/irfc/service/PictureService.java index 58b9b21..42fd744 100644 --- a/src/main/java/at/fh/joanneum/irfc/service/PictureService.java +++ b/src/main/java/at/fh/joanneum/irfc/service/PictureService.java @@ -36,6 +36,9 @@ public class PictureService { @ConfigProperty(name="pictures.root_path") String pictureRootPath; + @ConfigProperty(name="pictures.url") //TODO replace this with an .env var + String pictureUrl; + public PictureDTO get(Long id) { Optional byIdOptional = pictureRepository.findByIdOptional(id); if(byIdOptional.isEmpty()){ @@ -83,7 +86,7 @@ public void delete(Long id) { try { - File f= new File(pictureRootPath + pictureDto.getPath()); + File f= new File(pictureDto.getPath().replace(pictureUrl, pictureRootPath)); if(!f.delete()) { throw new RuntimeException("Picture with Path " + pictureDto.getPath() + " could not be deleted"); @@ -107,11 +110,12 @@ public PictureDTO create(MultipartBody data) { PictureEntity newEntity = new PictureEntity(); try { - File targetFile = new File(pictureRootPath + UUID.randomUUID() + "." + data.getFileEndingType().name().toLowerCase()); + String fileName = UUID.randomUUID() + "." + data.getFileEndingType().name().toLowerCase(); + File targetFile = new File(pictureRootPath + fileName); OutputStream outStream = new FileOutputStream(targetFile); outStream.write(data.file.readAllBytes()); outStream.close(); - pictureDTO.setPath(pictureRootPath + targetFile.getPath()); + pictureDTO.setPath(pictureUrl + fileName); } catch (IOException e) { throw new RuntimeException("Error storing Image"); } diff --git a/src/main/java/at/fh/joanneum/irfc/service/VotingService.java b/src/main/java/at/fh/joanneum/irfc/service/VotingService.java index c7485e7..55583d3 100644 --- a/src/main/java/at/fh/joanneum/irfc/service/VotingService.java +++ b/src/main/java/at/fh/joanneum/irfc/service/VotingService.java @@ -122,6 +122,7 @@ public VotingDTO endVoting(Long id) { } byId.setActive(false); VotingResultEntity votingResult = new VotingResultEntity(); + votingResult.setTitle(byId.getTitle()); votingResult.setVoting(byId); votingResult.setEndDate(Instant.now().toEpochMilli()); //TODO check if this is correct votingResultRepository.persist(votingResult); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 26f0b93..e77d631 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -60,6 +60,7 @@ quarkus: pictures: root_path: ${PICTURES_ROOT_PATH:C:/temp/pics/} + url: https://tmp.at/ # container-image: diff --git a/src/main/resources/db/53-add-fields.xml b/src/main/resources/db/53-add-fields.xml index e26b0a6..8457ab8 100644 --- a/src/main/resources/db/53-add-fields.xml +++ b/src/main/resources/db/53-add-fields.xml @@ -38,5 +38,9 @@ constraintName="fk_voting_event_event" onDelete="CASCADE"/> + + \ No newline at end of file