Skip to content

Commit

Permalink
Merge pull request #121 from team-winey/dev
Browse files Browse the repository at this point in the history
merge to main
  • Loading branch information
sss4920 authored Aug 14, 2023
2 parents 11df09a + 6e03a71 commit 4776b36
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 143 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/winey/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableJpaAuditing
@SpringBootApplication
@EnableFeignClients
@EnableScheduling
public class ServerApplication {

public static void main(String[] args) {
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/winey/server/controller/NotiController.java
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class GetCommentResponseDto {
private Long commentId;
private Long authorId;
private String author;
private String content;
private int authorLevel;
private LocalDateTime createdAt;

public static GetCommentResponseDto of(Long commentId,String author, String content, int authorLevel, LocalDateTime createdAt) {
return new GetCommentResponseDto(commentId, author, content, authorLevel, createdAt);
public static GetCommentResponseDto of(Long commentId,Long authorId, String author, String content, int authorLevel, LocalDateTime createdAt) {
return new GetCommentResponseDto(commentId, authorId, author, content, authorLevel, createdAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.winey.server.domain.feed.Feed;
import org.winey.server.domain.user.User;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -25,11 +23,13 @@ public class GetFeedResponseDto {
private Long feedMoney;
private Boolean isLiked;
private Long likes;
private Long comments;
private String timeAgo;
private LocalDateTime createdAt;


public static GetFeedResponseDto of(Long feedId,Long userId, String nickName, int writerLevel,String feedTitle, String feedImage,
Long feedMoney, Boolean isLiked, Long likes, LocalDateTime createdAt){
return new GetFeedResponseDto(feedId,userId,nickName,writerLevel, feedTitle, feedImage, feedMoney, isLiked, likes, createdAt);
public static GetFeedResponseDto of(Long feedId, Long userId, String nickName, int writerLevel, String feedTitle, String feedImage,
Long feedMoney, Boolean isLiked, Long likes, Long comments, String timeAgo, LocalDateTime createdAt) {
return new GetFeedResponseDto(feedId, userId, nickName, writerLevel, feedTitle, feedImage, feedMoney, isLiked, likes, comments, timeAgo, createdAt);
}
}
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);
}

}
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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/winey/server/domain/feed/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Feed extends AuditingTimeEntity {
private List<FeedLike> feedLikes;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, mappedBy = "feed", orphanRemoval = true)
private List<Comment> comment;
private List<Comment> comments;

@Builder
public Feed(User user, String feedTitle, String feedImage, Long feedMoney){
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/org/winey/server/domain/notification/NotiType.java
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;

}

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;
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/winey/server/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class User extends AuditingTimeEntity {
private List<Comment> comments;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, mappedBy = "user", orphanRemoval = true)
private List<FeedLike> feedlikes;
private List<FeedLike> feedLikes;

@Builder
public User(String nickname, String socialId, SocialType socialType) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/winey/server/exception/Success.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ public enum Success {
GET_FEED_LIST_SUCCESS(HttpStatus.OK, "피드 전체 조회 성공"),
GET_USER_SUCCESS(HttpStatus.OK, "유저 조회 성공"),
GET_MYFEED_SUCCESS(HttpStatus.OK, "마이 피드 조회 성공"),
GET_NOTIFICATIONS_SUCCESS(HttpStatus.OK, "알림 리스트 조회 성공"),
CHECK_ALL_NOTIFICATIONS(HttpStatus.OK, "알림 리스트 체크 성공"),

GET_DETAIL_SUCCESS(HttpStatus.OK, "피드 디테일 페이지 조회 성공"),

RE_ISSUE_TOKEN_SUCCESS(HttpStatus.OK, "토큰 재발급 성공"),
UPDATE_NICKNAME_SUCCESS(HttpStatus.OK, "닉네임 변경 성공"),
CHECK_NICKNAME_DUPLICATE_SUCCESS(HttpStatus.OK, "닉네임 중복 확인 성공"),
CHECK_NEW_NOTIFICATION_SUCCESS(HttpStatus.OK, "새 알림 여부 조회 성공"),

/**
* 201 CREATED
*/
Expand All @@ -39,6 +43,7 @@ public enum Success {
*/
DELETE_FEED_SUCCESS(HttpStatus.NO_CONTENT, "피드가 정상적으로 삭제되었습니다."),
DELETE_COMMENT_SUCCESS(HttpStatus.NO_CONTENT, "댓글이 정상적으로 삭제되었습니다."),
NOTIFICATION_EMPTY_SUCCESS(HttpStatus.NOT_FOUND, "알림이 한통도 없어요. 힝~구"),

DELETE_USER_SUCCESS(HttpStatus.NO_CONTENT, "회원 탈퇴가 정상적으로 이루어졌습니다.")
;
Expand Down
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);


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.winey.server.domain.feed.FeedLike;
import org.winey.server.domain.user.User;

import java.util.List;
import java.util.Optional;

public interface FeedLikeRepository extends Repository<FeedLike,Long> {
Expand All @@ -18,5 +19,5 @@ public interface FeedLikeRepository extends Repository<FeedLike,Long> {
// UPDATE

// DELETE
void deleteByFeedAndUser(Feed feed, User user);
List<FeedLike> deleteByFeedAndUser(Feed feed, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface GoalRepository extends Repository<Goal, Long> {
// READ

int countByUserAndIsAttained(User user, boolean isAttained);
@Query("SELECT g FROM Goal g WHERE g.createdAt IN (SELECT MAX(g2.createdAt) FROM Goal g2 WHERE g2.user = g.user)")
List<Goal> findLatestGoalsForEachUser();

@Query("select g from Goal g where g.user = ?1 order by g.createdAt DESC")
List<Goal> findByUserOrderByCreatedAtDesc(User user);
Expand Down
Loading

0 comments on commit 4776b36

Please sign in to comment.