-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: 관리자용 요청 주제(토픽) 조회 및 수정 API 구현 #319
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86d01c9
feat: 사용자용 요청 주제(토픽) 생성/조회 API 구현 (#306)
kdkdhoho a5eb37b
refactor: 불필요한 코드 제거 (#306)
kdkdhoho 3ed4a0c
feat: 사용자용 요청 주제 목록 조회 API URI를 WhiteList에 추가 (#306)
kdkdhoho ccd07f7
test: 토픽 생성 테스트 검증 수정 (#306)
kdkdhoho 739763b
feat: 관리자용 토픽 조회 API 구현 (#307)
kdkdhoho f7f47c8
feat: 관리자용 요청 주제(토픽) 수정 API 구현 (#307)
kdkdhoho 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 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: 2 additions & 0 deletions
2
src/main/java/com/listywave/list/application/domain/category/CategoryTypeConverter.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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/listywave/topic/application/domain/Topic.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,52 @@ | ||
package com.listywave.topic.application.domain; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import com.listywave.common.BaseEntity; | ||
import com.listywave.list.application.domain.category.CategoryType; | ||
import com.listywave.list.application.domain.list.ListDescription; | ||
import com.listywave.list.application.domain.list.ListTitle; | ||
import com.listywave.user.application.domain.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ForeignKey; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = PROTECTED) | ||
@AllArgsConstructor | ||
public class Topic extends BaseEntity { | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", nullable = false, foreignKey = @ForeignKey(name = "topic_user_fk")) | ||
private User user; | ||
|
||
@Column(name = "category_code", length = 10, nullable = false) | ||
private CategoryType category; | ||
|
||
@Embedded | ||
private ListTitle title; | ||
|
||
@Embedded | ||
private ListDescription description; | ||
|
||
@Column(nullable = false) | ||
private boolean isAnonymous; | ||
|
||
@Column(nullable = false) | ||
private boolean isExposed; | ||
|
||
public void update(boolean isExposed, CategoryType categoryType, String title) { | ||
this.isExposed = isExposed; | ||
this.category = categoryType; | ||
this.title = new ListTitle(title); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/listywave/topic/application/service/TopicService.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,48 @@ | ||
package com.listywave.topic.application.service; | ||
|
||
import com.listywave.list.application.domain.category.CategoryType; | ||
import com.listywave.topic.application.domain.Topic; | ||
import com.listywave.topic.application.service.dto.ExposedTopicFindResponse; | ||
import com.listywave.topic.application.service.dto.TopicCreateRequest; | ||
import com.listywave.topic.application.service.dto.TopicFindResponse; | ||
import com.listywave.topic.repository.TopicRepository; | ||
import com.listywave.user.application.domain.User; | ||
import com.listywave.user.repository.user.UserRepository; | ||
import jakarta.annotation.Nullable; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class TopicService { | ||
|
||
private final UserRepository userRepository; | ||
private final TopicRepository topicRepository; | ||
|
||
public void create(TopicCreateRequest request, Long userId) { | ||
User user = userRepository.getById(userId); | ||
Topic topic = request.toEntity(user); | ||
topicRepository.save(topic); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ExposedTopicFindResponse findAllExposed(@Nullable Long cursorId, int size) { | ||
List<Topic> result = topicRepository.findAllExposed(cursorId, size); | ||
return ExposedTopicFindResponse.of(result, size); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public TopicFindResponse findAll(@Nullable Long cursorId, int size) { | ||
List<Topic> result = topicRepository.findAll(cursorId, size); | ||
long totalCount = (topicRepository.count() / size) + 1; | ||
return TopicFindResponse.from(result, size, totalCount); | ||
} | ||
|
||
public void update(Long topicId, boolean isExposed, String categoryCode, String title) { | ||
Topic topic = topicRepository.getById(topicId); | ||
topic.update(isExposed, CategoryType.codeOf(categoryCode), title); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/listywave/topic/application/service/dto/ExposedTopicFindResponse.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,60 @@ | ||
package com.listywave.topic.application.service.dto; | ||
|
||
import com.listywave.topic.application.domain.Topic; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
public record ExposedTopicFindResponse( | ||
Long cursorId, | ||
boolean hasNext, | ||
List<TopicDto> topics | ||
) { | ||
|
||
public static ExposedTopicFindResponse of(List<Topic> topics, int size) { | ||
if (topics.isEmpty()) { | ||
return new ExposedTopicFindResponse(null, false, List.of()); | ||
} | ||
|
||
boolean hasNext = false; | ||
if (topics.size() > size) { | ||
hasNext = true; | ||
topics.remove(topics.size() - 1); | ||
} | ||
Long cursorId = topics.get(topics.size() - 1).getId(); | ||
List<TopicDto> topicDtos = TopicDto.toList(topics); | ||
|
||
return new ExposedTopicFindResponse(cursorId, hasNext, topicDtos); | ||
} | ||
|
||
@Builder | ||
public record TopicDto( | ||
Long id, | ||
String categoryEngName, | ||
String categoryKorName, | ||
String title, | ||
String description, | ||
Long ownerId, | ||
String ownerNickname, | ||
boolean isAnonymous | ||
) { | ||
|
||
public static List<TopicDto> toList(List<Topic> topics) { | ||
return topics.stream() | ||
.map(TopicDto::of) | ||
.toList(); | ||
} | ||
|
||
public static TopicDto of(Topic topic) { | ||
return TopicDto.builder() | ||
.id(topic.getId()) | ||
.categoryEngName(topic.getCategory().name()) | ||
.categoryKorName(topic.getCategory().getViewName()) | ||
.title(topic.getTitle().getValue()) | ||
.description(topic.getDescription().getValue()) | ||
.ownerId(topic.getUser().getId()) | ||
.ownerNickname(topic.getUser().getNickname()) | ||
.isAnonymous(topic.isAnonymous()) | ||
.build(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/listywave/topic/application/service/dto/TopicCreateRequest.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,24 @@ | ||
package com.listywave.topic.application.service.dto; | ||
|
||
import com.listywave.list.application.domain.category.CategoryType; | ||
import com.listywave.list.application.domain.list.ListDescription; | ||
import com.listywave.list.application.domain.list.ListTitle; | ||
import com.listywave.topic.application.domain.Topic; | ||
import com.listywave.user.application.domain.User; | ||
|
||
public record TopicCreateRequest( | ||
String categoryKorName, | ||
String title, | ||
String description, | ||
boolean isAnonymous | ||
) { | ||
|
||
public Topic toEntity(User user) { | ||
return Topic.builder() | ||
.user(user) | ||
.category(CategoryType.viewNameOf(categoryKorName)) | ||
.title(new ListTitle(title)) | ||
.description(new ListDescription(description)) | ||
.build(); | ||
} | ||
} |
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(); | ||
} | ||
} | ||
} |
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.
이거또한 앞서 페이징유틸에서 사용하는 메서드 이용하실 수 있으면 하면 좋고 동호님 판단하에 해주시길 바랍니다 !!