diff --git a/.gradle/7.2/executionHistory/executionHistory.bin b/.gradle/7.2/executionHistory/executionHistory.bin index 16b66f5b..7a16417a 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.bin and b/.gradle/7.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.2/executionHistory/executionHistory.lock b/.gradle/7.2/executionHistory/executionHistory.lock index 396fd643..9df77ea6 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.lock and b/.gradle/7.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.2/fileHashes/fileHashes.bin b/.gradle/7.2/fileHashes/fileHashes.bin index 9d7830c7..fb20c0d9 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.bin and b/.gradle/7.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.2/fileHashes/fileHashes.lock b/.gradle/7.2/fileHashes/fileHashes.lock index 812ac770..afa429da 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.lock and b/.gradle/7.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.2/fileHashes/resourceHashesCache.bin b/.gradle/7.2/fileHashes/resourceHashesCache.bin index 3944155a..a8ec9827 100644 Binary files a/.gradle/7.2/fileHashes/resourceHashesCache.bin and b/.gradle/7.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 4efe3edd..c0ed5ea2 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java b/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java index 4ebf5c5a..6fa3653b 100644 --- a/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java +++ b/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java @@ -10,8 +10,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2023-10-28T15:14:51+0900", - comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)" + date = "2023-10-28T16:41:57+0900", + comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 17.0.9 (Homebrew)" ) @Component public class MemberMapperImpl implements MemberMapper { diff --git a/src/main/generated/com/example/just/Mapper/PostMapperImpl.java b/src/main/generated/com/example/just/Mapper/PostMapperImpl.java index 3f06f612..aa85422b 100644 --- a/src/main/generated/com/example/just/Mapper/PostMapperImpl.java +++ b/src/main/generated/com/example/just/Mapper/PostMapperImpl.java @@ -3,7 +3,7 @@ import com.example.just.Dao.Comment; import com.example.just.Dao.Member; import com.example.just.Dao.Post; -import com.example.just.Dto.PostDto; +import com.example.just.Dto.PutPostDto; import java.util.ArrayList; import java.util.List; import javax.annotation.processing.Generated; @@ -11,14 +11,14 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2023-10-28T15:14:51+0900", - comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)" + date = "2023-10-28T16:41:57+0900", + comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 17.0.9 (Homebrew)" ) @Component public class PostMapperImpl implements PostMapper { @Override - public Post toEntity(PostDto dto) { + public Post toEntity(PutPostDto dto) { if ( dto == null ) { return null; } @@ -30,7 +30,6 @@ public Post toEntity(PostDto dto) { post.setPost_tag( dto.getPost_tag() ); post.setPost_picture( dto.getPost_picture() ); post.setPost_create_time( dto.getPost_create_time() ); - post.setPost_like( dto.getPost_like() ); post.setSecret( dto.getSecret() ); post.setEmoticon( dto.getEmoticon() ); post.setPost_category( dto.getPost_category() ); @@ -43,39 +42,36 @@ public Post toEntity(PostDto dto) { if ( list1 != null ) { post.setComments( new ArrayList( list1 ) ); } - post.setBlamedCount( dto.getBlamedCount() ); return post; } @Override - public PostDto toDto(Post entity) { + public PutPostDto toDto(Post entity) { if ( entity == null ) { return null; } - PostDto postDto = new PostDto(); + PutPostDto putPostDto = new PutPostDto(); - postDto.setPost_id( entity.getPost_id() ); - postDto.setPost_content( entity.getPost_content() ); - postDto.setPost_tag( entity.getPost_tag() ); - postDto.setPost_like( entity.getPost_like() ); - postDto.setPost_picture( entity.getPost_picture() ); - postDto.setPost_create_time( entity.getPost_create_time() ); - postDto.setSecret( entity.getSecret() ); - postDto.setEmoticon( entity.getEmoticon() ); - postDto.setPost_category( entity.getPost_category() ); + putPostDto.setPost_id( entity.getPost_id() ); + putPostDto.setPost_content( entity.getPost_content() ); + putPostDto.setPost_tag( entity.getPost_tag() ); + putPostDto.setPost_picture( entity.getPost_picture() ); + putPostDto.setPost_create_time( entity.getPost_create_time() ); + putPostDto.setSecret( entity.getSecret() ); + putPostDto.setEmoticon( entity.getEmoticon() ); + putPostDto.setPost_category( entity.getPost_category() ); List list = entity.getLikedMembers(); if ( list != null ) { - postDto.setLikedMembers( new ArrayList( list ) ); + putPostDto.setLikedMembers( new ArrayList( list ) ); } - postDto.setMember( entity.getMember() ); + putPostDto.setMember( entity.getMember() ); List list1 = entity.getComments(); if ( list1 != null ) { - postDto.setComments( new ArrayList( list1 ) ); + putPostDto.setComments( new ArrayList( list1 ) ); } - postDto.setBlamedCount( entity.getBlamedCount() ); - return postDto; + return putPostDto; } } diff --git a/src/main/java/com/example/just/Controller/PostController.java b/src/main/java/com/example/just/Controller/PostController.java index af842927..8e90fc67 100644 --- a/src/main/java/com/example/just/Controller/PostController.java +++ b/src/main/java/com/example/just/Controller/PostController.java @@ -2,6 +2,8 @@ import com.example.just.Dto.PostDto; +import com.example.just.Dto.PostPostDto; +import com.example.just.Dto.PutPostDto; import com.example.just.Service.PostService; import com.example.just.Service.ResponseGetPost; import com.example.just.Service.ResponsePost; @@ -37,6 +39,7 @@ public ResponseGetPost getPosts(@RequestParam Long request_page, Long member_id = Long.valueOf(jwtProvider.getIdFromToken(token)); //토큰 String cursor = req.getHeader("viewed"); + return postService.searchByCursor(cursor, request_page, member_id); } @@ -55,11 +58,11 @@ public ResponseEntity> getMyPosts( */ - @Operation(summary = "게시글 작성 api", description = "post_content, post_tag는 null값이 발생하면" + - " 안됨\n" + "다른 건 null이와도 예외처리 완료\n 자기가 쓴 글이면 true") + @Operation(summary = "게시글 작성 api", description = "RequestBody에 null값이 있으면 안됨" + + "\n 공개글이면 true 아니라면 false") @PostMapping("/post/post") public ResponsePost write(HttpServletRequest request, - @RequestBody PostDto postDto) { + @RequestBody PostPostDto postDto) { String token = jwtProvider.getAccessToken(request); System.out.println(token + "ㅋㅋ"); Long member_id = Long.valueOf(jwtProvider.getIdFromToken(token)); //토큰 @@ -75,12 +78,12 @@ public ResponsePost deletePost(@RequestParam Long post_id) { @Operation(summary = "게시글 수정 api", description = "JSON넘길 때 null이 하나도 있으면 안됨 꼭 다채워서 넘기기") @PutMapping("/put/post") - public ResponsePost putPost(@RequestParam Long post_id, HttpServletRequest request, - @RequestBody PostDto postDto) { + public ResponsePost putPost(HttpServletRequest request, + @RequestBody PutPostDto postDto) { String token = jwtProvider.getAccessToken(request); Long member_id = Long.valueOf(jwtProvider.getIdFromToken(token)); //토큰 - return postService.putPost(post_id, member_id, postDto); + return postService.putPost(member_id, postDto); } @Operation(summary = "게시글 좋아요 api", description = "\n 자기가 좋아요 한 글이면 true") diff --git a/src/main/java/com/example/just/Mapper/PostMapper.java b/src/main/java/com/example/just/Mapper/PostMapper.java index 529ae33e..673b8734 100644 --- a/src/main/java/com/example/just/Mapper/PostMapper.java +++ b/src/main/java/com/example/just/Mapper/PostMapper.java @@ -2,8 +2,10 @@ import com.example.just.Dao.Post; import com.example.just.Dto.PostDto; +import com.example.just.Dto.PostPostDto; +import com.example.just.Dto.PutPostDto; import org.mapstruct.Mapper; @Mapper(componentModel = "spring") -public interface PostMapper extends EntityMapper{ +public interface PostMapper extends EntityMapper{ } diff --git a/src/main/java/com/example/just/Service/PostService.java b/src/main/java/com/example/just/Service/PostService.java index b2d8ea23..2f79ee62 100644 --- a/src/main/java/com/example/just/Service/PostService.java +++ b/src/main/java/com/example/just/Service/PostService.java @@ -1,8 +1,11 @@ package com.example.just.Service; + import com.example.just.Dao.Member; import com.example.just.Dao.Post; import com.example.just.Dao.QPost; import com.example.just.Dto.PostDto; +import com.example.just.Dto.PostPostDto; +import com.example.just.Dto.PutPostDto; import com.example.just.Impl.MySliceImpl; import com.example.just.Mapper.PostMapper; import com.example.just.Repository.MemberRepository; @@ -21,7 +24,6 @@ import java.util.stream.Collectors; - @Service public class PostService { @@ -46,7 +48,7 @@ public PostService(EntityManager em, JPAQueryFactory query) { } - public ResponsePost write(Long member_id, PostDto postDto) { //글 작성 + public ResponsePost write(Long member_id, PostPostDto postDto) { //글 작성 Optional optionalMember = memberRepository.findById(member_id); if (!optionalMember.isPresent()) { //아이디 없을시 예외처리 @@ -67,7 +69,6 @@ public ResponsePost write(Long member_id, PostDto postDto) { //글 작성 } - //글 삭제 @Transactional public ResponsePost deletePost(Long post_id) { @@ -76,7 +77,6 @@ public ResponsePost deletePost(Long post_id) { throw new NoSuchElementException("post_id의 값이 DB에 존재하지 않습니다:" + post_id); } Post post = optionalPost.get(); - post.setMember(null); try { postRepository.delete(post); } catch (Exception e) { @@ -87,7 +87,9 @@ public ResponsePost deletePost(Long post_id) { } //글 수정 - public ResponsePost putPost(Long post_id, Long member_id, PostDto postDto) { + public ResponsePost putPost(Long member_id, PutPostDto postDto) { + Long post_id = postDto.getPost_id(); + System.out.println(post_id); Optional optionalPost = postRepository.findById(post_id); if (!optionalPost.isPresent()) { //아이디 없을시 예외처리 throw new NoSuchElementException("post_id의 값이 DB에 존재하지 않습니다:" + post_id); @@ -96,10 +98,13 @@ public ResponsePost putPost(Long post_id, Long member_id, PostDto postDto) { if (!optionalMember.isPresent()) { //아이디 없을시 예외처리 throw new NoSuchElementException("DB에 존재하지 않는 ID : " + member_id); } + postDto.setPost_create_time(new Timestamp(System.currentTimeMillis())); + Member member = optionalMember.get(); //존재한다면 객체 생성 postDto.setMember(member); Post post = postMapper.toEntity(postDto); + post.setPost_like(optionalPost.get().getPost_like()); postRepository.save(post); ResponsePost responsePost = new ResponsePost(post, true); return responsePost; @@ -107,7 +112,6 @@ public ResponsePost putPost(Long post_id, Long member_id, PostDto postDto) { public ResponseGetPost searchByCursor(String cursor, Long limit, Long member_id) { //글 조 - QPost post = QPost.post; Set viewedPostIds = new HashSet<>(); @@ -116,7 +120,7 @@ public ResponseGetPost searchByCursor(String cursor, Long limit, Long member_id) String[] viewedPostIdsArray = cursor.split(","); viewedPostIds = new HashSet<>(); for (String viewedPostId : viewedPostIdsArray) { - viewedPostIds.add(Long.parseLong(viewedPostId)); + viewedPostIds.add(Long.parseLong(viewedPostId.trim())); } } @@ -128,7 +132,6 @@ public ResponseGetPost searchByCursor(String cursor, Long limit, Long member_id) .orderBy(Expressions.numberTemplate(Double.class, "function('rand')").asc()) .limit(limit + 1) .fetch(); - // 가져온 글들의 ID를 저장합니다. Set resultPostIds = results.stream().map(Post::getPost_id).collect(Collectors.toSet()); viewedPostIds.addAll(resultPostIds); @@ -146,7 +149,8 @@ public ResponseGetPost searchByCursor(String cursor, Long limit, Long member_id) } // Slice 객체를 생성해서 반환합니다. - ResponseGetPost responseGetPost = new ResponseGetPost(new MySliceImpl<>(results, PageRequest.of(0, Math.toIntExact(limit)), hasNext, nextCursor), false); + ResponseGetPost responseGetPost = new ResponseGetPost( + new MySliceImpl<>(results, PageRequest.of(0, Math.toIntExact(limit)), hasNext, nextCursor), false); return responseGetPost; } @@ -182,12 +186,9 @@ public Slice searchByMyPost(Long limit, Long member_id) { */ - - @Transactional public ResponsePost postLikes(Long post_id, Long member_id) { //글 좋아요 - Optional optionalPost = postRepository.findById(post_id); if (!optionalPost.isPresent()) { //아이디 없을시 예외처리 throw new NoSuchElementException("post_id의 값이 DB에 존재하지 않습니다:" + post_id); diff --git a/src/main/java/com/example/just/Service/ResponseGetPost.java b/src/main/java/com/example/just/Service/ResponseGetPost.java index 75c755e5..6003c900 100644 --- a/src/main/java/com/example/just/Service/ResponseGetPost.java +++ b/src/main/java/com/example/just/Service/ResponseGetPost.java @@ -2,7 +2,10 @@ import com.example.just.Dao.Post; import com.example.just.Impl.MySliceImpl; +import lombok.Getter; +import org.springframework.web.bind.annotation.GetMapping; +@Getter public class ResponseGetPost { private MySliceImpl mySlice; private boolean value;