-
Notifications
You must be signed in to change notification settings - Fork 3
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 #366 from TrandPick/development
트랜드픽 배포v1.1.3
- Loading branch information
Showing
98 changed files
with
2,492 additions
and
2,280 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
73 changes: 6 additions & 67 deletions
73
src/main/java/project/trendpick_pro/domain/answer/service/AnswerService.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 |
---|---|---|
@@ -1,76 +1,15 @@ | ||
package project.trendpick_pro.domain.answer.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import project.trendpick_pro.domain.answer.entity.Answer; | ||
import project.trendpick_pro.domain.answer.entity.dto.request.AnswerRequest; | ||
import project.trendpick_pro.domain.answer.entity.dto.response.AnswerResponse; | ||
import project.trendpick_pro.domain.answer.entity.form.AnswerForm; | ||
import project.trendpick_pro.domain.answer.repository.AnswerRepository; | ||
import project.trendpick_pro.domain.ask.entity.Ask; | ||
import project.trendpick_pro.domain.ask.entity.dto.response.AskResponse; | ||
import project.trendpick_pro.domain.ask.repository.AskRepository; | ||
import project.trendpick_pro.domain.ask.service.AskService; | ||
import project.trendpick_pro.domain.member.entity.Member; | ||
import project.trendpick_pro.domain.member.entity.RoleType; | ||
import project.trendpick_pro.global.rsData.RsData; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class AnswerService { | ||
private final AnswerRepository answerRepository; | ||
private final AskRepository askRepository; | ||
|
||
@Transactional | ||
public RsData<Long> register(Member member, Long askId, AnswerForm answerForm) { | ||
Ask ask = askRepository.findById(askId).orElseThrow( | ||
() -> new IllegalArgumentException("해당 문의는 없는 문의입니다.") | ||
); | ||
if (!member.getBrand().equals(ask.getProduct().getBrand().getName())) | ||
return RsData.of("F-1", "타 브랜드 상품에 대한 문의글에는 답변 권한이 없습니다."); | ||
|
||
Answer answer = Answer.write(answerForm); | ||
answer.connectAsk(ask); | ||
answerRepository.save(answer); | ||
return RsData.of("S-1", "답변이 성공적으로 등록되었습니다.", ask.getId()); | ||
} | ||
|
||
@Transactional | ||
public RsData<Long> delete(Member member, Long answerId) { | ||
Answer answer = answerRepository.findById(answerId).orElseThrow( | ||
() -> new IllegalArgumentException("해당 답변은 없는 답변입니다.") | ||
); | ||
|
||
if(!answer.getAsk().getProduct().getBrand().equals(member.getBrand())) | ||
return RsData.of("F-1", "접근 권한이 없습니다."); | ||
|
||
Ask ask = answer.getAsk(); | ||
ask.getAnswerList().remove(answer); | ||
if(ask.getAnswerList().size() == 0) | ||
ask.changeStatusYet(); | ||
|
||
return RsData.of("S-1", "답변이 삭제되었습니다.", answer.getAsk().getId()); | ||
} | ||
|
||
public RsData<Long> modify(Member member, Long answerId, AnswerForm answerForm) { | ||
Answer answer = answerRepository.findById(answerId).orElseThrow( | ||
() -> new IllegalArgumentException("해당 답변은 없는 답변입니다.") | ||
); | ||
|
||
if(!Objects.equals(answer.getAsk().getAuthor().getBrand(), member.getBrand())) | ||
return RsData.of("F-1", "접근 권한이 없습니다."); | ||
answer.update(answerForm); | ||
|
||
return RsData.of("S-1", "답변이 수정되었습니다.", answer.getAsk().getId()); | ||
} | ||
|
||
public List<AnswerResponse> showAll(Long askId) { | ||
List<Answer> answers = answerRepository.findAllByAskId(askRepository.findById(askId).get()); | ||
return AnswerResponse.of(answers); | ||
} | ||
} | ||
public interface AnswerService { | ||
RsData<Long> register(Member member, Long askId, AnswerForm answerForm); | ||
RsData<Long> delete(Member member, Long answerId); | ||
RsData<Long> modify(Member member, Long answerId, AnswerForm answerForm); | ||
List<AnswerResponse> showAll(Long askId); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/project/trendpick_pro/domain/answer/service/AnswerServiceImpl.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,75 @@ | ||
package project.trendpick_pro.domain.answer.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import project.trendpick_pro.domain.answer.entity.Answer; | ||
import project.trendpick_pro.domain.answer.entity.dto.response.AnswerResponse; | ||
import project.trendpick_pro.domain.answer.entity.form.AnswerForm; | ||
import project.trendpick_pro.domain.answer.repository.AnswerRepository; | ||
import project.trendpick_pro.domain.ask.entity.Ask; | ||
import project.trendpick_pro.domain.ask.repository.AskRepository; | ||
import project.trendpick_pro.domain.member.entity.Member; | ||
import project.trendpick_pro.global.rsData.RsData; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Objects; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AnswerServiceImpl implements AnswerService{ | ||
private final AnswerRepository answerRepository; | ||
private final AskRepository askRepository; | ||
|
||
@Transactional | ||
public RsData<Long> register(Member member, Long askId, AnswerForm answerForm) { | ||
Ask ask = askRepository.findById(askId).orElseThrow( | ||
() -> new NoSuchElementException("해당 문의는 없는 문의입니다.") | ||
); | ||
if (!member.getBrand().equals(ask.getProduct().getBrand().getName())) | ||
return RsData.of("F-1", "타 브랜드 상품에 대한 문의글에는 답변 권한이 없습니다."); | ||
|
||
Answer answer = Answer.write(answerForm); | ||
answer.connectAsk(ask); | ||
answerRepository.save(answer); | ||
return RsData.of("S-1", "답변이 성공적으로 등록되었습니다.", ask.getId()); | ||
} | ||
|
||
@Transactional | ||
public RsData<Long> delete(Member member, Long answerId) { | ||
Answer answer = answerRepository.findById(answerId).orElseThrow( | ||
() -> new NoSuchElementException("해당 답변은 없는 답변입니다.") | ||
); | ||
|
||
if(!answer.getAsk().getProduct().getBrand().getName().equals(member.getBrand())) | ||
return RsData.of("F-1", "접근 권한이 없습니다."); | ||
|
||
Ask ask = answer.getAsk(); | ||
ask.getAnswerList().remove(answer); | ||
if(ask.getAnswerList().size() == 0) | ||
ask.changeStatusYet(); | ||
|
||
return RsData.of("S-1", "답변이 삭제되었습니다.", answer.getAsk().getId()); | ||
} | ||
|
||
@Transactional | ||
public RsData<Long> modify(Member member, Long answerId, AnswerForm answerForm) { | ||
Answer answer = answerRepository.findById(answerId).orElseThrow( | ||
() -> new NoSuchElementException("해당 답변은 없는 답변입니다.") | ||
); | ||
|
||
if(!Objects.equals(answer.getAsk().getAuthor().getBrand(), member.getBrand())) | ||
return RsData.of("F-1", "접근 권한이 없습니다."); | ||
answer.update(answerForm); | ||
|
||
return RsData.of("S-1", "답변이 수정되었습니다.", answer.getAsk().getId()); | ||
} | ||
|
||
@Transactional | ||
public List<AnswerResponse> showAll(Long askId) { | ||
List<Answer> answers = answerRepository.findAllByAskId(askRepository.findById(askId).get()); | ||
return AnswerResponse.of(answers); | ||
} | ||
} | ||
|
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
12 changes: 0 additions & 12 deletions
12
src/main/java/project/trendpick_pro/domain/ask/entity/dto/request/AskByProductRequest.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/main/java/project/trendpick_pro/domain/ask/entity/dto/request/AskRequest.java
This file was deleted.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
src/main/java/project/trendpick_pro/domain/ask/exception/AskNotFoundException.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,14 @@ | ||
package project.trendpick_pro.domain.ask.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import project.trendpick_pro.global.exception.BaseException; | ||
import project.trendpick_pro.global.exception.ErrorCode; | ||
|
||
public class AskNotFoundException extends BaseException { | ||
|
||
private static final ErrorCode code = ErrorCode.ASK_NOT_FOUND; | ||
|
||
public AskNotFoundException(String message) { | ||
super(code, HttpStatus.BAD_REQUEST, message); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/project/trendpick_pro/domain/ask/exception/AskNotMatchException.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,14 @@ | ||
package project.trendpick_pro.domain.ask.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import project.trendpick_pro.global.exception.BaseException; | ||
import project.trendpick_pro.global.exception.ErrorCode; | ||
|
||
public class AskNotMatchException extends BaseException { | ||
|
||
private static final ErrorCode code = ErrorCode.ASK_NOT_MATCH; | ||
|
||
public AskNotMatchException(String message) { | ||
super(code, HttpStatus.BAD_REQUEST, message); | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
src/main/java/project/trendpick_pro/domain/ask/repository/AskRepository.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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
package project.trendpick_pro.domain.ask.repository; | ||
|
||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import project.trendpick_pro.domain.ask.entity.Ask; | ||
import project.trendpick_pro.domain.member.entity.Member; | ||
|
||
public interface AskRepository extends JpaRepository<Ask, Long>, AskRepositoryCustom { | ||
@Query("select a from Ask a where a.author = :member") | ||
Page<Ask> findAllByMember(Member member, Pageable pageable); | ||
} |
Oops, something went wrong.