Skip to content

Commit

Permalink
Merge pull request #122 from seniors-project/feature/#121
Browse files Browse the repository at this point in the history
  • Loading branch information
char-yb authored Nov 15, 2023
2 parents 2864c55 + b77ceb6 commit 3599fc7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public DataResponseDto<CustomSlice<NotificationDto>> notificationList(
@ApiResponse(responseCode = "500", description = "서버 에러.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)))
@PatchMapping("/{id}")
public DataResponseDto<Notification> notificationRead(
public DataResponseDto<NotificationDto> notificationRead(
@PathVariable Long id,
@LoginUsers CustomUserDetails userDetails
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class NotificationDto {
* 알림 id
*/
private Long id;

private Long userId;

/**
Expand All @@ -29,24 +30,18 @@ public class NotificationDto {
* 알림이 생성된 날짜
*/
private LocalDateTime createdAt;
/**
* 알림이 수정된 날짜
*/
private LocalDateTime lastModifiedDate;

/**
* 알림 읽음 여부
*/
private boolean isRead;

@Builder
public NotificationDto(Long id, Long userId, String content, String url, LocalDateTime createdAt, LocalDateTime lastModifiedDate, boolean isRead) {
public NotificationDto(Long id, Long userId, String content, String url, LocalDateTime createdAt, boolean isRead) {
this.id = id;
this.userId = userId;
this.content = content;
this.url = url;
this.createdAt = createdAt;
this.lastModifiedDate = lastModifiedDate;
this.isRead = isRead;
}

Expand All @@ -57,7 +52,6 @@ public static NotificationDto of(Notification notification) {
.content(notification.getContent())
.url(notification.getUrl())
.createdAt(notification.getCreatedAt())
.lastModifiedDate(notification.getLastModifiedDate())
.isRead(notification.isRead())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.seniors.domain.notification.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.seniors.common.entity.BaseTimeEntity;
import com.seniors.domain.users.entity.Users;
import jakarta.persistence.*;
Expand All @@ -22,6 +23,7 @@ public class Notification extends BaseTimeEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId")
@JsonBackReference
private Users users;

@Column(columnDefinition = "varchar(50) not null COMMENT '알림 내용'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ public Slice<NotificationDto> findNotificationList(Long userId, Pageable pageabl
.orderBy(notification.id.desc())
.limit(pageable.getPageSize() + 1)
.fetch();
List<NotificationDto> content = results.stream()
List<NotificationDto> list = results.stream()
.map(n -> new NotificationDto(
n.getId(),
n.getUsers().getId(),
n.getContent(),
n.getUrl(),
n.getCreatedAt(),
n.getLastModifiedDate(),
n.isRead()
))
.collect(Collectors.toList());

return checkLastPage(pageable, content);
return checkLastPage(pageable, list);
}

private BooleanExpression userIdEq(Long userId) {
return notification.users.id.ne(userId);
return notification.users.id.eq(userId);
}

// no-offset 방식 처리하는 메서드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public CustomSlice<NotificationDto> findNotificationList(CustomUserDetails userD
}

@Transactional
public Notification readNotification(CustomUserDetails userDetails, Long id) {
public NotificationDto readNotification(CustomUserDetails userDetails, Long id) {

Notification notification = notificationRepository.findById(id)
.orElseThrow(() -> new NotFoundException("존재하지 않는 알림입니다."));
Expand All @@ -150,6 +150,6 @@ public Notification readNotification(CustomUserDetails userDetails, Long id) {
throw new NotAuthorizedException("읽기 권한이 없습니다.");
}
notification.read();
return notification;
return NotificationDto.of(notification);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/seniors/domain/users/entity/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.seniors.domain.notification.entity.Notification;
import com.seniors.domain.post.entity.Post;
import com.seniors.domain.post.entity.PostLike;
import com.seniors.domain.resume.entity.Resume;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.BatchSize;
Expand Down Expand Up @@ -77,6 +76,7 @@ public class Users extends BaseTimeEntity {
@OneToMany(mappedBy = "users", cascade = CascadeType.PERSIST)
private List<PostLike> postLikes = new ArrayList<>();

@JsonManagedReference
@OneToMany(mappedBy = "users", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
private List<Notification> notifications = new ArrayList<>();

Expand Down

0 comments on commit 3599fc7

Please sign in to comment.