Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class Answer extends BaseTimeEntity {
private String content;

@ManyToOne(fetch = LAZY)
@JsonBackReference
@JsonBackReference(value="question-answer")
@JoinColumn(name = "QUESTION_ID")
Question question;

@ManyToOne(fetch = LAZY)
@JsonBackReference
@JsonBackReference(value="member-answer")
@JoinColumn(name = "MEMBER_ID")
Member member;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.example.interviewPrep.quiz.domain.BaseTimeEntity;
import com.example.interviewPrep.quiz.member.domain.Member;
import com.example.interviewPrep.quiz.notification.domain.Notification;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -31,6 +33,11 @@ public class AnswerComment extends BaseTimeEntity {
@JoinColumn(name = "MEMBER_ID")
Member member;

// Notification 엔티티와 @OneToMany 참조 관계를 설정하였습니다
// 연관관계의 주인을 Notification.comment로 설정하였습니다
@OneToMany(mappedBy = "comment")
List<Notification> notifications;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "ANSWER_WRITER_ID")
Member answerWriter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.interviewPrep.quiz.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
Expand All @@ -15,8 +16,10 @@
public abstract class BaseTimeEntity {

@CreatedDate
@JsonIgnore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JsonIgnore 는 왜 추가가 됐을까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저 부분 때문에 Redis에서 직렬화, 역직렬화 할 때 에러가 발생하더라고요
그래서 추가했습니다!

private LocalDateTime createdDate;

@LastModifiedDate
@JsonIgnore
private LocalDateTime modifiedDate;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.interviewPrep.quiz.emitter.repository;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand All @@ -10,59 +11,18 @@
public class EmitterRepository {

public final Map<String, SseEmitter> emitters = new ConcurrentHashMap<>();
private final Map<String, Object> eventCache = new ConcurrentHashMap<>();

public SseEmitter save(String id, SseEmitter sseEmitter) {
emitters.put(id, sseEmitter);
return sseEmitter;
}

public void saveEventCache(String id, Object event) {
eventCache.put(id, event);
public Optional<SseEmitter> findById(String id) {
Optional<SseEmitter> emitter = Optional.ofNullable(emitters.get(id));
return emitter;
}

public void showAll(){

for(String key: emitters.keySet()){
System.out.println("key, value는?" + key + " " + emitters.get(key));
}

}

public Map<String, SseEmitter> findAllById(String id) {

return emitters.entrySet().stream()
.filter(entry -> entry.getKey().startsWith(id))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

public Map<String, Object> findAllEventCacheStartWithId(String id) {
return eventCache.entrySet().stream()
.filter(entry -> entry.getKey().startsWith(id))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

public void deleteAllById(String id) {
emitters.forEach(
(key, emitter) -> {
if (key.startsWith(id)) {
emitters.remove(key);
}
}
);
}

public void deleteById(String id) {
emitters.remove(id);
}

public void deleteAllEventCacheStartWithId(String id) {
eventCache.forEach(
(key, data) -> {
if (key.startsWith(id)) {
eventCache.remove(key);
}
}
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.interviewPrep.quiz.member.domain;

import com.example.interviewPrep.quiz.answer.domain.Answer;
import com.example.interviewPrep.quiz.notification.domain.Notification;
import com.example.interviewPrep.quiz.domain.BaseTimeEntity;
import com.example.interviewPrep.quiz.member.dto.Role;
import com.example.interviewPrep.quiz.notification.domain.Notification;
import com.fasterxml.jackson.annotation.*;
import lombok.*;

Expand All @@ -19,6 +21,7 @@
@Table(indexes = @Index(name= "i_member", columnList = "email"))
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
public class Member extends BaseTimeEntity {

public Member(String email, String password, String nickName){
this.email = email;
this.password = password;
Expand All @@ -39,9 +42,6 @@ public Member(String email, String password, String nickName){

private String nickName;

@OneToMany(mappedBy = "member")
@JsonManagedReference
private List<Answer> answers = new ArrayList<>();
private String name;
@Column
private String picture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ public void logout(String token){
}

redisDao.setValues(accessToken, "logout", Duration.ofMillis(expiration));
emitterRepository.showAll();
emitterRepository.deleteAllById(memberId);
emitterRepository.deleteAllEventCacheStartWithId(memberId);
emitterRepository.showAll();
emitterRepository.deleteById(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public class MemberService {
public Member createMember(SignUpRequestDTO memberDTO) throws Exception {

AES256 aes256 = new AES256();
String code = memberDTO.getCode();
String email = redisDao.getValues(aes256.decrypt(code));
// String code = memberDTO.getCode();
// String email = redisDao.getValues(aes256.decrypt(code));
String email = memberDTO.getEmail();

String password = SHA256Util.encryptSHA256(memberDTO.getPassword());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public NotificationController(NotificationService notificationService) {
* @title 로그인 한 유저 sse 연결
*/
@GetMapping(value = "/subscribe", produces = "text/event-stream")
public SseEmitter subscribe(@RequestParam(value = "lastEventId", required = false, defaultValue = "") String lastEventId) {
return notificationService.subscribe(lastEventId);
public SseEmitter subscribe() {
return notificationService.subscribe();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@
import com.example.interviewPrep.quiz.answer.domain.AnswerComment;

import com.example.interviewPrep.quiz.member.domain.Member;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.*;


@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Getter
public class Notification extends BaseTimeEntity {

// Notification의 ID를 나타낸다
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="NOTIFICATION_ID")
private Long id;

// Notification을 받아야 하는 MEMBER_ID를 나타낸다
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(name = "fk_notification_to_receiver"))
@JoinColumn(name = "MEMBER_ID")
@JsonBackReference(value="receiver-notification")
private Member receiver;

private String receiver_member_id;

// AnswerComment 엔티티와
// @ManyToOne 연관관계를 설정하였습니다
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(name = "fk_notification_to_review"))
private AnswerComment comment;

private String content;
Expand All @@ -34,15 +38,19 @@ public class Notification extends BaseTimeEntity {

private boolean isRead;

@Builder
public Notification(Member receiver, AnswerComment comment, String content, String url, boolean isRead) {
public Notification(){
}
public Notification(Member receiver, AnswerComment comment, String content, boolean isRead) {
this.receiver = receiver;
this.comment = comment;
this.content = content;
this.url = url;
this.isRead = isRead;
}

public void createReceiverMemberId(String receiver_member_id){
this.receiver_member_id = receiver_member_id;
}

public void read() {
this.isRead = true;
}
Expand Down
Loading