-
Notifications
You must be signed in to change notification settings - Fork 2
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 #246 from haedoang/feature/report
[feature/report] 리포트 기능 구현
- Loading branch information
Showing
16 changed files
with
380 additions
and
23 deletions.
There are no files selected for viewing
Submodule config
updated
from d72c95 to fa7a7c
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
import com.koliving.api.i18n.LanguageRepository; | ||
import com.koliving.api.location.domain.Location; | ||
import com.koliving.api.location.infra.LocationRepository; | ||
import com.koliving.api.report.application.ReportReasonRepository; | ||
import com.koliving.api.report.domain.ReportReason; | ||
import com.koliving.api.room.domain.Furnishing; | ||
import com.koliving.api.room.domain.FurnishingType; | ||
import com.koliving.api.room.domain.Like; | ||
|
@@ -71,7 +73,8 @@ CommandLineRunner commandLineRunner( | |
LikeRepository likeRepository, | ||
UserRepository userRepository, | ||
PasswordEncoder encoder, | ||
NotificationRepository notificationRepository | ||
NotificationRepository notificationRepository, | ||
ReportReasonRepository reportReasonRepository | ||
) { | ||
return args -> { | ||
initImageFiles(imageFileRepository); | ||
|
@@ -80,9 +83,21 @@ CommandLineRunner commandLineRunner( | |
initLanguages(languageRepository); | ||
User user = initUser(userRepository, encoder, notificationRepository); | ||
initRooms(roomRepository, locationRepository, furnishingRepository, imageFileRepository, likeRepository, user); | ||
initReport(reportReasonRepository); | ||
}; | ||
} | ||
|
||
private void initReport(ReportReasonRepository reportReasonRepository) { | ||
reportReasonRepository.saveAll( | ||
List.of( | ||
ReportReason.of("Not a real Place"), | ||
ReportReason.of("Inappropriate content"), | ||
ReportReason.of("Incorrect information"), | ||
ReportReason.of("Suspected scammer") | ||
) | ||
); | ||
} | ||
|
||
private User initUser(UserRepository userRepository, PasswordEncoder encoder, NotificationRepository notificationRepository) { | ||
final User user = User.valueOf("[email protected]", encoder.encode("test1234!@"), UserRole.USER); | ||
final User user2 = User.valueOf("[email protected]", encoder.encode("test1234!@"), UserRole.USER); | ||
|
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/koliving/api/report/application/ReportReasonRepository.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,11 @@ | ||
package com.koliving.api.report.application; | ||
|
||
import com.koliving.api.report.domain.ReportReason; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* author : haedoang date : 2023/11/29 description : | ||
*/ | ||
public interface ReportReasonRepository extends JpaRepository<ReportReason, Long> { | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/koliving/api/report/application/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,30 @@ | ||
package com.koliving.api.report.application; | ||
|
||
import com.koliving.api.report.application.dto.ReportReasonResponse; | ||
import com.koliving.api.report.application.dto.ReportRequest; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* author : haedoang date : 2023/11/29 description : | ||
*/ | ||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ReportService { | ||
private final ReportReasonRepository reportReasonRepository; | ||
|
||
public List<ReportReasonResponse> getReasons() { | ||
return reportReasonRepository.findAll() | ||
.stream() | ||
.map(ReportReasonResponse::of) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public void saveReport(ReportRequest request) { | ||
//TODO 리포트 로직 구현 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/koliving/api/report/application/dto/ReportReasonResponse.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,21 @@ | ||
package com.koliving.api.report.application.dto; | ||
|
||
import com.koliving.api.report.domain.ReportReason; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
/** | ||
* author : haedoang date : 2023/11/29 description : | ||
*/ | ||
@Schema(description = "리포트 사유 조회") | ||
public record ReportReasonResponse( | ||
@Schema(description = "리포트 사유 고유 ID") | ||
Long id, | ||
|
||
@Schema(description = "리포트 사유 설명") | ||
String desc | ||
) { | ||
|
||
public static ReportReasonResponse of(ReportReason entity) { | ||
return new ReportReasonResponse(entity.getId(), entity.getName()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/koliving/api/report/application/dto/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,16 @@ | ||
package com.koliving.api.report.application.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
/** | ||
* author : haedoang date : 2023/11/29 description : | ||
*/ | ||
@Schema(description = "리포트 사유 조회") | ||
public record ReportRequest( | ||
@Schema(description = "리포트 대상 룸 ID") | ||
Long roomId, | ||
|
||
@Schema(description = "리포트 사유 ID") | ||
Long reportId | ||
) { | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/koliving/api/report/domain/ReportReason.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,42 @@ | ||
package com.koliving.api.report.domain; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import com.koliving.api.base.domain.BaseEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.SQLDelete; | ||
import org.hibernate.annotations.Where; | ||
|
||
/** | ||
* author : haedoang date : 2023/11/29 description : | ||
*/ | ||
@Getter | ||
@Entity(name = "TB_REPORT_REASON") | ||
@SQLDelete(sql = "UPDATE TB_REPORT_REASON SET deleted = true WHERE id = ?") | ||
@Where(clause = "deleted = false") | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class ReportReason extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false, unique = true) | ||
private String name; | ||
|
||
private ReportReason(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static ReportReason of(String name) { | ||
return new ReportReason(name); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/com/koliving/api/report/ui/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,76 @@ | ||
package com.koliving.api.report.ui; | ||
|
||
|
||
import com.koliving.api.base.ErrorResponse; | ||
import com.koliving.api.report.application.ReportService; | ||
import com.koliving.api.report.application.dto.ReportReasonResponse; | ||
import com.koliving.api.report.application.dto.ReportRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
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.RestController; | ||
|
||
@Tag(name = "리포트 API", description = "REPORT API") | ||
@RequestMapping("api/v1/report") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class ReportController { | ||
private final ReportService reportService; | ||
|
||
@Operation( | ||
summary = "리포트 사유 목록", | ||
description = "리포트 사유를 요청합니다", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "리포트 사유 요청 성공", | ||
content = @Content(schema = @Schema(implementation = ReportReasonResponse.class) | ||
) | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "리포트 사유 요청 실패", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class) | ||
) | ||
) | ||
} | ||
) | ||
@GetMapping("/reasons") | ||
public ResponseEntity<List<ReportReasonResponse>> getReasons() { | ||
final List<ReportReasonResponse> responses = reportService.getReasons(); | ||
return ResponseEntity.ok() | ||
.body(responses); | ||
} | ||
|
||
|
||
@Operation( | ||
summary = "리포트 요청", | ||
description = "리포트를 요청합니다", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "201", | ||
description = "리포트 요청 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "리포트 요청 실패", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class) | ||
) | ||
) | ||
} | ||
) | ||
@PostMapping("/reasons") | ||
public ResponseEntity<Void> report(@RequestBody ReportRequest request) { | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
} |
Oops, something went wrong.