-
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.
* test: 삭제된 회원 조회 테스트 추가 * refactor: 회원 조회 변경 * feat: 신고 기능 추가 및 테스트 코드 추가 * refactor: 신고 기능 로직 수정 및 테스트 코드 추가 * feat: 신고 api 기능 추가 및 테스트 코드 추가 * fix: 통합 테스트간 데이터 중복 및 index 문제 해결 * refactor: CsvSource null 부분 변경
- Loading branch information
Showing
28 changed files
with
623 additions
and
27 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
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) { | ||
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
Submodule config
updated
from ea25d8 to 2e4604
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.