Skip to content

Commit

Permalink
#1 [FEAT] 알림 리스트 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
bbabbi committed Dec 21, 2024
1 parent 92ec1ef commit df51490
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.vsa.server.Notification.controller;

import org.vsa.server.Notification.dto.NotificationResponseDto;
import org.vsa.server.Notification.service.NotificationService;
import org.vsa.server.common.FindLoginMember;
import org.vsa.server.member.dto.response.PostWrittenDto;
import org.vsa.server.member.repository.MemberRepository;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class NotificationController {

@Autowired
private NotificationService notificationService;
@Autowired
private MemberRepository memberRepository;

@GetMapping("/notification")
@Operation(summary = "알림 리스트", description = "알림 리스트")
public ResponseEntity<Page<NotificationResponseDto>> getNotifications(@RequestParam(required = false, defaultValue = "0", value = "page") int pageNo) {

String memberEmail = FindLoginMember.getCurrentUserId();

Long memberId = memberRepository.findBySocialId(memberEmail).getMemberId();


Page<NotificationResponseDto> notificationList = notificationService.findAllNotification(memberId,pageNo);

return ResponseEntity.ok(notificationList);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.vsa.server.Notification.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@Builder
@AllArgsConstructor
public class NotificationResponseDto {

private Long notificationId;
private LocalDateTime startNotification;
private Boolean isRead;
private String message;
private Long paramId;
private String type;
}


Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.vsa.server.Notification.service;

import org.springframework.data.domain.PageImpl;
import org.vsa.server.Notification.dto.NotificationResponseDto;
import org.vsa.server.Notification.entity.Notification;
import org.vsa.server.Notification.repository.NotificationRepository;
import lombok.Data;
Expand All @@ -10,6 +12,9 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Data
@NoArgsConstructor
Expand All @@ -18,13 +23,25 @@ public class NotificationService {
@Autowired
private NotificationRepository notificationRepository;

public Page<Notification> findAllNotification(Long memberId, int pageNo){
public Page<NotificationResponseDto> findAllNotification(Long memberId, int pageNo){

Pageable pageable = PageRequest.of(pageNo,8);
Pageable pageable = PageRequest.of(pageNo,10);

Page<Notification> notifications = notificationRepository.findAllByMember_MemberId(memberId,pageable);

return notifications;

List<NotificationResponseDto> myNotificationList = notifications.stream()
.map(notification -> NotificationResponseDto.builder()
.notificationId(notification.getId())
.message(notification.getMessage()) // Null 체크
.startNotification(notification.getCreatedAt())
.isRead(notification.getIsRead())
.paramId(notification.getParamId())
.type(notification.getType())
.build())
.collect(Collectors.toList());

return new PageImpl<>(myNotificationList, pageable, notifications.getTotalElements());
}


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/vsa/server/member/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SecurityConfig(JwtUtil jwtUtil,AuthenticationConfiguration authentication
"/webjars/**", // Webjars used by Swagger UI
"/api/oauth", // 카카오 로그인 엔드포인트
"/api/logout", // 로그아웃 엔드포인트
"/actuator/health" // healthcheck
"/actuator/health"
};

@Bean
Expand All @@ -47,7 +47,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf(csrf -> csrf.disable()) // CSRF 비활성화
.authorizeRequests(auth -> auth
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // CORS 프리플라이트 요청 허용
.requestMatchers("/api/inquire","/api/view").hasAnyRole("ADMIN", "STANDARD", "PREMIUM")
.requestMatchers("/api/inquire","/api/view").hasAnyAuthority("ADMIN", "STANDARD", "PREMIUM")
.requestMatchers(AUTH_WHITELIST).permitAll()// 인증이 필요 없는 요청들
.anyRequest().authenticated() // 그 외 요청은 인증 필요
)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/vsa/server/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Member extends BaseEntity {
@OneToOne(mappedBy = "member", cascade = CascadeType.ALL)
private Subscribe subscribe;

@Enumerated(EnumType.STRING)
private UserRole userRole;

private String password;
Expand Down Expand Up @@ -59,4 +60,4 @@ public Member(Long subscribeId, UserRole userRole, String password, String nickN
this.authKey = authKey;
this.billingKey = billingKey;
}
}
}

0 comments on commit df51490

Please sign in to comment.