-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 방/회원/인증 신고 기능 추가 #158
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e39e7f1
test: 삭제된 회원 조회 테스트 추가
parksey 0e339ff
refactor: 회원 조회 변경
parksey 3c10ab6
feat: 신고 기능 추가 및 테스트 코드 추가
parksey cfec3f8
refactor: 신고 기능 로직 수정 및 테스트 코드 추가
parksey e9679dd
feat: 신고 api 기능 추가 및 테스트 코드 추가
parksey b2ba6eb
fix: 통합 테스트간 데이터 중복 및 index 문제 해결
parksey 35ab8d4
refactor: CsvSource null 부분 변경
parksey d781652
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey 7b5bfba
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/moabam/api/application/report/ReportMapper.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,23 @@ | ||
package com.moabam.api.application.report; | ||
|
||
import com.moabam.api.domain.report.Report; | ||
import com.moabam.api.domain.room.Certification; | ||
import com.moabam.api.domain.room.Room; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ReportMapper { | ||
|
||
public static Report toReport(Long reporterId, Long reportedMemberId, | ||
Room room, Certification certification, String description) { | ||
return Report.builder() | ||
.reporterId(reporterId) | ||
.reportedMemberId(reportedMemberId) | ||
.certification(certification) | ||
.room(room) | ||
.description(description) | ||
.build(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/moabam/api/application/report/ReportService.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,60 @@ | ||
package com.moabam.api.application.report; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.moabam.api.application.member.MemberService; | ||
import com.moabam.api.application.room.CertificationService; | ||
import com.moabam.api.application.room.RoomService; | ||
import com.moabam.api.domain.member.Member; | ||
import com.moabam.api.domain.report.Report; | ||
import com.moabam.api.domain.report.repository.ReportRepository; | ||
import com.moabam.api.domain.room.Certification; | ||
import com.moabam.api.domain.room.Room; | ||
import com.moabam.api.dto.report.ReportRequest; | ||
import com.moabam.global.auth.model.AuthMember; | ||
import com.moabam.global.error.exception.BadRequestException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReportService { | ||
|
||
private final MemberService memberService; | ||
private final RoomService roomService; | ||
private final CertificationService certificationService; | ||
private final ReportRepository reportRepository; | ||
|
||
@Transactional | ||
public void report(AuthMember authMember, ReportRequest reportRequest) { | ||
validateNoReportSubject(reportRequest.roomId(), reportRequest.certificationId()); | ||
Report report = createReport(authMember.id(), reportRequest); | ||
reportRepository.save(report); | ||
} | ||
|
||
private Report createReport(Long reporterId, ReportRequest reportRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. R: 네이밍 수정쫌... create에 찌들어버렸어 ,, |
||
Member reportedMember = memberService.findMember(reportRequest.reportedId()); | ||
|
||
if (nonNull(reportRequest.certificationId())) { | ||
Certification certification = certificationService.findCertification(reportRequest.certificationId()); | ||
|
||
return ReportMapper.toReport(reporterId, reportedMember.getId(), | ||
null, certification, reportRequest.description()); | ||
} | ||
|
||
Room room = roomService.findRoom(reportRequest.roomId()); | ||
|
||
return ReportMapper.toReport(reporterId, reportedMember.getId(), | ||
room, null, reportRequest.description()); | ||
} | ||
|
||
private void validateNoReportSubject(Long roomId, Long certificationId) { | ||
if (isNull(roomId) && isNull(certificationId)) { | ||
throw new BadRequestException(ErrorMessage.REPORT_REQUEST_ERROR); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.moabam.api.domain.report; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import com.moabam.api.domain.room.Certification; | ||
import com.moabam.api.domain.room.Room; | ||
import com.moabam.global.common.entity.BaseTimeEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "report") | ||
@Entity | ||
public class Report extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "reporter_id", nullable = false, updatable = false) | ||
private Long reporterId; | ||
|
||
@Column(name = "reported_member_id", nullable = false, updatable = false) | ||
private Long reportedMemberId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "room_id", updatable = false) | ||
private Room room; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "certification_id", updatable = false) | ||
private Certification certification; | ||
|
||
@Column(name = "description") | ||
private String description; | ||
|
||
@Builder | ||
private Report(Long reporterId, Long reportedMemberId, Room room, Certification certification, String description) { | ||
this.reporterId = requireNonNull(reporterId); | ||
this.reportedMemberId = requireNonNull(reportedMemberId); | ||
this.room = room; | ||
this.certification = certification; | ||
this.description = description; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/moabam/api/domain/report/repository/ReportRepository.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,9 @@ | ||
package com.moabam.api.domain.report.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.moabam.api.domain.report.Report; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moabam/api/dto/report/ReportRequest.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,12 @@ | ||
package com.moabam.api.dto.report; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record ReportRequest( | ||
@NotNull Long reportedId, | ||
Long roomId, | ||
Long certificationId, | ||
String description | ||
) { | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/moabam/api/presentation/ReportController.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 com.moabam.api.presentation; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.moabam.api.application.report.ReportService; | ||
import com.moabam.api.dto.report.ReportRequest; | ||
import com.moabam.global.auth.annotation.Auth; | ||
import com.moabam.global.auth.model.AuthMember; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/reports") | ||
@RequiredArgsConstructor | ||
public class ReportController { | ||
|
||
private final ReportService reportService; | ||
|
||
@PostMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
public void reports(@Auth AuthMember authMember, @Valid @RequestBody ReportRequest reportRequest) { | ||
reportService.report(authMember, reportRequest); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: report, createReport는 어떤 기능을 하는 서비스인가요?