Skip to content

Commit

Permalink
Merge pull request #167 from pknu-wap/feature/또또추가사항
Browse files Browse the repository at this point in the history
prPost 작성 시 prid만 받기
  • Loading branch information
JONG-KYEONG authored Nov 29, 2023
2 parents 0f98081 + 7852875 commit bf4fd58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.project.Glog.repository;

import com.project.Glog.domain.Category;
import com.project.Glog.domain.Post;
import com.project.Glog.domain.PrPost;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -23,4 +24,7 @@ public interface PrPostRepository extends JpaRepository<PrPost, Long> {
@Query("SELECT pr FROM PrPost pr WHERE pr.id=:prId")
Optional<PrPost> findPrByPrId( @Param("prId") Long prId);

@Query("SELECT p.category FROM PrPost p WHERE p.category.id=:PrId")
Category findByPrId(@Param("PrId") Long PrId);

}
14 changes: 8 additions & 6 deletions server/src/main/java/com/project/Glog/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,29 @@ public class PostService {

public Post create(UserPrincipal userPrincipal, MultipartFile multipartFile, PostCreateRequest req) throws IOException {
User user = userRepository.findById(userPrincipal.getId()).get();
Category category = categoryRepository.findById(req.getCategoryId()).get();
Blog blog = blogRepository.findByUserId(userPrincipal.getId()).get();
Post post = req.toPost(user, category, blog);
Post post;


//image
if (!multipartFile.isEmpty())
post.setThumbnail(awsUtils.upload(multipartFile, "thumbnail").getPath());

if (req.getPrId() != null) {
PrPost prPost = prPostRepository.findPrByPrId(req.getPrId()).get();
Category ct = prPostRepository.findByPrId(req.getPrId());
post = req.toPost(user, ct, blog);
post.setPrPost(prPost);
post.setIsPr(true);
prPost.setIsPosted(true);
prPost.setPost(post);
postRepository.save(post);
prPostRepository.save(prPost);
} else {
Category category = categoryRepository.findById(req.getCategoryId()).get();
post = req.toPost(user, category, blog);
post.setIsPr(false);
postRepository.save(post);
}
//image
if (!multipartFile.isEmpty())
post.setThumbnail(awsUtils.upload(multipartFile, "thumbnail").getPath());

//hashtags

Expand Down

0 comments on commit bf4fd58

Please sign in to comment.