-
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.
Browse files
Browse the repository at this point in the history
BE/#255 알림 목록 조회 기능 구현
- Loading branch information
Showing
6 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...c/main/java/com/graphy/backend/domain/notification/controller/NotificationController.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,34 @@ | ||
package com.graphy.backend.domain.notification.controller; | ||
|
||
import com.graphy.backend.domain.auth.util.annotation.CurrentUser; | ||
import com.graphy.backend.domain.member.domain.Member; | ||
import com.graphy.backend.domain.notification.dto.response.GetNotificationResponse; | ||
import com.graphy.backend.domain.notification.service.NotificationService; | ||
import com.graphy.backend.global.common.PageRequest; | ||
import com.graphy.backend.global.result.ResultCode; | ||
import com.graphy.backend.global.result.ResultResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
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.util.List; | ||
|
||
@Tag(name = "NotificationController", description = "알림 관련 API") | ||
@RestController | ||
@RequestMapping("/api/v1/notifications") | ||
@RequiredArgsConstructor | ||
public class NotificationController { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@Operation(summary = "findNotificationList", description = "알림 목록 조회") | ||
@GetMapping | ||
public ResponseEntity<ResultResponse> notificationList(PageRequest pageRequest, @CurrentUser Member loginUser) { | ||
List<GetNotificationResponse> result = notificationService.findNotificationList(pageRequest, loginUser); | ||
return ResponseEntity.ok(ResultResponse.of(ResultCode.NOTIFICATION_PAGING_GET_SUCCESS, result)); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...ain/java/com/graphy/backend/domain/notification/dto/response/GetNotificationResponse.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,36 @@ | ||
package com.graphy.backend.domain.notification.dto.response; | ||
|
||
import com.graphy.backend.domain.notification.domain.Notification; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class GetNotificationResponse { | ||
private Long id; | ||
private String type; | ||
private String content; | ||
private boolean isRead; | ||
|
||
public static GetNotificationResponse from(Notification notification) { | ||
return GetNotificationResponse.builder() | ||
.id(notification.getId()) | ||
.type(notification.getType().toString()) | ||
.content(notification.getContent()) | ||
.isRead(notification.isRead()) | ||
.build(); | ||
} | ||
|
||
public static List<GetNotificationResponse> from(List<Notification> notifications) { | ||
return notifications.stream() | ||
.map(GetNotificationResponse::from) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
...c/main/java/com/graphy/backend/domain/notification/repository/NotificationRepository.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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.graphy.backend.domain.notification.repository; | ||
|
||
import com.graphy.backend.domain.notification.domain.Notification; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NotificationRepository extends JpaRepository<Notification, Long> { | ||
|
||
Page<Notification> findAllByMemberId(Long memberId, Pageable pageable); | ||
} |
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
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