Skip to content

Commit

Permalink
fix: question entity(questionService 제외)
Browse files Browse the repository at this point in the history
  • Loading branch information
jihyo-j committed Apr 27, 2024
1 parent 04a8aaf commit 534cd6b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor

public class Question {
private Long questionId;
private Long memberId;
private String content;
public Question(Long questionId, Long memberId, String content) {
this.questionId = questionId;
this.memberId = memberId;
this.content = content;
}
private LocalDateTime createdDate;
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ public class QuestionEntity {
@Column(name = "created_date", nullable = false, length = 30)
private LocalDateTime createdDate;

public QuestionEntity(Long id, String content, Member member, LocalDateTime createdDate) {
this.id = id;
this.content = content;
this.member = member;
this.createdDate = createdDate;
}
public void updateContent(String content) {
this.content = content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.web.baebaeBE.infra.member.repository.MemberRepository;
import com.web.baebaeBE.infra.question.entity.Question;
import com.web.baebaeBE.infra.question.entity.QuestionEntity;
import com.web.baebaeBE.presentation.question.dto.QuestionDetailResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +12,7 @@
@Component
@RequiredArgsConstructor
public class QuestionMapper {
private MemberRepository memberRepository;
private final MemberRepository memberRepository;

public QuestionEntity toEntity(Question question, String email) {
Optional<Member> optionalMember = memberRepository.findByEmail(email);
Expand All @@ -25,12 +24,21 @@ public QuestionEntity toEntity(Question question, String email) {
.build();
}

public QuestionDetailResponse toDomain(QuestionEntity questionEntity) {
return new QuestionDetailResponse(
public QuestionEntity toEntity(Question question, Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("No member found with id: " + memberId));

return QuestionEntity.builder()
.content(question.getContent())
.member(member)
.build();
}

public Question toDomain(QuestionEntity questionEntity) {
return new Question(
questionEntity.getId(),
questionEntity.getContent(),
questionEntity.getMember().getNickname(),
questionEntity.getCreatedDate()
questionEntity.getMember().getId(),
questionEntity.getContent()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface QuestionRepository{
Optional<Question> findById(Long questionId);
Question save(QuestionEntity questionEntity, Long memberId);
Question save(Question question, Long memberId);
Page<Question> findAllByMemberId(Long memberId, Pageable pageable);
}

0 comments on commit 534cd6b

Please sign in to comment.