Skip to content

Commit

Permalink
Feat/#151 notification check (#202)
Browse files Browse the repository at this point in the history
* [FEAT] Notification 알림 확인 API 구현

* [FEAT] Swagger 구현
  • Loading branch information
tidavid1 authored Mar 4, 2024
1 parent 0ba9c08 commit d476b53
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import io.oeid.mogakgo.common.base.CursorPaginationInfoReq;
import io.oeid.mogakgo.common.base.CursorPaginationResult;
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerNotificationErrorExamples;
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerUserErrorExamples;
import io.oeid.mogakgo.domain.notification.application.dto.res.NotificationCheckedRes;
import io.oeid.mogakgo.domain.notification.presentation.dto.req.FCMTokenApiRequest;
import io.oeid.mogakgo.domain.notification.presentation.dto.res.NotificationPublicApiRes;
import io.oeid.mogakgo.exception.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -51,4 +54,18 @@ ResponseEntity<Void> manageFCMToken(@Parameter(hidden = true) Long userId,
ResponseEntity<CursorPaginationResult<NotificationPublicApiRes>> getByUserId(
@Parameter(hidden = true) Long id,
@Parameter(hidden = true) CursorPaginationInfoReq pageable);

@Operation(summary = "알림 확인", description = "회원의 알림을 확인할 때 사용하는 API")
@ApiResponse(responseCode = "200", description = "알림 확인 성공")
@ApiResponse(responseCode = "404", description = "요청한 유저가 존재하지 않음", content = @Content(
mediaType = APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ErrorResponse.class),
examples = {
@ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND),
@ExampleObject(name = "E060302", value = SwaggerNotificationErrorExamples.NOTIFICATION_NOT_FOUND)
})
)
ResponseEntity<NotificationCheckedRes> markCheckedNotification(
@Parameter(hidden = true) Long userId,
@Parameter(in = ParameterIn.PATH) Long notificationId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.oeid.mogakgo.core.properties.swagger.error;

public class SwaggerNotificationErrorExamples {

public static final String NOTIFICATION_FCM_TOKEN_NOT_FOUND = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":404,\"code\":\"E060301\",\"message\":\"해당 유저의 FCM 토큰이 존재하지 않습니다.\"}";
public static final String NOTIFICATION_NOT_FOUND = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":404,\"code\":\"E060302\",\"message\":\"해당 알림이 존재하지 않습니다.\"}";
private SwaggerNotificationErrorExamples() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq;
import io.oeid.mogakgo.common.base.CursorPaginationResult;
import io.oeid.mogakgo.domain.notification.application.dto.req.NotificationCreateRequest;
import io.oeid.mogakgo.domain.notification.application.dto.res.NotificationCheckedRes;
import io.oeid.mogakgo.domain.notification.application.dto.res.NotificationCreateResponse;
import io.oeid.mogakgo.domain.notification.domain.Notification;
import io.oeid.mogakgo.domain.notification.exception.NotificationException;
import io.oeid.mogakgo.domain.notification.infrastructure.NotificationJpaRepository;
import io.oeid.mogakgo.domain.notification.presentation.dto.res.NotificationPublicApiRes;
import io.oeid.mogakgo.domain.user.application.UserCommonService;
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.exception.code.ErrorCode404;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -37,4 +40,13 @@ public CursorPaginationResult<NotificationPublicApiRes> getNotifications(Long us
User user = userCommonService.getUserById(userId);
return notificationRepository.findByUserIdWithPagination(user.getId(), pageable);
}

@Transactional
public NotificationCheckedRes checkedNotification(Long userId, Long notificationId) {
User user = userCommonService.getUserById(userId);
Notification notification = notificationRepository.findByIdAndReceiver(notificationId, user)
.orElseThrow(() -> new NotificationException(ErrorCode404.NOTIFICATION_NOT_FOUND));
notification.markAsChecked();
return new NotificationCheckedRes(notification.getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.oeid.mogakgo.domain.notification.application.dto.res;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "알림 확인 응답")
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class NotificationCheckedRes {

@Schema(description = "알림 ID", example = "1", implementation = Long.class)
private Long notificationId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ private String validateDetailData(String detailData) {
}
return detailData;
}

public void markAsChecked() {
this.checkedYn = true;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.oeid.mogakgo.domain.notification.infrastructure;

import io.oeid.mogakgo.domain.notification.domain.Notification;
import io.oeid.mogakgo.domain.user.domain.User;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface NotificationJpaRepository extends JpaRepository<Notification, Long>,
NotificationCustomRepository {

Optional<Notification> findByIdAndReceiver(Long id, User receiver);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import io.oeid.mogakgo.common.swagger.template.NotificationSwagger;
import io.oeid.mogakgo.domain.notification.application.FCMNotificationService;
import io.oeid.mogakgo.domain.notification.application.NotificationService;
import io.oeid.mogakgo.domain.notification.application.dto.res.NotificationCheckedRes;
import io.oeid.mogakgo.domain.notification.presentation.dto.req.FCMTokenApiRequest;
import io.oeid.mogakgo.domain.notification.presentation.dto.res.NotificationPublicApiRes;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -38,4 +41,10 @@ public ResponseEntity<CursorPaginationResult<NotificationPublicApiRes>> getByUse
@UserId Long id, @Valid @ModelAttribute CursorPaginationInfoReq pageable) {
return ResponseEntity.ok().body(notificationService.getNotifications(id, pageable));
}

@PatchMapping("/{notificationId}")
public ResponseEntity<NotificationCheckedRes> markCheckedNotification(@UserId Long userId,
@PathVariable Long notificationId) {
return ResponseEntity.ok(notificationService.checkedNotification(userId, notificationId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum ErrorCode404 implements ErrorCode {
PROJECT_NOT_FOUND("E030301", "해당 프로젝트가 존재하지 않습니다."),
PROFILE_CARD_NOT_FOUND("E040301", "해당 프로필 카드가 존재하지 않습니다."),
NOTIFICATION_FCM_TOKEN_NOT_FOUND("E060301", "해당 유저의 FCM 토큰이 존재하지 않습니다."),
NOTIFICATION_NOT_FOUND("E060302", "해당 알림이 존재하지 않습니다."),
PROJECT_JOIN_REQUEST_NOT_FOUND("E050301", "해당 프로젝트 참여 요청이 존재하지 않습니다."),
MATCHING_NOT_FOUND("E090301", "해당 매칭이 존재하지 않습니다."),
CHAT_ROOM_NOT_FOUND("E110301", "해당 채팅방이 존재하지 않습니다."),
Expand Down

0 comments on commit d476b53

Please sign in to comment.