forked from Team-TenTen/LinkHub-BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Team-TenTen#150 from Team-TenTen/Feature/get-notif…
…ications Feature/get notifications - 알림 조회 기능 구현
- Loading branch information
Showing
18 changed files
with
464 additions
and
4 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/tenten/linkhub/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,60 @@ | ||
package com.tenten.linkhub.domain.notification.controller; | ||
|
||
import com.tenten.linkhub.domain.auth.MemberDetails; | ||
import com.tenten.linkhub.domain.notification.controller.dto.SpaceInviteNotificationGetApiRequest; | ||
import com.tenten.linkhub.domain.notification.controller.dto.SpaceInviteNotificationGetApiResponses; | ||
import com.tenten.linkhub.domain.notification.controller.mapper.NotificationApiMapper; | ||
import com.tenten.linkhub.domain.notification.service.NotificationService; | ||
import com.tenten.linkhub.domain.notification.service.dto.SpaceInviteNotificationGetRequest; | ||
import com.tenten.linkhub.domain.notification.service.dto.SpaceInviteNotificationGetResponses; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Notification", description = "notification 템플릿 API Document") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/notifications") | ||
public class NotificationController { | ||
private final NotificationService notificationService; | ||
private final NotificationApiMapper apiMapper; | ||
|
||
/** | ||
* 스페이스 초대 알림 조회 API | ||
*/ | ||
@Operation( | ||
summary = "스페이스 초대 알림 조회 API ", description = "[JWT 필요] - pageNumber, pageSize를 받아 스페이스 초대 알림 내역을 조회합니다. ", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "초대 알림 조회가 성공적으로 완료되었습니다.") | ||
}) | ||
@GetMapping(value = "/invitations") | ||
public ResponseEntity<SpaceInviteNotificationGetApiResponses> getInviteNotifications( | ||
@ModelAttribute SpaceInviteNotificationGetApiRequest request, | ||
@AuthenticationPrincipal MemberDetails memberDetails | ||
) { | ||
PageRequest pageRequest = PageRequest.of( | ||
request.pageNumber(), | ||
request.pageSize() | ||
); | ||
|
||
SpaceInviteNotificationGetRequest serviceRequest = apiMapper.toSpaceInvitationGetRequest( | ||
pageRequest, | ||
memberDetails.memberId() | ||
); | ||
|
||
SpaceInviteNotificationGetResponses responses = notificationService.getSpaceInvitations(serviceRequest); | ||
SpaceInviteNotificationGetApiResponses apiResponses = SpaceInviteNotificationGetApiResponses.from(responses); | ||
|
||
return ResponseEntity | ||
.ok() | ||
.body(apiResponses); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...nten/linkhub/domain/notification/controller/dto/SpaceInviteNotificationGetApiRequest.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,12 @@ | ||
package com.tenten.linkhub.domain.notification.controller.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record SpaceInviteNotificationGetApiRequest( | ||
@Schema(title = "페이지 번호", example = "1") | ||
Integer pageNumber, | ||
|
||
@Schema(title = "페이지 크기", example = "10") | ||
Integer pageSize | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
...ten/linkhub/domain/notification/controller/dto/SpaceInviteNotificationGetApiResponse.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,14 @@ | ||
package com.tenten.linkhub.domain.notification.controller.dto; | ||
|
||
import com.tenten.linkhub.domain.notification.model.NotificationType; | ||
|
||
public record SpaceInviteNotificationGetApiResponse( | ||
Long notificationId, | ||
Long invitingMemberId, | ||
Long spaceId, | ||
String invitingMemberName, | ||
String spaceName, | ||
NotificationType notificationType, | ||
boolean isAccepted | ||
) { | ||
} |
35 changes: 35 additions & 0 deletions
35
...en/linkhub/domain/notification/controller/dto/SpaceInviteNotificationGetApiResponses.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,35 @@ | ||
package com.tenten.linkhub.domain.notification.controller.dto; | ||
|
||
import com.tenten.linkhub.domain.notification.service.dto.SpaceInviteNotificationGetResponses; | ||
import com.tenten.linkhub.global.util.PageMetaData; | ||
import org.springframework.data.domain.Slice; | ||
|
||
import java.util.List; | ||
|
||
public record SpaceInviteNotificationGetApiResponses( | ||
List<SpaceInviteNotificationGetApiResponse> responses, | ||
PageMetaData pageMetaData | ||
) { | ||
public static SpaceInviteNotificationGetApiResponses from(SpaceInviteNotificationGetResponses responses) { | ||
Slice<SpaceInviteNotificationGetApiResponse> invitationResponses = responses.responses() | ||
.map(i -> new SpaceInviteNotificationGetApiResponse( | ||
i.notificationId(), | ||
i.invitingMemberId(), | ||
i.spaceId(), | ||
i.invitingMemberName(), | ||
i.spaceName(), | ||
i.notificationType(), | ||
i.isAccepted() | ||
)); | ||
|
||
PageMetaData pageMetaData = new PageMetaData( | ||
invitationResponses.hasNext(), | ||
invitationResponses.getSize(), | ||
invitationResponses.getNumber()); | ||
|
||
return new SpaceInviteNotificationGetApiResponses( | ||
invitationResponses.getContent(), | ||
pageMetaData | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../java/com/tenten/linkhub/domain/notification/controller/mapper/NotificationApiMapper.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,13 @@ | ||
package com.tenten.linkhub.domain.notification.controller.mapper; | ||
|
||
import com.tenten.linkhub.domain.notification.service.dto.SpaceInviteNotificationGetRequest; | ||
import org.mapstruct.InjectionStrategy; | ||
import org.mapstruct.Mapper; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
@Mapper(componentModel = "spring", | ||
injectionStrategy = InjectionStrategy.CONSTRUCTOR | ||
) | ||
public interface NotificationApiMapper { | ||
SpaceInviteNotificationGetRequest toSpaceInvitationGetRequest(Pageable pageable, Long memberId); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/tenten/linkhub/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,9 +1,14 @@ | ||
package com.tenten.linkhub.domain.notification.repository; | ||
|
||
import com.tenten.linkhub.domain.notification.model.Notification; | ||
import com.tenten.linkhub.domain.notification.repository.dto.NotificationGetQueryCondition; | ||
import com.tenten.linkhub.domain.notification.repository.dto.SpaceInvitationNotificationGetDto; | ||
import org.springframework.data.domain.Slice; | ||
|
||
public interface NotificationRepository { | ||
Notification getById(Long notificationId); | ||
|
||
Slice<SpaceInvitationNotificationGetDto> getInviteNotifications(NotificationGetQueryCondition condition); | ||
|
||
Notification save(Notification notification); | ||
} |
9 changes: 9 additions & 0 deletions
9
.../com/tenten/linkhub/domain/notification/repository/dto/NotificationGetQueryCondition.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,9 @@ | ||
package com.tenten.linkhub.domain.notification.repository.dto; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
|
||
public record NotificationGetQueryCondition( | ||
Long memberId, | ||
Pageable pageable | ||
) { | ||
} |
31 changes: 31 additions & 0 deletions
31
.../tenten/linkhub/domain/notification/repository/dto/SpaceInvitationNotificationGetDto.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,31 @@ | ||
package com.tenten.linkhub.domain.notification.repository.dto; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import com.tenten.linkhub.domain.notification.model.NotificationType; | ||
|
||
public record SpaceInvitationNotificationGetDto( | ||
Long notificationId, | ||
Long invitingMemberId, | ||
Long spaceId, | ||
String invitingMemberName, | ||
String spaceName, | ||
NotificationType notificationType, | ||
boolean isAccepted | ||
) { | ||
@QueryProjection | ||
public SpaceInvitationNotificationGetDto(Long notificationId, | ||
Long invitingMemberId, | ||
Long spaceId, | ||
String invitingMemberName, | ||
String spaceName, | ||
NotificationType notificationType, | ||
boolean isAccepted) { | ||
this.notificationId = notificationId; | ||
this.invitingMemberId = invitingMemberId; | ||
this.spaceId = spaceId; | ||
this.invitingMemberName = invitingMemberName; | ||
this.spaceName = spaceName; | ||
this.notificationType = notificationType; | ||
this.isAccepted = isAccepted; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...enten/linkhub/domain/notification/repository/querydsl/NotificationQueryDslRepository.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,65 @@ | ||
package com.tenten.linkhub.domain.notification.repository.querydsl; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.tenten.linkhub.domain.notification.repository.dto.NotificationGetQueryCondition; | ||
import com.tenten.linkhub.domain.notification.repository.dto.QSpaceInvitationNotificationGetDto; | ||
import com.tenten.linkhub.domain.notification.repository.dto.SpaceInvitationNotificationGetDto; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.domain.SliceImpl; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.tenten.linkhub.domain.member.model.QMember.member; | ||
import static com.tenten.linkhub.domain.notification.model.QNotification.notification; | ||
import static com.tenten.linkhub.domain.space.model.space.QInvitation.invitation; | ||
import static com.tenten.linkhub.domain.space.model.space.QSpace.space; | ||
|
||
@Repository | ||
public class NotificationQueryDslRepository { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public NotificationQueryDslRepository(JPAQueryFactory jpaQueryFactory) { | ||
this.jpaQueryFactory = jpaQueryFactory; | ||
|
||
} | ||
|
||
public Slice<SpaceInvitationNotificationGetDto> getSpaceInvitationNotifications(NotificationGetQueryCondition condition) { | ||
List<SpaceInvitationNotificationGetDto> notificationGetDtos = jpaQueryFactory | ||
.select(new QSpaceInvitationNotificationGetDto( | ||
notification.id, | ||
notification.senderId, | ||
invitation.space.id, | ||
member.nickname, | ||
space.spaceName, | ||
notification.notificationType, | ||
invitation.isAccepted | ||
)) | ||
.from(notification) | ||
.join(invitation).on(invitation.notificationId.eq(notification.id)) | ||
.join(invitation.space, space) | ||
.join(member).on(checkMemberJoinCondition(condition.memberId())) | ||
.offset(condition.pageable().getOffset()) | ||
.limit(condition.pageable().getPageSize() + 1) | ||
.fetch(); | ||
|
||
boolean hasNext = false; | ||
|
||
if (notificationGetDtos.size() > condition.pageable().getPageSize()) { | ||
notificationGetDtos.remove(condition.pageable().getPageSize()); | ||
hasNext = true; | ||
} | ||
|
||
return new SliceImpl<>(notificationGetDtos, condition.pageable(), hasNext); | ||
|
||
} | ||
|
||
BooleanExpression checkMemberJoinCondition(Long memberId) { | ||
BooleanExpression joinMemberCondition = notification.senderId.eq(member.id); | ||
BooleanExpression isSameMemberId = notification.recipientId.eq(memberId); | ||
|
||
return joinMemberCondition.and(isSameMemberId); | ||
} | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
...com/tenten/linkhub/domain/notification/service/dto/SpaceInviteNotificationGetRequest.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,9 @@ | ||
package com.tenten.linkhub.domain.notification.service.dto; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
|
||
public record SpaceInviteNotificationGetRequest( | ||
Pageable pageable, | ||
Long memberId | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
...om/tenten/linkhub/domain/notification/service/dto/SpaceInviteNotificationGetResponse.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,14 @@ | ||
package com.tenten.linkhub.domain.notification.service.dto; | ||
|
||
import com.tenten.linkhub.domain.notification.model.NotificationType; | ||
|
||
public record SpaceInviteNotificationGetResponse( | ||
Long notificationId, | ||
Long invitingMemberId, | ||
Long spaceId, | ||
String invitingMemberName, | ||
String spaceName, | ||
NotificationType notificationType, | ||
boolean isAccepted | ||
) { | ||
} |
24 changes: 24 additions & 0 deletions
24
...m/tenten/linkhub/domain/notification/service/dto/SpaceInviteNotificationGetResponses.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,24 @@ | ||
package com.tenten.linkhub.domain.notification.service.dto; | ||
|
||
import com.tenten.linkhub.domain.notification.repository.dto.SpaceInvitationNotificationGetDto; | ||
import org.springframework.data.domain.Slice; | ||
|
||
public record SpaceInviteNotificationGetResponses( | ||
Slice<SpaceInviteNotificationGetResponse> responses | ||
) { | ||
public static SpaceInviteNotificationGetResponses from(Slice<SpaceInvitationNotificationGetDto> notificationGetDtos) { | ||
Slice<SpaceInviteNotificationGetResponse> responseList = notificationGetDtos.map( | ||
n -> new SpaceInviteNotificationGetResponse( | ||
n.notificationId(), | ||
n.invitingMemberId(), | ||
n.spaceId(), | ||
n.invitingMemberName(), | ||
n.spaceName(), | ||
n.notificationType(), | ||
n.isAccepted() | ||
) | ||
); | ||
|
||
return new SpaceInviteNotificationGetResponses(responseList); | ||
} | ||
} |
Oops, something went wrong.