-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#69 [[feat] 카테고리별 글 리스트
- Loading branch information
Showing
32 changed files
with
238 additions
and
63 deletions.
There are no files selected for viewing
16 changes: 9 additions & 7 deletions
16
module-api/src/main/java/com/mile/controller/moim/MoimController.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
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
2 changes: 1 addition & 1 deletion
2
module-api/src/main/java/com/mile/controller/post/PostController.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
2 changes: 1 addition & 1 deletion
2
module-api/src/main/java/com/mile/controller/post/PostControllerSwagger.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
27 changes: 27 additions & 0 deletions
27
module-api/src/main/java/com/mile/controller/topic/TopicController.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,27 @@ | ||
package com.mile.controller.topic; | ||
|
||
import com.mile.dto.SuccessResponse; | ||
import com.mile.exception.message.SuccessMessage; | ||
import com.mile.topic.service.TopicService; | ||
import com.mile.topic.service.dto.PostListInTopicResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/topic") | ||
public class TopicController implements TopicControllerSwagger { | ||
|
||
private final TopicService topicService; | ||
|
||
@Override | ||
@GetMapping("/{topicId}") | ||
public SuccessResponse<PostListInTopicResponse> getPostListByTopic( | ||
@PathVariable Long topicId | ||
) { | ||
return SuccessResponse.of(SuccessMessage.MOIM_POST_GET_SUCCESS, topicService.getPostListByTopic(topicId)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
module-api/src/main/java/com/mile/controller/topic/TopicControllerSwagger.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,32 @@ | ||
package com.mile.controller.topic; | ||
|
||
|
||
import com.mile.dto.ErrorResponse; | ||
import com.mile.dto.SuccessResponse; | ||
import com.mile.topic.service.dto.PostListInTopicResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
@Tag(name = "Topic") | ||
public interface TopicControllerSwagger { | ||
|
||
@Operation(summary = "글모임뷰 - 글감 별 글 List") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse(responseCode = "200", description = "카테고리별 글 리스트 조회가 완료되었습니다."), | ||
@ApiResponse(responseCode = "404", description = "1. 해당 글감이 존재하지 않습니다.\n 2. 해당 글감의 글이 존재하지 않습니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "500", description = "서버 내부 오류입니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
|
||
} | ||
) | ||
SuccessResponse<PostListInTopicResponse> getPostListByTopic( | ||
@PathVariable Long topicId | ||
); | ||
} |
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
7 changes: 3 additions & 4 deletions
7
.../mile/curious/serivce/CuriousService.java → .../mile/curious/service/CuriousService.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
2 changes: 1 addition & 1 deletion
2
...ious/serivce/dto/CuriousInfoResponse.java → ...ious/service/dto/CuriousInfoResponse.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
21 changes: 11 additions & 10 deletions
21
...va/com/mile/moim/serivce/MoimService.java → ...va/com/mile/moim/service/MoimService.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
4 changes: 2 additions & 2 deletions
4
...oim/serivce/dto/CategoryListResponse.java → ...oim/service/dto/CategoryListResponse.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
4 changes: 2 additions & 2 deletions
4
...moim/serivce/dto/ContentListResponse.java → ...moim/service/dto/ContentListResponse.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
2 changes: 1 addition & 1 deletion
2
...serivce/dto/MoimAuthenticateResponse.java → ...service/dto/MoimAuthenticateResponse.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
2 changes: 1 addition & 1 deletion
2
...ivce/dto/MoimCuriousPostListResponse.java → ...vice/dto/MoimCuriousPostListResponse.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.mile.moim.serivce.dto; | ||
package com.mile.moim.service.dto; | ||
|
||
|
||
import java.util.List; | ||
|
2 changes: 1 addition & 1 deletion
2
...le/moim/serivce/dto/MoimInfoResponse.java → ...le/moim/service/dto/MoimInfoResponse.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.mile.moim.serivce.dto; | ||
package com.mile.moim.service.dto; | ||
|
||
public record MoimInfoResponse( | ||
|
||
|
4 changes: 1 addition & 3 deletions
4
...ivce/dto/MoimMostCuriousPostResponse.java → ...vice/dto/MoimMostCuriousPostResponse.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
2 changes: 1 addition & 1 deletion
2
...e/moim/serivce/dto/MoimTopicResponse.java → ...e/moim/service/dto/MoimTopicResponse.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
5 changes: 5 additions & 0 deletions
5
module-domain/src/main/java/com/mile/post/repository/PostRepository.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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.mile.post.repository; | ||
|
||
import com.mile.post.domain.Post; | ||
import com.mile.topic.domain.Topic; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long>, PostRepositoryCustom { | ||
boolean existsPostByIdAndWriterNameId(final Long postId, final Long userId); | ||
|
||
List<Post> findByTopic(final Topic topic); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
module-domain/src/main/java/com/mile/post/service/PostGetService.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,35 @@ | ||
package com.mile.post.service; | ||
|
||
import com.mile.exception.message.ErrorMessage; | ||
import com.mile.exception.model.NotFoundException; | ||
import com.mile.post.domain.Post; | ||
import com.mile.post.repository.PostRepository; | ||
import com.mile.topic.domain.Topic; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PostGetService { | ||
|
||
private final PostRepository postRepository; | ||
|
||
|
||
public List<Post> findByTopic( | ||
final Topic topic | ||
) { | ||
List<Post> postList = postRepository.findByTopic(topic); | ||
isPostListEmpty(postList); | ||
return postList; | ||
} | ||
|
||
private void isPostListEmpty( | ||
List<Post> postList | ||
) { | ||
if(postList.isEmpty()) { | ||
throw new NotFoundException(ErrorMessage.MOIM_TOPIC_NOT_FOUND); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
module-domain/src/main/java/com/mile/post/service/dto/PostListResponse.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,34 @@ | ||
package com.mile.post.service.dto; | ||
|
||
import com.mile.post.domain.Post; | ||
import com.mile.utils.DateUtil; | ||
|
||
public record PostListResponse( | ||
Long postId, | ||
String postTitle, | ||
String postContent, | ||
String writerName, | ||
String createdAt, | ||
int curiousCount, | ||
String imageUrl | ||
) { | ||
private static final int SUBSTRING_START = 0; | ||
private static final int SUBSTRING_END_WITH_IMAGE = 104; | ||
private static final int SUBSTRING_END_WITHOUT_IMAGE = 166; | ||
|
||
public static PostListResponse of(final Post post) { | ||
return new PostListResponse(post.getId(), post.getTitle(), getSubString(post), | ||
post.getWriterName().getName(), | ||
DateUtil.getStringWithTimeOfLocalDate(post.getCreatedAt()), | ||
post.getCuriousCount(), | ||
post.getImageUrl()); | ||
} | ||
|
||
private static String getSubString(final Post post) { | ||
if (post.getImageUrl().isEmpty()) { | ||
return post.getContent().substring(SUBSTRING_START, SUBSTRING_END_WITHOUT_IMAGE); | ||
} else { | ||
return post.getContent().substring(SUBSTRING_START, SUBSTRING_END_WITH_IMAGE); | ||
} | ||
} | ||
} |
Oops, something went wrong.