-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : 데일리 답변에 대한 신고 기능 추가, 유저 신고 로직 수정 #114
- Loading branch information
1 parent
5716f0b
commit 34d8495
Showing
20 changed files
with
293 additions
and
41 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
16 changes: 16 additions & 0 deletions
16
Api/src/main/java/tify/server/api/answer/model/response/AnswerReportResponse.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,16 @@ | ||
package tify.server.api.answer.model.response; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class AnswerReportResponse { | ||
|
||
private final Long userId; | ||
|
||
private final Long answerId; | ||
|
||
private final boolean reportSuccess; | ||
} |
16 changes: 0 additions & 16 deletions
16
Api/src/main/java/tify/server/api/answer/model/response/RetrieveAnswerCountResponse.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
Api/src/main/java/tify/server/api/answer/model/vo/RetrieveAnswerCountVo.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,16 @@ | ||
package tify.server.api.answer.model.vo; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class RetrieveAnswerCountVo { | ||
|
||
private final Long answerCount; | ||
|
||
public static RetrieveAnswerCountVo of(Long answerCount) { | ||
return RetrieveAnswerCountVo.builder().answerCount(answerCount).build(); | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
Api/src/main/java/tify/server/api/answer/service/CreateDailyAnswerReportUseCase.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,51 @@ | ||
package tify.server.api.answer.service; | ||
|
||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
import static org.springframework.http.HttpStatus.OK; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import tify.server.api.answer.model.response.AnswerReportResponse; | ||
import tify.server.api.config.security.SecurityUtils; | ||
import tify.server.core.annotation.UseCase; | ||
import tify.server.domain.domains.question.adaptor.AnswerReportAdaptor; | ||
import tify.server.domain.domains.question.domain.AnswerReport; | ||
import tify.server.domain.domains.question.validator.AnswerReportValidator; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class CreateDailyAnswerReportUseCase { | ||
|
||
private final AnswerReportAdaptor answerReportAdaptor; | ||
private final AnswerReportValidator answerReportValidator; | ||
|
||
@Transactional | ||
public ResponseEntity<AnswerReportResponse> execute(Long answerId) { | ||
Long currentUserId = SecurityUtils.getCurrentUserId(); | ||
Optional<AnswerReport> report = | ||
answerReportAdaptor.optionalQueryByUserIdAndAnswerId(currentUserId, answerId); | ||
if (report.isPresent()) { | ||
AnswerReportResponse response = | ||
AnswerReportResponse.builder() | ||
.userId(currentUserId) | ||
.answerId(answerId) | ||
.reportSuccess(false) | ||
.build(); | ||
return new ResponseEntity<>(response, new HttpHeaders(), BAD_REQUEST); | ||
} else { | ||
answerReportValidator.isMyAnswer(currentUserId, answerId); | ||
answerReportAdaptor.save( | ||
AnswerReport.builder().reportUserId(currentUserId).answerId(answerId).build()); | ||
AnswerReportResponse response = | ||
AnswerReportResponse.builder() | ||
.userId(currentUserId) | ||
.answerId(answerId) | ||
.reportSuccess(true) | ||
.build(); | ||
return new ResponseEntity<>(response, new HttpHeaders(), OK); | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
Api/src/main/java/tify/server/api/user/model/dto/response/UserReportResponse.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 tify.server.api.user.model.dto.response; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class UserReportResponse { | ||
|
||
private final Long fromUserId; | ||
private final Long toUserId; | ||
private final boolean reportSuccess; | ||
} |
38 changes: 30 additions & 8 deletions
38
Api/src/main/java/tify/server/api/user/service/CreateUserReportUseCase.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,30 +1,52 @@ | ||
package tify.server.api.user.service; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import tify.server.api.config.security.SecurityUtils; | ||
import tify.server.api.user.model.dto.response.UserReportResponse; | ||
import tify.server.core.annotation.UseCase; | ||
import tify.server.domain.domains.user.adaptor.UserAdaptor; | ||
import tify.server.domain.domains.user.adaptor.UserReportAdaptor; | ||
import tify.server.domain.domains.user.domain.UserReport; | ||
import tify.server.domain.domains.user.validator.UserValidator; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class CreateUserReportUseCase { | ||
|
||
private final UserReportAdaptor userReportAdaptor; | ||
private final UserAdaptor userAdaptor; | ||
private final UserValidator userValidator; | ||
|
||
@Transactional | ||
public void execute(Long userId) { | ||
public ResponseEntity<UserReportResponse> execute(Long userId) { | ||
Long currentUserId = SecurityUtils.getCurrentUserId(); | ||
userReportAdaptor.save( | ||
UserReport.builder() | ||
.fromUserId(currentUserId) | ||
.toUserId(userAdaptor.query(userId).getId()) | ||
.build()); | ||
Optional<UserReport> report = | ||
userReportAdaptor.optionalQueryByFromUserIdAndToUserId(currentUserId, userId); | ||
if (report.isPresent()) { // 이미 신고가 존재할 때 | ||
UserReportResponse response = | ||
UserReportResponse.builder() | ||
.fromUserId(currentUserId) | ||
.toUserId(userId) | ||
.reportSuccess(false) | ||
.build(); | ||
return new ResponseEntity<>(response, new HttpHeaders(), BAD_REQUEST); | ||
} else { // 새로운 신고일 때 | ||
userReportAdaptor.save( | ||
UserReport.builder() | ||
.fromUserId(currentUserId) | ||
.toUserId(userAdaptor.query(userId).getId()) | ||
.build()); | ||
UserReportResponse response = | ||
UserReportResponse.builder() | ||
.fromUserId(currentUserId) | ||
.toUserId(userId) | ||
.reportSuccess(true) | ||
.build(); | ||
return new ResponseEntity<>(response, new HttpHeaders(), OK); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Domain/src/main/java/tify/server/domain/domains/question/adaptor/AnswerReportAdaptor.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,30 @@ | ||
package tify.server.domain.domains.question.adaptor; | ||
|
||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import tify.server.core.annotation.Adaptor; | ||
import tify.server.domain.domains.question.domain.AnswerReport; | ||
import tify.server.domain.domains.question.exception.AnswerReportNotFoundException; | ||
import tify.server.domain.domains.question.repository.AnswerReportRepository; | ||
|
||
@Adaptor | ||
@RequiredArgsConstructor | ||
public class AnswerReportAdaptor { | ||
|
||
private final AnswerReportRepository answerReportRepository; | ||
|
||
public AnswerReport query(Long id) { | ||
return answerReportRepository | ||
.findById(id) | ||
.orElseThrow(() -> AnswerReportNotFoundException.EXCEPTION); | ||
} | ||
|
||
public Optional<AnswerReport> optionalQueryByUserIdAndAnswerId(Long userId, Long answerId) { | ||
return answerReportRepository.findByAnswerIdAndReportUserId(answerId, userId); | ||
} | ||
|
||
public void save(AnswerReport answerReport) { | ||
answerReportRepository.save(answerReport); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Domain/src/main/java/tify/server/domain/domains/question/domain/AnswerReport.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,35 @@ | ||
package tify.server.domain.domains.question.domain; | ||
|
||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import tify.server.domain.domains.AbstractTimeStamp; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "tbl_answer_report") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class AnswerReport extends AbstractTimeStamp { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotNull private Long answerId; | ||
|
||
@NotNull private Long reportUserId; | ||
|
||
@Builder | ||
public AnswerReport(Long answerId, Long reportUserId) { | ||
this.answerId = answerId; | ||
this.reportUserId = reportUserId; | ||
} | ||
} |
Oops, something went wrong.