Skip to content

Commit

Permalink
feat get Info Noti API
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong0329 committed Aug 10, 2024
1 parent e3b2933 commit 271aa35
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ApiResponse<Object>> getInfoNotification(Principal principal) {
Long memberId = MemberUtil.getMemberId(principal);
return ApiResponse.success(SuccessStatus.INFO_NOTIFICATION_ALL_SUCCESS,
infoNotificationQueryService.getInfoNotification(memberId));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wable.www.WableServer.api.notification.domain;

public enum InfoNotificationType {
GAMEDONE, GAMESTART, WEEKDONE
}
Original file line number Diff line number Diff line change
@@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -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<InfoNotification, Long> {
List<InfoNotification> findAllByInfoNotificationTargetMemberOrderByCreatedAtDesc(Member member);
}
Original file line number Diff line number Diff line change
@@ -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<InfoNotificationAllResponseDto> getInfoNotification(Long memberId) {
Member member = memberRepository.findMemberByIdOrThrow(memberId);
List<InfoNotification> infoNotifications =
infoNotificationRepository.findAllByInfoNotificationTargetMemberOrderByCreatedAtDesc(member);

return infoNotifications.stream()
.map(infoNotification -> InfoNotificationAllResponseDto.of(
infoNotification,
INFO_IMAGE_S3
)).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 271aa35

Please sign in to comment.