From 38acba63620573dfd4e4361b45ecc6ce04ee15ba Mon Sep 17 00:00:00 2001 From: denniskp <122602355+denniskp@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:24:41 +0200 Subject: [PATCH] fix: image check --- .../de/tinf22b6/dhbwhub/service/PostServiceImpl.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java b/src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java index 23aacb89..d351768b 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java +++ b/src/main/java/de/tinf22b6/dhbwhub/service/PostServiceImpl.java @@ -71,19 +71,20 @@ public Post create(PostProposal proposal) { public HomepagePostPreviewProposal create(CreatePostProposal proposal) { // Creating the Post itself User user = userRepository.findByAccountId(proposal.getAccountId()); - if(user == null){ + if (user == null) { throw new NoSuchEntryException("User with the AccountId " + proposal.getAccountId() + " does not exist!"); } - Picture picture = !proposal.getPostImage().isEmpty() ? - pictureRepository.save(PictureMapper.mapToModelPost(proposal.getPostImage())): null; - Post post = repository.save(PostMapper.mapToModel(proposal,user,picture)); + Picture picture = proposal.getPostImage() != null ? + pictureRepository.save(PictureMapper.mapToModelPost(proposal.getPostImage())) : null; + + Post post = repository.save(PostMapper.mapToModel(proposal, user, picture)); // Creating Tags after the Post is created Arrays.stream(proposal.getTags()).forEach(t -> { PostTag postTag = new PostTag(post, t); postTagRepository.save(postTag); - } ); + }); return getPostHomepageView(post.getId()); }