-
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 #121 from team-winey/dev
merge to main
- Loading branch information
Showing
23 changed files
with
546 additions
and
143 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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/winey/server/controller/NotiController.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,58 @@ | ||
package org.winey.server.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.winey.server.common.dto.ApiResponse; | ||
import org.winey.server.config.resolver.UserId; | ||
import org.winey.server.controller.response.feed.GetAllFeedResponseDto; | ||
import org.winey.server.controller.response.notification.GetAllNotiResponseDto; | ||
import org.winey.server.exception.Error; | ||
import org.winey.server.exception.Success; | ||
import org.winey.server.service.FeedService; | ||
import org.winey.server.service.NotiService; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/noti") | ||
@Tag(name = "Notification", description = "위니 알림 API Document") | ||
public class NotiController { | ||
private final NotiService notiService; | ||
|
||
@GetMapping("") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "위니 알림 전체 조회 API", description = "위니 알림 전체를 조회합니다.") | ||
public ApiResponse<GetAllNotiResponseDto> getAllNoti(@UserId Long userId) { | ||
GetAllNotiResponseDto res = notiService.getAllNoti(userId); | ||
if (res ==null){ | ||
return ApiResponse.success(Success.NOTIFICATION_EMPTY_SUCCESS); | ||
} | ||
return ApiResponse.success(Success.GET_NOTIFICATIONS_SUCCESS, res); | ||
} | ||
|
||
@PostMapping("") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "위니 안읽은 알림 읽음처리 API", description = "위니 알림 전체를 읽음처리 합니다.") | ||
public ApiResponse checkAllNoti(@UserId Long userId){ | ||
notiService.checkAllNoti(userId); | ||
return ApiResponse.success(Success.CHECK_ALL_NOTIFICATIONS); | ||
} | ||
|
||
@GetMapping("/check") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "새로운 알림 여부 체크 API", description = "미확인 알림이 있는지 확인합니다.") | ||
public ApiResponse checkNewNoti(@UserId Long userId) { | ||
Map<String, Boolean> result = new HashMap<String, Boolean>() { | ||
{ | ||
put("hasNewNotification", notiService.checkNewNoti(userId)); | ||
} | ||
}; | ||
return ApiResponse.success(Success.CHECK_NEW_NOTIFICATION_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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/org/winey/server/controller/response/notification/GetAllNotiResponseDto.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,23 @@ | ||
package org.winey.server.controller.response.notification; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.winey.server.controller.response.PageResponseDto; | ||
import org.winey.server.controller.response.feed.GetAllFeedResponseDto; | ||
import org.winey.server.controller.response.feed.GetFeedResponseDto; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class GetAllNotiResponseDto { | ||
private List<GetNotiResponseDto> getNotiResponseDtoList; | ||
|
||
public static GetAllNotiResponseDto of(List<GetNotiResponseDto> getNotiResponseDtoList) { | ||
return new GetAllNotiResponseDto(getNotiResponseDtoList); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/winey/server/controller/response/notification/GetNotiResponseDto.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,33 @@ | ||
package org.winey.server.controller.response.notification; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.winey.server.controller.response.feed.GetFeedResponseDto; | ||
import org.winey.server.domain.notification.NotiType; | ||
import org.winey.server.domain.notification.Notification; | ||
import org.winey.server.domain.user.User; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class GetNotiResponseDto { | ||
private Long notiId; | ||
// user부분 | ||
private String notiReceiver; //알림 받은 유저 닉네임. | ||
private String notiMessage; | ||
private NotiType notiType; | ||
private Boolean isChecked; //유저가 이 알림을 체크했는지 | ||
private Long LinkId; //좋아요, 댓글일 경우에는 feedid를 넘기고 아니면 안넘어감. | ||
private String timeAgo; | ||
private LocalDateTime createdAt; | ||
|
||
public static GetNotiResponseDto of(Long notiId, String notiReceiver, String notiMessage, NotiType notiType, boolean isChecked, Long linkId, String timeAgo, LocalDateTime createdAt) { | ||
return new GetNotiResponseDto(notiId, notiReceiver, notiMessage, notiType, isChecked, linkId, timeAgo, createdAt); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/org/winey/server/domain/notification/NotiType.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,39 @@ | ||
package org.winey.server.domain.notification; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.validation.constraints.Null; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum NotiType { | ||
//등급 상승 | ||
RANKUPTO2("기사가 되신 걸 축하해요!"), | ||
RANKUPTO3("귀족이 되신 걸 축하해요!"), | ||
RANKUPTO4("황제가 되신 걸 축하해요!"), | ||
|
||
//삭제로 등급 강등 | ||
DELETERANKDOWNTO3("게시글이 삭제되어 등급이 귀족으로 내려갔어요."), | ||
DELETERANKDOWNTO2("게시글이 삭제되어 등급이 기사로 내려갔어요."), | ||
|
||
DELETERANKDOWNTO1("게시글이 삭제되어 등급이 귀족으로 내려갔어요."), | ||
|
||
//목표 달성 실패 | ||
GOALFAILED("이번에는 아쉽지만 힘내서 다음 목표를 세워볼까요?"), | ||
|
||
//좋아요 알림 -> 내가 좋아요 누른건 알림 안주기 | ||
LIKENOTI("님이 회원님의 게시글을 좋아해요."), | ||
|
||
//피드에 댓글 알림 -> 내가 댓글 쓴건 알림 안주기 | ||
COMMENTNOTI("님이 회원님의 게시글에 댓글을 남겼어요."), | ||
|
||
//처음 로그인했을 때 생성하는 알림 | ||
HOWTOLEVELUP("위니의 캐릭터 레벨업 방법을 알아볼까요?"); | ||
|
||
private final String type; | ||
|
||
} | ||
|
60 changes: 60 additions & 0 deletions
60
src/main/java/org/winey/server/domain/notification/Notification.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 org.winey.server.domain.notification; | ||
|
||
import lombok.*; | ||
import org.winey.server.domain.AuditingTimeEntity; | ||
import org.winey.server.domain.user.User; | ||
|
||
import javax.persistence.*; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Notification extends AuditingTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "noti_id") | ||
private Long notiId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "receive_user") | ||
private User notiReceiver; | ||
|
||
private String notiMessage; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private NotiType notiType; | ||
|
||
private boolean isChecked; // 유저가 이 알림을 체크했는지 | ||
|
||
private Long linkId; // 링크 타고 갈 피드 아이디 | ||
|
||
private Long responseId; // 해당 알림을 만드는 반응의 아이디? (commentId or likeId) | ||
|
||
private Long requestUserId; // 알림을 생성한 유저의 아이디 | ||
|
||
@Builder | ||
public Notification(User notiReciver, NotiType notiType, String notiMessage, boolean isChecked) { | ||
this.notiReceiver = notiReciver; | ||
this.notiType = notiType; | ||
this.notiMessage = notiMessage; | ||
this.isChecked = isChecked; | ||
} | ||
|
||
public void updateLinkId(Long linkId) { | ||
this.linkId = linkId; | ||
} | ||
|
||
public void updateResponseId(Long responseId) { | ||
this.responseId = responseId; | ||
} | ||
|
||
public void updateIsChecked() { | ||
this.isChecked = true; | ||
} | ||
|
||
public void updateRequestUserId(Long requestUserId) { | ||
this.requestUserId = requestUserId; | ||
} | ||
|
||
} |
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
13 changes: 6 additions & 7 deletions
13
src/main/java/org/winey/server/infrastructure/CommentRepository.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,26 +1,25 @@ | ||
package org.winey.server.infrastructure; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.Repository; | ||
import org.winey.server.domain.comment.Comment; | ||
import org.winey.server.domain.feed.Feed; | ||
import org.winey.server.domain.feed.FeedLike; | ||
import org.winey.server.domain.user.User; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CommentRepository extends Repository<Comment,Long> { | ||
// CREATE | ||
void save(Comment comment); | ||
|
||
// READ | ||
Long countByFeed(Feed feed); | ||
|
||
Optional<Comment> findByCommentId(Long feedId); | ||
|
||
void save(Comment comment); | ||
List<Comment> findAllByFeedOrderByCreatedAtDesc(Feed feed); | ||
|
||
// DELETE | ||
Long deleteByCommentId(Long commentId); | ||
|
||
List<Comment> findAllByFeedOrderByCreatedAtDesc(Feed feed); | ||
|
||
|
||
} |
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
Oops, something went wrong.