-
Notifications
You must be signed in to change notification settings - Fork 2
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
* feat: 관리자용 토픽 조회 API 구현 (#307) * feat: 관리자용 요청 주제(토픽) 수정 API 구현 (#307) * test: static import 추가 (#307)
- Loading branch information
Showing
10 changed files
with
275 additions
and
10 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/listywave/topic/application/service/dto/TopicFindResponse.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,69 @@ | ||
package com.listywave.topic.application.service.dto; | ||
|
||
import com.listywave.topic.application.domain.Topic; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record TopicFindResponse( | ||
boolean hasNext, | ||
long totalCount, | ||
Long cursorId, | ||
List<TopicDto> topics | ||
) { | ||
|
||
public static TopicFindResponse from(List<Topic> topics, int size, long totalCount) { | ||
if (topics.isEmpty()) { | ||
return new TopicFindResponse(false, totalCount, null, List.of()); | ||
} | ||
|
||
boolean hasNext = false; | ||
if (topics.size() > size) { | ||
hasNext = true; | ||
topics.remove(topics.size() - 1); | ||
} | ||
long cursorId = topics.get(topics.size() - 1).getId(); | ||
|
||
return TopicFindResponse.builder() | ||
.hasNext(hasNext) | ||
.totalCount(totalCount) | ||
.cursorId(cursorId) | ||
.topics(TopicDto.toList(topics)) | ||
.build(); | ||
} | ||
|
||
@Builder | ||
public record TopicDto( | ||
String categoryEngName, | ||
String categoryKorName, | ||
String title, | ||
String description, | ||
LocalDateTime createdDate, | ||
Long ownerId, | ||
String ownerNickname, | ||
boolean isAnonymous, | ||
boolean isExposed | ||
) { | ||
|
||
public static List<TopicDto> toList(List<Topic> topics) { | ||
return topics.stream() | ||
.map(TopicDto::of) | ||
.toList(); | ||
} | ||
|
||
private static TopicDto of(Topic topic) { | ||
return TopicDto.builder() | ||
.categoryEngName(topic.getCategory().name()) | ||
.categoryKorName(topic.getCategory().getViewName()) | ||
.title(topic.getTitle().getValue()) | ||
.description(topic.getDescription().getValue()) | ||
.createdDate(topic.getCreatedDate()) | ||
.ownerId(topic.getUser().getId()) | ||
.ownerNickname(topic.getUser().getNickname()) | ||
.isAnonymous(topic.isAnonymous()) | ||
.isExposed(topic.isExposed()) | ||
.build(); | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/listywave/topic/presentation/dto/TopicUpdateRequest.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,8 @@ | ||
package com.listywave.topic.presentation.dto; | ||
|
||
public record TopicUpdateRequest( | ||
boolean isExposed, | ||
String categoryCode, | ||
String title | ||
) { | ||
} |
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: 7 additions & 0 deletions
7
src/main/java/com/listywave/topic/repository/TopicRepository.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,7 +1,14 @@ | ||
package com.listywave.topic.repository; | ||
|
||
import static com.listywave.common.exception.ErrorCode.RESOURCE_NOT_FOUND; | ||
|
||
import com.listywave.common.exception.CustomException; | ||
import com.listywave.topic.application.domain.Topic; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TopicRepository extends JpaRepository<Topic, Long>, CustomTopicRepository { | ||
|
||
default Topic getById(Long id) { | ||
return findById(id).orElseThrow(() -> new CustomException(RESOURCE_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
Oops, something went wrong.