-
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.
Merge pull request #59 from Cafegory/feature-58
[BUILD SUCCESS] [BUILD SUCCESS] [BUILD FAIL] [BUILD FAIL] 카공 Q&A 질문 생성,수정,삭제 기능구현
- Loading branch information
Showing
19 changed files
with
634 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/example/demo/domain/StudyOnceQuestion.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,59 @@ | ||
package com.example.demo.domain; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.ConstraintMode; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.ForeignKey; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Table(name = "study_once_question") | ||
public class StudyOnceQuestion extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "study_once_question_id") | ||
private Long id; | ||
|
||
private String content; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) | ||
private MemberImpl member; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "study_once_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) | ||
private StudyOnceImpl studyOnce; | ||
|
||
@Builder | ||
private StudyOnceQuestion(Long id, String content, MemberImpl member, StudyOnceImpl studyOnce) { | ||
//todo content에 대한 검증 추가 | ||
this.id = id; | ||
this.content = content; | ||
this.member = member; | ||
this.studyOnce = studyOnce; | ||
} | ||
|
||
public void changeContent(String content) { | ||
//todo content 에 대한 검증 추가 | ||
this.content = content; | ||
} | ||
|
||
public boolean isPersonAsked(MemberImpl member) { | ||
return this.member.getId().equals(member.getId()); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/demo/dto/StudyOnceQuestionRequest.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,19 @@ | ||
package com.example.demo.dto; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class StudyOnceQuestionRequest { | ||
|
||
@NotBlank | ||
private String content; | ||
|
||
public StudyOnceQuestionRequest() { | ||
} | ||
|
||
public StudyOnceQuestionRequest(String content) { | ||
this.content = content; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/demo/dto/StudyOnceQuestionResponse.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,13 @@ | ||
package com.example.demo.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class StudyOnceQuestionResponse { | ||
|
||
private final Long questionId; | ||
private final String content; | ||
private final WriterResponse writer; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/demo/dto/StudyOnceQuestionUpdateRequest.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,19 @@ | ||
package com.example.demo.dto; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class StudyOnceQuestionUpdateRequest { | ||
|
||
@NotBlank | ||
private String content; | ||
|
||
public StudyOnceQuestionUpdateRequest() { | ||
} | ||
|
||
public StudyOnceQuestionUpdateRequest(String content) { | ||
this.content = content; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.demo.mapper; | ||
|
||
import com.example.demo.domain.MemberImpl; | ||
import com.example.demo.dto.WriterResponse; | ||
|
||
public class MemberMapper { | ||
|
||
public WriterResponse toWriterResponse(MemberImpl member) { | ||
return new WriterResponse(member.getId(), member.getName(), member.getThumbnailImage().getThumbnailImage()); | ||
} | ||
} |
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/example/demo/repository/StudyOnceQuestionRepository.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.example.demo.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.example.demo.domain.StudyOnceQuestion; | ||
|
||
public interface StudyOnceQuestionRepository extends JpaRepository<StudyOnceQuestion, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/demo/service/StudyOnceQAndAQueryService.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.example.demo.service; | ||
|
||
import com.example.demo.dto.StudyOnceQuestionResponse; | ||
|
||
public interface StudyOnceQAndAQueryService { | ||
|
||
StudyOnceQuestionResponse searchQuestion(Long studyOnceQuestionId); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/demo/service/StudyOnceQAndAQueryServiceImpl.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,38 @@ | ||
package com.example.demo.service; | ||
|
||
import static com.example.demo.exception.ExceptionType.*; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.example.demo.domain.StudyOnceQuestion; | ||
import com.example.demo.dto.StudyOnceQuestionResponse; | ||
import com.example.demo.dto.WriterResponse; | ||
import com.example.demo.exception.CafegoryException; | ||
import com.example.demo.mapper.MemberMapper; | ||
import com.example.demo.mapper.StudyOnceMapper; | ||
import com.example.demo.repository.StudyOnceQuestionRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class StudyOnceQAndAQueryServiceImpl implements StudyOnceQAndAQueryService { | ||
|
||
private final StudyOnceQuestionRepository studyOnceQuestionRepository; | ||
private final MemberMapper memberMapper; | ||
private final StudyOnceMapper studyOnceMapper; | ||
|
||
@Override | ||
public StudyOnceQuestionResponse searchQuestion(Long studyOnceQuestionId) { | ||
StudyOnceQuestion question = findStudyOnceQuestionById(studyOnceQuestionId); | ||
WriterResponse writerResponse = memberMapper.toWriterResponse(question.getMember()); | ||
return studyOnceMapper.toStudyOnceQuestionResponse(question, writerResponse); | ||
} | ||
|
||
private StudyOnceQuestion findStudyOnceQuestionById(Long studyOnceQuestionId) { | ||
return studyOnceQuestionRepository.findById(studyOnceQuestionId) | ||
.orElseThrow(() -> new CafegoryException(STUDY_ONCE_QUESTION_NOT_FOUND)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/example/demo/service/StudyOnceQuestionService.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,15 @@ | ||
package com.example.demo.service; | ||
|
||
import com.example.demo.dto.StudyOnceQuestionRequest; | ||
import com.example.demo.dto.StudyOnceQuestionUpdateRequest; | ||
|
||
public interface StudyOnceQuestionService { | ||
|
||
Long saveQuestion(Long memberId, Long studyOnceId, StudyOnceQuestionRequest request); | ||
|
||
void updateQuestion(Long memberId, Long studyOnceQuestionId, StudyOnceQuestionUpdateRequest request); | ||
|
||
void deleteQuestion(Long studyOnceQuestionId); | ||
|
||
boolean isPersonWhoAskedQuestion(Long memberId, Long studyOnceQuestionId); | ||
} |
Oops, something went wrong.