Skip to content

Commit

Permalink
Merge pull request #246 from haedoang/feature/report
Browse files Browse the repository at this point in the history
[feature/report] 리포트 기능 구현
  • Loading branch information
haedoang authored Nov 29, 2023
2 parents 400fea3 + cbde0f3 commit 5ea1e29
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config
17 changes: 16 additions & 1 deletion src/main/java/com/koliving/api/KolivingApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,7 +73,8 @@ CommandLineRunner commandLineRunner(
LikeRepository likeRepository,
UserRepository userRepository,
PasswordEncoder encoder,
NotificationRepository notificationRepository
NotificationRepository notificationRepository,
ReportReasonRepository reportReasonRepository
) {
return args -> {
initImageFiles(imageFileRepository);
Expand All @@ -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);
Expand Down
54 changes: 50 additions & 4 deletions src/main/java/com/koliving/api/my/ui/MyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.koliving.api.room.application.RoomService;
import com.koliving.api.room.application.dto.RoomResponse;
import com.koliving.api.user.application.dto.NotificationResponse;
import com.koliving.api.user.domain.NotifyType;
import com.koliving.api.user.domain.User;
import com.koliving.api.user.application.UserService;
import com.koliving.api.user.application.dto.UserResponse;
Expand All @@ -20,9 +21,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


Expand Down Expand Up @@ -86,7 +89,8 @@ public ResponseEntity<UserResponse> myProfile(@AuthenticationPrincipal User user
responses = {
@ApiResponse(
responseCode = "200",
description = "좋아요 게시글 조회 성공"
description = "좋아요 게시글 조회 성공",
content = @Content(schema = @Schema(implementation = RoomResponse.class))
),
@ApiResponse(
responseCode = "400",
Expand All @@ -108,7 +112,8 @@ public ResponseEntity<Page<RoomResponse>> getLikedRooms(Pageable pageable, @Auth
responses = {
@ApiResponse(
responseCode = "200",
description = "알림 리스트 조회 성공"
description = "알림 리스트 조회 성공",
content = @Content(schema = @Schema(implementation = NotificationResponse.class))
),
@ApiResponse(
responseCode = "400",
Expand All @@ -117,9 +122,50 @@ public ResponseEntity<Page<RoomResponse>> getLikedRooms(Pageable pageable, @Auth
),
})
@GetMapping("/notification")
public ResponseEntity<List<NotificationResponse>> getNotifications(@AuthenticationPrincipal User user) {
List<NotificationResponse> responses = userService.getNotifications(user);
public ResponseEntity<List<NotificationResponse>> getNotifications(@RequestParam(name = "notifyType", defaultValue = "ALL") NotifyType notifyType, @AuthenticationPrincipal User user) {
List<NotificationResponse> responses = userService.getNotifications(notifyType, user);
return ResponseEntity.ok()
.body(responses);
}

@Operation(
summary = "알림 확인하기",
description = "알림을 확인합니다",
responses = {
@ApiResponse(
responseCode = "200",
description = "알림 확인 성공"
),
@ApiResponse(
responseCode = "400",
description = "알림 확인 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
})
@PutMapping("/notification/{id}")
public ResponseEntity<Void> notificationConfirmed(@PathVariable Long id, @AuthenticationPrincipal User user) {
userService.notificationConfirmed(id, user);
return ResponseEntity.ok()
.build();
}

@Operation(
summary = "수신 새 알림 조회",
description = "수신 새 알림을 조회합니다",
responses = {
@ApiResponse(
responseCode = "200",
description = "수신 새 알림 확인 성공"
),
@ApiResponse(
responseCode = "400",
description = "수신 새 알림 확인 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
})
@GetMapping("/notification/check")
public ResponseEntity<List<NotificationResponse>> hasCheckedNewNotification(@AuthenticationPrincipal User user) {
List<NotificationResponse> responses = userService.hasCheckedNewNotification(user);
return ResponseEntity.ok().body(responses);
}
}
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> {

}
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 리포트 로직 구현
}
}
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());
}
}
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 src/main/java/com/koliving/api/report/domain/ReportReason.java
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 src/main/java/com/koliving/api/report/ui/ReportController.java
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();
}
}
Loading

0 comments on commit 5ea1e29

Please sign in to comment.