Skip to content

Commit

Permalink
Merge pull request #141 from oduck-team/feature/138
Browse files Browse the repository at this point in the history
도메인 이름 변경 #138
  • Loading branch information
jaycobcoder authored Dec 6, 2023
2 parents 0a16bff + a8dacf6 commit 012bc80
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class InquiryFeedback {
public class AnswerFeedback {
private Long inquiryId;
private FeedbackType helpful;

public static InquiryFeedback from(Long inquiryId, FeedbackType helpful) {
return new InquiryFeedback(inquiryId, helpful);
public static AnswerFeedback from(Long inquiryId, FeedbackType helpful) {
return new AnswerFeedback(inquiryId, helpful);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class CheckAnswerRequest {
private Long inquiryId;
public class ContactId {
private Long contactId;

public static CheckAnswerRequest from(Long inquiryId) {
return new CheckAnswerRequest(inquiryId);
public static ContactId from(Long inquiryId) {
return new ContactId(inquiryId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Getter;
import org.hibernate.validator.constraints.Length;

public class InquiryReq {
public class ContactReq {
@Getter
@AllArgsConstructor
public static class PostReq {
Expand All @@ -25,4 +25,15 @@ public static class PostReq {
message = "글자 수는 1~1000를 허용합니다.")
private String content;
}

@Getter
@AllArgsConstructor
public static class AnswerReq {
private Long id;

@NotBlank
@Length(min = 1, max = 1000,
message = "글자 수는 1~1000를 허용합니다.")
private String content;
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package io.oduck.api.domain.inquiry.dto;

import io.oduck.api.domain.inquiry.dto.InquiryReq.PostReq;
import io.oduck.api.domain.inquiry.entity.Inquiry;
import io.oduck.api.domain.inquiry.dto.ContactReq.PostReq;
import io.oduck.api.domain.inquiry.entity.Contact;
import io.oduck.api.domain.member.entity.Member;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public class InquiryRequestHolder {
private Inquiry inquiry;
public class ContactRequestHolder {
private Contact contact;

public static InquiryRequestHolder from(PostReq request, Member member) {
Inquiry inquiry = Inquiry.builder()
public static ContactRequestHolder from(PostReq request, Member member) {
Contact contact = Contact.builder()
.title(request.getTitle())
.content(request.getContent())
.type(request.getType())
.answer(false)
.check(false)
.answered(false)
.member(member)
.build();
return new InquiryRequestHolder(inquiry);
return new ContactRequestHolder(contact);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.oduck.api.domain.inquiry.dto;

import io.oduck.api.domain.inquiry.entity.Inquiry;
import io.oduck.api.domain.inquiry.entity.Contact;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;

public class InquiryRes {
public class ContactRes {

@Getter
@AllArgsConstructor
Expand All @@ -31,8 +31,8 @@ public static class DetailRes {
private LocalDate localDate;
private boolean answer;

public static DetailRes from(Inquiry inquiry) {
return new DetailRes(inquiry.getTitle(), inquiry.getCreatedAt().toLocalDate(), inquiry.isAnswer());
public static DetailRes from(Contact contact) {
return new DetailRes(contact.getTitle(), contact.getCreatedAt().toLocalDate(), contact.isAnswered());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -15,7 +17,8 @@
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class InquiryAnswer {
@Table(name = "answer")
public class Answer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -25,6 +28,16 @@ public class InquiryAnswer {

private FeedbackType helpful;

@Column(name = "check_answer")
private boolean check = false;

@OneToOne(mappedBy = "answer")
private Contact contact;

public void check() {
check = true;
}

public void feedback(FeedbackType helpful) {
this.helpful = helpful;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import io.oduck.api.domain.member.entity.Member;
import io.oduck.api.global.audit.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -21,7 +24,7 @@
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class Inquiry extends BaseEntity {
public class Contact extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -36,20 +39,16 @@ public class Inquiry extends BaseEntity {
@Column(nullable = false, length = 1000)
private String content;

@Enumerated(value = EnumType.STRING)
private InquiryType type;

private boolean answer = false;
private boolean check = false;
private boolean answered = false;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "inquiry_answer_id")
private InquiryAnswer inquiryAnswer;

public void checkAnswer() {
check = true;
}
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "answer_id")
private Answer answer;

public void feedback(FeedbackType helpful) {
inquiryAnswer.feedback(helpful);
answer.feedback(helpful);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.oduck.api.domain.inquiry.repository;

import io.oduck.api.domain.inquiry.entity.Contact;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ContactRepository extends JpaRepository<Contact, Long>, ContactRepositoryCustom {

@Query("select c from Contact c join fetch c.member where c.id = :id")
Optional<Contact> findWithMemberById(@Param("id") Long id);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.oduck.api.domain.inquiry.repository;

import io.oduck.api.domain.inquiry.dto.InquiryRes.MyInquiry;
import io.oduck.api.domain.inquiry.dto.ContactRes.MyInquiry;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface InquiryRepositoryCustom {
public interface ContactRepositoryCustom {

Page<MyInquiry> getAllByMemberId(Long memberId, Pageable pageable);

boolean existsByIdAndCheck(Long id, Boolean check);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.oduck.api.domain.inquiry.repository;

import static io.oduck.api.domain.inquiry.entity.QInquiry.inquiry;
import static io.oduck.api.domain.inquiry.entity.QAnswer.answer;
import static io.oduck.api.domain.inquiry.entity.QContact.contact;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.oduck.api.domain.inquiry.dto.InquiryRes.MyInquiry;
import io.oduck.api.domain.inquiry.dto.ContactRes.MyInquiry;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -18,7 +19,7 @@
@Slf4j
@Repository
@RequiredArgsConstructor
public class InquiryRepositoryCustomImpl implements InquiryRepositoryCustom {
public class ContactRepositoryCustomImpl implements ContactRepositoryCustom {

private final JPAQueryFactory queryFactory;

Expand All @@ -28,22 +29,42 @@ public Page<MyInquiry> getAllByMemberId(Long memberId, Pageable pageable) {
List<MyInquiry> content = queryFactory.select(
Projections.constructor(
MyInquiry.class,
inquiry.id,
inquiry.title,
inquiry.createdAt,
inquiry.answer
contact.id,
contact.title,
contact.createdAt,
contact.answer
)
).from(inquiry)
).from(contact)
.where(memberIdEq(memberId))
.fetch();

JPAQuery<Long> expression = queryFactory.select(inquiry.id.count()).from(inquiry)
JPAQuery<Long> expression = queryFactory.select(contact.id.count()).from(contact)
.where(memberIdEq(memberId));

return PageableExecutionUtils.getPage(content, pageable, expression::fetchOne);
}

public boolean existsByIdAndCheck(Long id, Boolean check) {
Integer fetchOne = queryFactory.selectOne()
.from(contact)
.join(contact.answer, answer)
.where(
idEq(id),
isCheck(check)
)
.fetchFirst();
return fetchOne != null;
}

private BooleanExpression isCheck(Boolean check) {
return check == null ? null : answer.check.eq(check);
}

private BooleanExpression idEq(Long id) {
return id == null? null : answer.id.eq(id);
}

private BooleanExpression memberIdEq(Long memberId) {
return memberId == null ? null : inquiry.member.id.eq(memberId);
return memberId == null ? null : contact.member.id.eq(memberId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.oduck.api.domain.inquiry.service;

import io.oduck.api.domain.inquiry.dto.ContactReq.AnswerReq;
import io.oduck.api.domain.inquiry.entity.Contact;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class AnswerHolder {
private Contact contact;
private AnswerReq request;
public static AnswerHolder from(Contact contact, AnswerReq request) {
return new AnswerHolder(contact, request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.oduck.api.domain.inquiry.service;

import io.oduck.api.domain.inquiry.entity.Contact;
import io.oduck.api.domain.member.entity.Member;
import io.oduck.api.global.exception.ForbiddenException;
import org.springframework.stereotype.Component;

@Component
public class ContactPolicy {

public void isAccessOwnInquiry(Contact contact, Member member) {
if(!isOwnInquiry(contact, member)) {
throw new ForbiddenException("not has permission");
}
contact.getMember().getId();
}

private boolean isOwnInquiry(Contact contact, Member member) {
return contact.getMember().getId().equals(member.getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.oduck.api.domain.inquiry.service;

import io.oduck.api.domain.inquiry.dto.InquiryReq.PostReq;
import io.oduck.api.domain.inquiry.dto.InquiryRes.DetailRes;
import io.oduck.api.domain.inquiry.dto.InquiryRes.MyInquiry;
import io.oduck.api.domain.inquiry.dto.ContactReq.PostReq;
import io.oduck.api.domain.inquiry.dto.ContactRes.DetailRes;
import io.oduck.api.domain.inquiry.dto.ContactRes.MyInquiry;
import io.oduck.api.domain.inquiry.entity.FeedbackType;
import io.oduck.api.global.common.PageResponse;

public interface InquiryService {
public interface ContactService {
void inquiry(Long memberId, PostReq request);

PageResponse<MyInquiry> getAllByMemberId(Long memberId, int page, int size);
Expand All @@ -19,7 +19,7 @@ public interface InquiryService {

// Page<?> getAll();
//
// void answer();
// void answer(Long adminId, AnswerReq request);
//
// void update(Long id);
}
Loading

0 comments on commit 012bc80

Please sign in to comment.