From 271aa351e0258ba6e7b927ba8ae4b62816c1fa18 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Sat, 10 Aug 2024 22:06:48 +0900 Subject: [PATCH] feat get Info Noti API --- .../InfoNotificationController.java | 33 +++++++++++++++++ .../notification/domain/InfoNotification.java | 24 +++++++++++++ .../domain/InfoNotificationType.java | 5 +++ .../InfoNotificationAllResponseDto.java | 18 ++++++++++ .../InfoNotificationRepository.java | 11 ++++++ .../service/InfoNotificationQueryService.java | 35 +++++++++++++++++++ .../common/response/SuccessStatus.java | 2 ++ 7 files changed, 128 insertions(+) create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/notification/controller/InfoNotificationController.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotification.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotificationType.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/notification/dto/response/InfoNotificationAllResponseDto.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/notification/repository/InfoNotificationRepository.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/InfoNotificationQueryService.java diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/controller/InfoNotificationController.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/controller/InfoNotificationController.java new file mode 100644 index 0000000..00bb828 --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/controller/InfoNotificationController.java @@ -0,0 +1,33 @@ +package com.wable.www.WableServer.api.notification.controller; + +import com.wable.www.WableServer.api.notification.service.InfoNotificationQueryService; +import com.wable.www.WableServer.common.response.ApiResponse; +import com.wable.www.WableServer.common.response.SuccessStatus; +import com.wable.www.WableServer.common.util.MemberUtil; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; + +@RestController +@RequestMapping("/api/v1/") +@RequiredArgsConstructor +@SecurityRequirement(name = "JWT Auth") +@Tag(name="정보 노티 관련",description = "Information Notification Api Document") +public class InfoNotificationController { + private final InfoNotificationQueryService infoNotificationQueryService; + + @GetMapping("notification/info/all") + @Operation(summary = "정보 노티 목록 조회 API 입니다.",description = "InfoNotiList") + public ResponseEntity> getInfoNotification(Principal principal) { + Long memberId = MemberUtil.getMemberId(principal); + return ApiResponse.success(SuccessStatus.INFO_NOTIFICATION_ALL_SUCCESS, + infoNotificationQueryService.getInfoNotification(memberId)); + } +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotification.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotification.java new file mode 100644 index 0000000..df1f063 --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotification.java @@ -0,0 +1,24 @@ +package com.wable.www.WableServer.api.notification.domain; + +import com.wable.www.WableServer.api.member.domain.Member; +import com.wable.www.WableServer.common.entity.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import static lombok.AccessLevel.PROTECTED; + +@Entity +@Getter +@NoArgsConstructor(access = PROTECTED) +public class InfoNotification extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "target_member_id") + private Member infoNotificationTargetMember; + + private InfoNotificationType infoNotificationType; +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotificationType.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotificationType.java new file mode 100644 index 0000000..9bb3b6b --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/domain/InfoNotificationType.java @@ -0,0 +1,5 @@ +package com.wable.www.WableServer.api.notification.domain; + +public enum InfoNotificationType { + GAMEDONE, GAMESTART, WEEKDONE +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/dto/response/InfoNotificationAllResponseDto.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/dto/response/InfoNotificationAllResponseDto.java new file mode 100644 index 0000000..07819ff --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/dto/response/InfoNotificationAllResponseDto.java @@ -0,0 +1,18 @@ +package com.wable.www.WableServer.api.notification.dto.response; + +import com.wable.www.WableServer.api.notification.domain.InfoNotification; +import com.wable.www.WableServer.common.util.TimeUtilCustom; + +public record InfoNotificationAllResponseDto( + String InfoNotificationType, + String time, + String imageUrl +) { + public static InfoNotificationAllResponseDto of(InfoNotification infoNotification, String imageUrl) { + return new InfoNotificationAllResponseDto( + infoNotification.getInfoNotificationType().name(), + TimeUtilCustom.refineTime(infoNotification.getCreatedAt()), + imageUrl + ); + } +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/repository/InfoNotificationRepository.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/repository/InfoNotificationRepository.java new file mode 100644 index 0000000..89de54c --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/repository/InfoNotificationRepository.java @@ -0,0 +1,11 @@ +package com.wable.www.WableServer.api.notification.repository; + +import com.wable.www.WableServer.api.member.domain.Member; +import com.wable.www.WableServer.api.notification.domain.InfoNotification; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface InfoNotificationRepository extends JpaRepository { + List findAllByInfoNotificationTargetMemberOrderByCreatedAtDesc(Member member); +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/InfoNotificationQueryService.java b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/InfoNotificationQueryService.java new file mode 100644 index 0000000..f6671ca --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/notification/service/InfoNotificationQueryService.java @@ -0,0 +1,35 @@ +package com.wable.www.WableServer.api.notification.service; + +import com.wable.www.WableServer.api.member.domain.Member; +import com.wable.www.WableServer.api.member.repository.MemberRepository; +import com.wable.www.WableServer.api.notification.domain.InfoNotification; +import com.wable.www.WableServer.api.notification.dto.response.InfoNotificationAllResponseDto; +import com.wable.www.WableServer.api.notification.repository.InfoNotificationRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class InfoNotificationQueryService { + @Value("${aws-property.s3-info-image-url}") + private String INFO_IMAGE_S3; + + private final InfoNotificationRepository infoNotificationRepository; + private final MemberRepository memberRepository; + public List getInfoNotification(Long memberId) { + Member member = memberRepository.findMemberByIdOrThrow(memberId); + List infoNotifications = + infoNotificationRepository.findAllByInfoNotificationTargetMemberOrderByCreatedAtDesc(member); + + return infoNotifications.stream() + .map(infoNotification -> InfoNotificationAllResponseDto.of( + infoNotification, + INFO_IMAGE_S3 + )).collect(Collectors.toList()); + } + +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/common/response/SuccessStatus.java b/WableServer/src/main/java/com/wable/www/WableServer/common/response/SuccessStatus.java index 35df66a..abea78a 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/common/response/SuccessStatus.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/common/response/SuccessStatus.java @@ -47,6 +47,8 @@ public enum SuccessStatus { PATCH_MEMBER_PROFILE(HttpStatus.OK, "프로필 수정 완료"), NICKNAME_CHECK_SUCCESS(HttpStatus.OK, "사용 가능한 닉네임 입니다."), NOTIFICATION_ALL_SUCCESS(HttpStatus.OK,"알림 전체 조회 성공"), + INFO_NOTIFICATION_ALL_SUCCESS(HttpStatus.OK,"정보 알림 전체 조회 성공"), + /** * notification */