Skip to content

Commit

Permalink
refactor: 코드 리뷰 피드백 반영
Browse files Browse the repository at this point in the history
- topicService.createTopicByTopic -> TopicCreateRequest.from
  • Loading branch information
kimdozzi committed Jul 11, 2024
1 parent a4c47ef commit 52c4749
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/genius/gitget/topic/domain/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public Topic(String title, String description, String tags, String notice, int p
this.pointPerPerson = pointPerPerson;
}

//== 비즈니스 로직 ==//
public void updateExistInstance(String description) {
this.description = description;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/genius/gitget/topic/dto/TopicCreateRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.genius.gitget.topic.dto;

import com.genius.gitget.topic.domain.Topic;
import lombok.Builder;

@Builder
Expand All @@ -10,4 +11,13 @@ public record TopicCreateRequest(
int pointPerPerson,
String notice
) {
public static Topic from(TopicCreateRequest topicCreateRequest) {
return Topic.builder()
.title(topicCreateRequest.title())
.description(topicCreateRequest.description())
.tags(topicCreateRequest.tags())
.pointPerPerson(topicCreateRequest.pointPerPerson())
.notice(topicCreateRequest.notice())
.build();
}
}
15 changes: 2 additions & 13 deletions src/main/java/com/genius/gitget/topic/service/TopicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.genius.gitget.global.util.exception.BusinessException;
import com.genius.gitget.global.util.exception.ErrorCode;
import com.genius.gitget.topic.domain.Topic;
import com.genius.gitget.topic.dto.TopicCreateRequest;
import com.genius.gitget.topic.repository.TopicRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -29,8 +28,8 @@ public Topic findOne(Long id) {
}

@Transactional
public Long create(Topic byTopicCreateDto) {
Topic savedTopic = topicRepository.save(byTopicCreateDto);
public Long create(Topic topic) {
Topic savedTopic = topicRepository.save(topic);
return savedTopic.getId();
}

Expand All @@ -40,14 +39,4 @@ public void delete(Long id) {
.orElseThrow(() -> new BusinessException(ErrorCode.TOPIC_NOT_FOUND));
topicRepository.delete(topic);
}

public Topic createTopicByTopicCreateRequest(TopicCreateRequest topicCreateRequest) {
return Topic.builder()
.title(topicCreateRequest.title())
.description(topicCreateRequest.description())
.tags(topicCreateRequest.tags())
.pointPerPerson(topicCreateRequest.pointPerPerson())
.notice(topicCreateRequest.notice())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TopicDetailResponse findOne(Long id) {

@Override
public Long create(TopicCreateRequest topicCreateRequest) {
Topic topic = topicService.createTopicByTopicCreateRequest(topicCreateRequest);
Topic topic = TopicCreateRequest.from(topicCreateRequest);
return topicService.create(topic);
}

Expand Down

0 comments on commit 52c4749

Please sign in to comment.