From f3ab4a9feb4d46f22d365af7ebfcb458558bb054 Mon Sep 17 00:00:00 2001 From: Minji Kim Date: Thu, 11 Jan 2024 02:50:47 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[feat]=20=EA=B3=B5=EC=A7=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/controller/NoticeController.java | 10 ++++++++-- .../project/notice/service/NoticeService.java | 18 ++++++++++++++++++ .../wowmarket/wow_server/domain/Notice.java | 5 +++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java b/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java index cdd6aee..2c0c6b9 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java +++ b/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java @@ -24,7 +24,6 @@ public ResponseEntity createNotice(@PathVariable Long project_id, @RequestBody N return noticeService.createNotice(project_id, requestDto); } - // 주문폼: 공지 전체 조회 @GetMapping("/{project_id}/notice") public NoticePageResponseDto getNoticeList(@PathVariable Long project_id) { @@ -33,8 +32,15 @@ public NoticePageResponseDto getNoticeList(@PathVariable Long project_id) { // 주문폼: 공지 선택 조회 @GetMapping("/{project_id}/notice/{notice_id}") - public NoticeSelectResponseDto getNotice(@PathVariable String project_id, @PathVariable Long notice_id) { + public NoticeSelectResponseDto getNotice(@PathVariable Long project_id, @PathVariable Long notice_id) { return noticeService.getNotice(notice_id); } + //주문폼: 공지 수정 (판매자만 가능) + @PatchMapping("/{project_id}/notice/{notice_id}") + public ResponseEntity updateNotice(@PathVariable Long project_id, @PathVariable Long notice_id, @RequestBody NoticeRequestDto requestDto) + { + return noticeService.updateNotice(project_id, notice_id, requestDto); + } + } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java b/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java index d9fa0fc..47e363c 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java @@ -17,6 +17,7 @@ import wowmarket.wow_server.repository.UserRepository; import java.util.List; +import java.util.Optional; @Service public class NoticeService { @@ -73,4 +74,21 @@ public NoticeSelectResponseDto getNotice(Long notice_id) { // 해당 id 가 있을 경우 return new NoticeSelectResponseDto(notice); } + + //공지 수정 (판매자만 가능) + public ResponseEntity updateNotice(Long project_id, Long notice_id, NoticeRequestDto requestDto) { + User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + Project project = projectRepository.findByProject_Id(project_id); + //판매자만 공지 수정 가능 + if (user.getEmail() == project.getUser().getEmail()){ + Notice notice = noticeRepository.findByNoticeId(notice_id) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + notice.update(requestDto.getTitle(), requestDto.getContent()); + noticeRepository.save(notice); + return new ResponseEntity(HttpStatus.OK); + } + else return new ResponseEntity(HttpStatus.BAD_REQUEST); //판매자 아닐 경우 + } + } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/domain/Notice.java b/src/main/java/wowmarket/wow_server/domain/Notice.java index 31326f0..cd672cd 100644 --- a/src/main/java/wowmarket/wow_server/domain/Notice.java +++ b/src/main/java/wowmarket/wow_server/domain/Notice.java @@ -42,4 +42,9 @@ public Notice(Project project, User user, NoticeRequestDto requestDto) { this.content = requestDto.getContent(); } + public void update(String title, String content) { + this.title = title; + this.content = content; + } + } From a7fa6dc90cab850ffe2d27bce5d64c7d1966c92f Mon Sep 17 00:00:00 2001 From: Minji Kim Date: Thu, 11 Jan 2024 02:58:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[feat]=20=EA=B3=B5=EC=A7=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/notice/controller/NoticeController.java | 6 ++++++ .../project/notice/service/NoticeService.java | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java b/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java index 2c0c6b9..621fdac 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java +++ b/src/main/java/wowmarket/wow_server/detail/project/notice/controller/NoticeController.java @@ -43,4 +43,10 @@ public ResponseEntity updateNotice(@PathVariable Long project_id, @PathVariable return noticeService.updateNotice(project_id, notice_id, requestDto); } + @DeleteMapping("/{project_id}/notice/{notice_id}") + public ResponseEntity deleteNotice(@PathVariable Long project_id, @PathVariable Long notice_id) + { + return noticeService.deleteNotice(project_id, notice_id); + } + } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java b/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java index 47e363c..4ba28eb 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/notice/service/NoticeService.java @@ -91,4 +91,17 @@ public ResponseEntity updateNotice(Long project_id, Long notice_id, NoticeReques else return new ResponseEntity(HttpStatus.BAD_REQUEST); //판매자 아닐 경우 } + //공지 삭제 (판매자만 가능) + public ResponseEntity deleteNotice(Long project_id, Long notice_id) { + User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + Project project = projectRepository.findByProject_Id(project_id); + //판매자만 공지 삭제 가능 + if (user.getEmail() == project.getUser().getEmail()){ + noticeRepository.deleteById(notice_id); + return new ResponseEntity(HttpStatus.OK); + } + else return new ResponseEntity(HttpStatus.BAD_REQUEST); //판매자 아닐 경우 + } + } \ No newline at end of file From 174f50cf92ae8a3ecf780c472992d0471a1fb214 Mon Sep 17 00:00:00 2001 From: Minji Kim Date: Thu, 11 Jan 2024 03:42:50 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[feat]=20=EB=AC=B8=EC=9D=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95&=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/QuestionController.java | 17 +++++++++ .../question/service/QuestionService.java | 35 ++++++++++++++++--- .../wowmarket/wow_server/domain/Question.java | 6 ++++ .../repository/QuestionRepository.java | 4 +++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java b/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java index 091f123..3c6ff98 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java +++ b/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java @@ -1,7 +1,9 @@ package wowmarket.wow_server.detail.project.question.controller; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import wowmarket.wow_server.detail.project.notice.dto.NoticeRequestDto; import wowmarket.wow_server.detail.project.question.dto.AnswerRequestDto; import wowmarket.wow_server.detail.project.question.dto.AnswerResponseDto; import wowmarket.wow_server.detail.project.question.dto.QuestionRequestDto; @@ -23,6 +25,21 @@ public QuestionResponseDto createQuestion(@PathVariable Long project_id, @Reques return questionService.createQuestion(project_id, requestDto); } + //문의글 수정 (작성자만 가능) + @PatchMapping("/question/{question_id}") + public ResponseEntity updateQuestion(@PathVariable Long question_id, @RequestBody QuestionRequestDto requestDto) + { + return questionService.updateQuestion(question_id, requestDto); + } + + //문의글 삭제 (작성자만 가능) + @DeleteMapping("/question/{question_id}") + public ResponseEntity deleteQuestion(@PathVariable Long question_id) + { + return questionService.deleteQuestion(question_id); + } + + // 문의 전체 조회 @GetMapping("/{project_id}/question") public List getQuestionList(@PathVariable Long project_id) { diff --git a/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java b/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java index 6fd0514..2570c95 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java @@ -1,17 +1,16 @@ package wowmarket.wow_server.detail.project.question.service; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; +import wowmarket.wow_server.detail.project.notice.dto.NoticeRequestDto; import wowmarket.wow_server.detail.project.question.dto.AnswerRequestDto; import wowmarket.wow_server.detail.project.question.dto.AnswerResponseDto; import wowmarket.wow_server.detail.project.question.dto.QuestionRequestDto; import wowmarket.wow_server.detail.project.question.dto.QuestionResponseDto; import wowmarket.wow_server.detail.project.question.dto.QuestionSelectResponseDto; -import wowmarket.wow_server.domain.Answer; -import wowmarket.wow_server.domain.Project; -import wowmarket.wow_server.domain.Question; -import wowmarket.wow_server.domain.User; +import wowmarket.wow_server.domain.*; import wowmarket.wow_server.global.jwt.SecurityUtil; import wowmarket.wow_server.repository.ProjectRepository; import wowmarket.wow_server.repository.QuestionRepository; @@ -47,6 +46,33 @@ public QuestionResponseDto createQuestion(Long project_id, QuestionRequestDto re return questionResponseDto; } + //문의 수정 (글 작성자만 가능) + public ResponseEntity updateQuestion(Long question_id, QuestionRequestDto requestDto) { + User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + Question question = questionRepository.findByQuestion_Id(question_id); + //문의글 작성자만 글 수정 가능 + if (user.getEmail() == question.getUser().getEmail()){ + question.update(requestDto.getTitle(), requestDto.getContent(), requestDto.isSecret()); + questionRepository.save(question); + return new ResponseEntity(HttpStatus.OK); + } + else return new ResponseEntity(HttpStatus.BAD_REQUEST); //문의글 작성자가 아닐 경우 + } + + //문의 삭제 (작성자만 가능) + public ResponseEntity deleteQuestion(Long question_id) { + User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + Question question = questionRepository.findByQuestion_Id(question_id); + //판매자만 공지 삭제 가능 + if (user.getEmail() == question.getUser().getEmail()){ + questionRepository.deleteById(question_id); + return new ResponseEntity(HttpStatus.OK); + } + else return new ResponseEntity(HttpStatus.BAD_REQUEST); //판매자 아닐 경우 + } + // 문의 전체 조회 (비밀글 여부 Response로 출력 ok) public List getQuestionList(Long project_id) { @@ -134,4 +160,5 @@ public AnswerResponseDto createAnswer(Long project_id, Long question_id, AnswerR return null; } + } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/domain/Question.java b/src/main/java/wowmarket/wow_server/domain/Question.java index 39a6bf3..35da8a0 100644 --- a/src/main/java/wowmarket/wow_server/domain/Question.java +++ b/src/main/java/wowmarket/wow_server/domain/Question.java @@ -44,4 +44,10 @@ public Question(Project project, User user, QuestionRequestDto requestDto){ this.content = requestDto.getContent(); } + public void update(String title, String content, boolean secret) { + this.title = title; + this.content = content; + this.secret = secret; + } + } diff --git a/src/main/java/wowmarket/wow_server/repository/QuestionRepository.java b/src/main/java/wowmarket/wow_server/repository/QuestionRepository.java index 49bfc9d..b26fd88 100644 --- a/src/main/java/wowmarket/wow_server/repository/QuestionRepository.java +++ b/src/main/java/wowmarket/wow_server/repository/QuestionRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import wowmarket.wow_server.domain.Notice; +import wowmarket.wow_server.domain.Project; import wowmarket.wow_server.domain.Question; import java.util.List; @@ -17,4 +18,7 @@ public interface QuestionRepository extends JpaRepository { @Query(nativeQuery = true, value = "select * from question where project_id=? and question_id=?") Optional findByProjectIdAndQuestionId(Long project_id, Long question_id); + + @Query(nativeQuery = true, value = "select * from question where question_id =?") + Question findByQuestion_Id(Long questionId); } From e7e6613f8310622562b8940bf44a8f4124bd4469 Mon Sep 17 00:00:00 2001 From: Minji Kim Date: Thu, 11 Jan 2024 04:04:50 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[feat/fix]=20=EB=AC=B8=EC=9D=98=20=EB=8B=B5?= =?UTF-8?q?=EB=B3=80=20=EC=88=98=EC=A0=95&=EC=82=AD=EC=A0=9C=20+=20?= =?UTF-8?q?=EB=AC=B8=EC=9D=98=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EB=8B=B5?= =?UTF-8?q?=EB=B3=80=EB=8F=84=20=ED=95=A8=EA=BB=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/QuestionController.java | 14 +++++++ .../question/service/QuestionService.java | 37 ++++++++++++++++++- .../wowmarket/wow_server/domain/Answer.java | 4 ++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java b/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java index 3c6ff98..9420221 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java +++ b/src/main/java/wowmarket/wow_server/detail/project/question/controller/QuestionController.java @@ -58,4 +58,18 @@ public AnswerResponseDto createAnswer(@PathVariable Long project_id, @PathVariab return questionService.createAnswer(project_id, question_id, requestDto); } + // 문의 답변 수정 (판매자만 가능) + @PatchMapping("/{project_id}/question/{question_id}/answer") + public ResponseEntity updateAnswer(@PathVariable Long project_id, @PathVariable Long question_id, @RequestBody AnswerRequestDto requestDto) + { + return questionService.updateAnswer(project_id, question_id, requestDto); + } + + //문의 답변 삭제 (판매자만 가능) + @DeleteMapping("/{project_id}/question/{question_id}/answer") + public ResponseEntity deleteAnswer(@PathVariable Long project_id, @PathVariable Long question_id) + { + return questionService.deleteAnswer(project_id, question_id); + } + } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java b/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java index 2570c95..2b91ec6 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/question/service/QuestionService.java @@ -65,8 +65,14 @@ public ResponseEntity deleteQuestion(Long question_id) { User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); Question question = questionRepository.findByQuestion_Id(question_id); - //판매자만 공지 삭제 가능 + //판매자만 문의 삭제 가능 if (user.getEmail() == question.getUser().getEmail()){ + //문의 삭제시 문의 답변글도 함께 삭제 + if (answerRepository.existsByQuestionId(question_id)) //문의 답변이 존재하는 경우 + { + Answer answer = answerRepository.findByQuestionId(question_id); + answerRepository.deleteById(answer.getId()); + } questionRepository.deleteById(question_id); return new ResponseEntity(HttpStatus.OK); } @@ -157,8 +163,35 @@ public AnswerResponseDto createAnswer(Long project_id, Long question_id, AnswerR return answerResponseDto; } - return null; } + //문의 답변 수정 (판매자만 가능) + public ResponseEntity updateAnswer(Long project_id, Long question_id, AnswerRequestDto requestDto) { + User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + Project project = projectRepository.findByProject_Id(project_id); + //판매자만 문의 답변 수정 가능 + if (user.getEmail() == project.getUser().getEmail()){ + Answer answer = answerRepository.findByQuestionId(question_id); + answer.update(requestDto.getContent()); + answerRepository.save(answer); + return new ResponseEntity(HttpStatus.OK); + } + else return new ResponseEntity(HttpStatus.BAD_REQUEST); //판매자 아닐 경우 + } + + //문의 답변 삭제 (판매자만 가능) + public ResponseEntity deleteAnswer(Long project_id, Long question_id) { + User user = userRepository.findByEmail(SecurityUtil.getLoginUsername()) + .orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST)); + Project project = projectRepository.findByProject_Id(project_id); + //판매자만 문의 답변 삭제 가능 + if (user.getEmail() == project.getUser().getEmail()){ + Answer answer = answerRepository.findByQuestionId(question_id); + answerRepository.deleteById(answer.getId()); + return new ResponseEntity(HttpStatus.OK); + } + else return new ResponseEntity(HttpStatus.BAD_REQUEST); //판매자 아닐 경우 + } } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/domain/Answer.java b/src/main/java/wowmarket/wow_server/domain/Answer.java index eb4b1d6..3dfc218 100644 --- a/src/main/java/wowmarket/wow_server/domain/Answer.java +++ b/src/main/java/wowmarket/wow_server/domain/Answer.java @@ -49,4 +49,8 @@ public Answer(Project project, Question question, User user, AnswerRequestDto re this.content = requestDto.getContent(); } + public void update(String content) { + this.content = content; + } + }