Skip to content

Commit

Permalink
[FEAT] 알림 전체 읽기 (#155)
Browse files Browse the repository at this point in the history
* config: 프론트 개발서버 CORS 추가

* refactor: 커스텀 리파지토리 의존 관계 개선

* fix: 알림 읽음 엔드포인트 PATCH에서 POST로 변경

* feat: 알림 모두 읽기 구현

* style: 불필요한 공백 제거

* fix: 카카오 예외처리 info에서 error 로그로 변경
  • Loading branch information
Profile-exe authored Sep 13, 2024
1 parent d577515 commit 1b71a79
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Exception decode(String methodKey, feign.Response response) {
throw new RuntimeException(e);
}

log.info("Kakao Api Exception occurred: {}", kakaoErrorResponse.errorDescription());
log.error("Kakao Api Exception occurred: {}", kakaoErrorResponse.errorDescription());
yield FeignKakaoException.EXCEPTION;
}
case 404 -> {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/econo/buddybridge/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public void addCorsMappings(CorsRegistry registry) { // CORS 설정
"http://localhost:3000", "https://localhost:3000",
"http://localhost:8080", "https://localhost:8080",
"http://localhost:8081", "https://localhost:8081",
"https://buddy-bridge.vercel.app/"
"https://buddy-bridge.vercel.app/",
"https://buddy-bridge-develop-server.vercel.app/"
)
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -39,7 +39,7 @@ public ApiResponse<CustomBody<NotificationCustomPage>> getNotifications(
}

@Operation(summary = "알림 읽음 처리", description = "알림을 읽음 처리합니다.")
@PatchMapping("/{notification-id}/read")
@PostMapping("/{notification-id}/read")
public ApiResponse<CustomBody<Void>> markAsRead(
@PathVariable("notification-id") Long notificationId,
HttpServletRequest request
Expand All @@ -48,4 +48,11 @@ public ApiResponse<CustomBody<Void>> markAsRead(
notificationService.markAsRead(notificationId, memberId);
return ApiResponseGenerator.success(HttpStatus.OK);
}

@PostMapping("/read-all")
public ApiResponse<CustomBody<Void>> markAllAsRead(HttpServletRequest request) {
Long memberId = SessionUtils.getMemberId(request);
notificationService.markAllAsRead(memberId);
return ApiResponseGenerator.success(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import econo.buddybridge.notification.entity.Notification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface NotificationRepository extends JpaRepository<Notification, Long> {
public interface NotificationRepository extends JpaRepository<Notification, Long>, NotificationRepositoryCustom {

@Modifying(flushAutomatically = true, clearAutomatically = true)
@Query("update Notification n set n.isRead = true where n.receiver.id = :memberId")
void markAllAsRead(@Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package econo.buddybridge.notification.repository;

import econo.buddybridge.notification.dto.NotificationCustomPage;
import org.springframework.stereotype.Repository;

@Repository
public interface NotificationRepositoryCustom {
NotificationCustomPage findByMemberId(Long memberId, Integer size, Long cursor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import econo.buddybridge.notification.exception.NotificationAccessDeniedException;
import econo.buddybridge.notification.exception.NotificationNotFoundException;
import econo.buddybridge.notification.repository.NotificationRepository;
import econo.buddybridge.notification.repository.NotificationRepositoryCustom;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -18,7 +17,6 @@ public class NotificationService {

private final MemberService memberService;
private final NotificationRepository notificationRepository;
private final NotificationRepositoryCustom notificationRepositoryCustom;

@Transactional
public void saveNotification(Notification notification) {
Expand All @@ -28,7 +26,7 @@ public void saveNotification(Notification notification) {
@Transactional(readOnly = true)
public NotificationCustomPage getNotifications(Long memberId, Integer size, Long cursor) {
Member member = memberService.findMemberByIdOrThrow(memberId);
return notificationRepositoryCustom.findByMemberId(member.getId(), size, cursor);
return notificationRepository.findByMemberId(member.getId(), size, cursor);
}

@Transactional
Expand All @@ -44,4 +42,10 @@ public void markAsRead(Long notificationId, Long memberId) {

notification.markAsRead();
}

@Transactional
public void markAllAsRead(Long memberId) {
Member member = memberService.findMemberByIdOrThrow(memberId);
notificationRepository.markAllAsRead(member.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public ApiResponse<ApiResponse.CustomBody<Boolean>> managePostLike(
return ApiResponseGenerator.success(isLike, HttpStatus.OK);
}


@Operation(summary = "찜한 게시글 목록 조회", description = "찜한 게시글 목록을 조회합니다.")
@GetMapping("/my-page")
public ApiResponse<ApiResponse.CustomBody<PostCustomPage>> getPostLikes(
Expand Down

0 comments on commit 1b71a79

Please sign in to comment.