-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from lotteon2/develop
release
- Loading branch information
Showing
11 changed files
with
273 additions
and
87 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/dailyon/snsservice/controller/rest/PostAdminController.java
This file contains 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,39 @@ | ||
package com.dailyon.snsservice.controller.rest; | ||
|
||
import com.dailyon.snsservice.dto.response.post.PostAdminPageResponse; | ||
import com.dailyon.snsservice.service.post.PostAdminService; | ||
import com.dailyon.snsservice.service.post.PostService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RequestMapping("/admin") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class PostAdminController { | ||
|
||
private final PostAdminService postAdminService; | ||
|
||
@GetMapping("/posts") | ||
public ResponseEntity<PostAdminPageResponse> getPosts( | ||
@PageableDefault( | ||
page = 0, | ||
size = 5, | ||
sort = {"id"}, | ||
direction = Sort.Direction.ASC) | ||
Pageable pageable) { | ||
PostAdminPageResponse postAdminPageResponse = postAdminService.getPostsForAdmin(pageable); | ||
return ResponseEntity.ok(postAdminPageResponse); | ||
} | ||
|
||
@DeleteMapping("/posts") | ||
public ResponseEntity<Void> bulkDeletePosts(@RequestParam(name = "postIds") List<Long> postIds) { | ||
postAdminService.softBulkDeleteByIds(postIds); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/dailyon/snsservice/dto/response/post/PostAdminPageResponse.java
This file contains 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,42 @@ | ||
package com.dailyon.snsservice.dto.response.post; | ||
|
||
import com.dailyon.snsservice.entity.HashTag; | ||
import com.dailyon.snsservice.entity.Post; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.*; | ||
import org.springframework.data.domain.Page; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PostAdminPageResponse { | ||
|
||
private int totalPages; | ||
private long totalElements; | ||
private List<PostAdminResponse> posts; | ||
|
||
public static PostAdminPageResponse fromEntity(Page<Post> posts) { | ||
return PostAdminPageResponse.builder() | ||
.totalPages(posts.getTotalPages()) | ||
.totalElements(posts.getTotalElements()) | ||
.posts( | ||
posts.getContent().stream() | ||
.map( | ||
post -> | ||
PostAdminResponse.builder() | ||
.id(post.getId()) | ||
.thumbnailImgUrl(post.getPostImage().getThumbnailImgUrl()) | ||
.hashTagNames( | ||
post.getHashTags().stream() | ||
.map(HashTag::getName) | ||
.collect(Collectors.toList())) | ||
.title(post.getTitle()) | ||
.description(post.getDescription()) | ||
.memberNickname(post.getMember().getNickname()) | ||
.build()) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/dailyon/snsservice/dto/response/post/PostAdminResponse.java
This file contains 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,18 @@ | ||
package com.dailyon.snsservice.dto.response.post; | ||
|
||
import java.util.List; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PostAdminResponse { | ||
|
||
private Long id; | ||
private String thumbnailImgUrl; | ||
private List<String> hashTagNames; | ||
private String title; | ||
private String description; | ||
private String memberNickname; | ||
} |
This file contains 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 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 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 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 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 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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/dailyon/snsservice/service/post/PostAdminService.java
This file contains 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,31 @@ | ||
package com.dailyon.snsservice.service.post; | ||
|
||
import com.dailyon.snsservice.dto.response.post.PostAdminPageResponse; | ||
import com.dailyon.snsservice.entity.Post; | ||
import com.dailyon.snsservice.repository.post.PostRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class PostAdminService { | ||
|
||
private final PostRepository postRepository; | ||
|
||
public PostAdminPageResponse getPostsForAdmin(Pageable pageable) { | ||
Page<Post> posts = postRepository.findAllByIdAscAndIsDeletedFalse(pageable); | ||
return PostAdminPageResponse.fromEntity(posts); | ||
} | ||
|
||
public void softBulkDeleteByIds(List<Long> ids) { | ||
postRepository.softBulkDeleteByIds(ids); | ||
} | ||
} |
Oops, something went wrong.