-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 유저픽 게시글 삭제 기능 구현 #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/ftm/server/adapter/in/web/post/controller/DeletePostController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.ftm.server.adapter.in.web.post.controller; | ||
|
|
||
| import com.ftm.server.application.command.post.DeletePostCommand; | ||
| import com.ftm.server.application.port.in.post.DeletePostUseCase; | ||
| import com.ftm.server.common.response.ApiResponse; | ||
| import com.ftm.server.common.response.enums.SuccessResponseCode; | ||
| import com.ftm.server.infrastructure.security.UserPrincipal; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class DeletePostController { | ||
|
|
||
| private final DeletePostUseCase deletePostUseCase; | ||
|
|
||
| @DeleteMapping("/api/posts/{postId}") | ||
| public ResponseEntity<ApiResponse<Void>> deletePost( | ||
| @PathVariable Long postId, @AuthenticationPrincipal UserPrincipal userPrincipal) { | ||
|
|
||
| deletePostUseCase.execute(DeletePostCommand.of(postId, userPrincipal.getId())); | ||
| return ResponseEntity.status(HttpStatus.OK) | ||
| .body(ApiResponse.success(SuccessResponseCode.OK)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/ftm/server/adapter/out/persistence/repository/PostCustomRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.ftm.server.adapter.out.persistence.repository; | ||
|
|
||
| import com.ftm.server.adapter.out.persistence.model.PostJpaEntity; | ||
| import com.ftm.server.application.query.FindPostByDeleteOptionQuery; | ||
| import java.util.List; | ||
|
|
||
| public interface PostCustomRepository { | ||
|
|
||
| List<PostJpaEntity> findAllByDeletedBefore(FindPostByDeleteOptionQuery query); | ||
| } |
28 changes: 28 additions & 0 deletions
28
...main/java/com/ftm/server/adapter/out/persistence/repository/PostCustomRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.ftm.server.adapter.out.persistence.repository; | ||
|
|
||
| import static com.ftm.server.adapter.out.persistence.model.QPostJpaEntity.postJpaEntity; | ||
|
|
||
| import com.ftm.server.adapter.out.persistence.model.PostJpaEntity; | ||
| import com.ftm.server.application.query.FindPostByDeleteOptionQuery; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import java.time.LocalTime; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class PostCustomRepositoryImpl implements PostCustomRepository { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| @Override | ||
| public List<PostJpaEntity> findAllByDeletedBefore(FindPostByDeleteOptionQuery query) { | ||
| return queryFactory | ||
| .selectFrom(postJpaEntity) | ||
| .where( | ||
| postJpaEntity.isDeleted.eq(query.getIsDeleted()), | ||
| postJpaEntity.deletedAt.loe(query.getDeletedAt().atTime(LocalTime.MAX))) | ||
| .fetch(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...a/com/ftm/server/adapter/out/persistence/repository/PostProductImageCustomRepository.java
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...m/ftm/server/adapter/out/persistence/repository/PostProductImageCustomRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
14 changes: 12 additions & 2 deletions
14
...in/java/com/ftm/server/adapter/out/persistence/repository/PostProductImageRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| package com.ftm.server.adapter.out.persistence.repository; | ||
|
|
||
| import com.ftm.server.adapter.out.persistence.model.PostProductImageJpaEntity; | ||
| import io.lettuce.core.dynamic.annotation.Param; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
| public interface PostProductImageRepository | ||
| extends JpaRepository<PostProductImageJpaEntity, Long>, PostProductImageCustomRepository {} | ||
| public interface PostProductImageRepository extends JpaRepository<PostProductImageJpaEntity, Long> { | ||
|
|
||
| List<PostProductImageJpaEntity> findAllByPostProductIdIn(List<Long> postProductIds); | ||
|
|
||
| @Modifying | ||
| @Query("DELETE FROM PostProductImageJpaEntity ppi WHERE ppi.id IN (:postProductImageIds)") | ||
| void deleteAllByIdInBatch(@Param("postProductImageIds") List<Long> postProductImageIds); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/ftm/server/adapter/out/scheduler/PostHardDeleteScheduler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.ftm.server.adapter.out.scheduler; | ||
|
|
||
| import com.ftm.server.application.port.in.post.PostHardDeleteUseCase; | ||
| import com.ftm.server.common.annotation.Adapter; | ||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
|
|
||
| @Slf4j | ||
| @Adapter | ||
| @RequiredArgsConstructor | ||
| public class PostHardDeleteScheduler { | ||
|
|
||
| private final PostHardDeleteUseCase postHardDeleteUseCase; | ||
|
|
||
| // 매일 오전 3시 hard delete 진행 | ||
| @Scheduled(cron = "0 0 3 * * *", zone = "Asia/Seoul") | ||
| public void run() { | ||
| log.info( | ||
| "Posts Hard Delete started at {}", | ||
| LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); | ||
| postHardDeleteUseCase.execute(); | ||
| log.info("Posts Hard Deleted Finish."); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/ftm/server/application/command/post/DeletePostCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.ftm.server.application.command.post; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class DeletePostCommand { | ||
|
|
||
| private final Long postId; | ||
| private final Long userId; | ||
|
|
||
| private DeletePostCommand(Long postId, Long userId) { | ||
| this.postId = postId; | ||
| this.userId = userId; | ||
| } | ||
|
|
||
| public static DeletePostCommand of(Long postId, Long userId) { | ||
| return new DeletePostCommand(postId, userId); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 저도 한번 알아봐야겠네요..!!