Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 스터디 알림 기능을 구현한다. #593

Draft
wants to merge 8 commits into
base: BE/develop
Choose a base branch
from
3 changes: 3 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ dependencies {
annotationProcessor "javax.persistence:javax.persistence-api"
annotationProcessor "javax.annotation:javax.annotation-api"
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa"

// fcm
implementation 'com.google.firebase:firebase-admin:9.1.1'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.yigongil.backend.config.oauth.GithubProfileResponse;
import com.yigongil.backend.domain.member.Member;
import com.yigongil.backend.domain.member.MemberRepository;
import com.yigongil.backend.request.TokenRequest;
import com.yigongil.backend.request.RefreshTokenRequest;
import com.yigongil.backend.response.TokenResponse;
import java.util.Optional;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -40,7 +40,7 @@ public TokenResponse login(String code) {
return createTokens(id);
}

public TokenResponse refresh(TokenRequest request) {
public TokenResponse refresh(RefreshTokenRequest request) {
String refreshToken = request.refreshToken();

jwtTokenProvider.detectTokenTheft(refreshToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public MustDoService(
public void updateMustDo(Member member, Long roundId, MustDoUpdateRequest request) {
Round round = findRoundById(roundId);
round.updateMustDo(member, request.content());
roundRepository.save(round);
}

private Round findRoundById(Long roundId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.yigongil.backend.application;

import com.yigongil.backend.domain.event.MemberDeleteEvent;
import com.yigongil.backend.domain.event.MemberDeletedEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
Expand All @@ -15,7 +15,7 @@ public StudyEventListener(StudyService studyService) {
}

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void listenMemberDeleteEvent(MemberDeleteEvent event) {
public void listenMemberDeleteEvent(MemberDeletedEvent event) {
studyService.deleteByMasterId(event.memberId());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yigongil.backend.application;

import com.yigongil.backend.domain.certification.Certification;
import com.yigongil.backend.domain.meetingdayoftheweek.MeetingDayOfTheWeek;
import com.yigongil.backend.domain.meetingdayoftheweek.MeetingDayOfTheWeekRepository;
import com.yigongil.backend.domain.member.Member;
import com.yigongil.backend.domain.round.Round;
import com.yigongil.backend.domain.round.RoundRepository;
Expand Down Expand Up @@ -46,18 +48,21 @@ public class StudyService {
private final CertificationService certificationService;
private final FeedService feedService;
private final RoundRepository roundRepository;
private final MeetingDayOfTheWeekRepository meetingDayOfTheWeekRepository;

public StudyService(
StudyRepository studyRepository,
StudyMemberRepository studyMemberRepository,
CertificationService certificationService,
FeedService feedService,
final RoundRepository roundRepository) {
final RoundRepository roundRepository,
MeetingDayOfTheWeekRepository meetingDayOfTheWeekRepository) {
this.studyRepository = studyRepository;
this.studyMemberRepository = studyMemberRepository;
this.certificationService = certificationService;
this.feedService = feedService;
this.roundRepository = roundRepository;
this.meetingDayOfTheWeekRepository = meetingDayOfTheWeekRepository;
}

@Transactional
Expand Down Expand Up @@ -128,6 +133,7 @@ public List<MyStudyResponse> findMyStudies(Member member) {
public void apply(Member member, Long studyId) {
Study study = findStudyById(studyId);
study.apply(member);
studyRepository.save(study);
}

@Transactional
Expand Down Expand Up @@ -162,6 +168,7 @@ public void permitApplicant(Member master, Long studyId, Long memberId) {
Study study = studyMember.getStudy();

study.permit(studyMember.getMember(), master);
studyRepository.save(study);
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -230,9 +237,12 @@ public void proceedRound(LocalDate today) {
@Transactional
public void start(Member member, Long studyId, StudyStartRequest request) {
List<DayOfWeek> meetingDaysOfTheWeek = createDayOfWeek(request.meetingDaysOfTheWeek());

Study study = findStudyById(studyId);
study.start(member, meetingDaysOfTheWeek, LocalDateTime.now());
for (MeetingDayOfTheWeek meetingDayOfTheWeek : study.getMeetingDaysOfTheWeek()) {
meetingDayOfTheWeekRepository.save(meetingDayOfTheWeek);
}
studyRepository.save(study);
}

private List<DayOfWeek> createDayOfWeek(List<String> daysOfTheWeek) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.yigongil.backend.domain;

import com.yigongil.backend.domain.event.DomainEvent;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.domain.AfterDomainEventPublication;
import org.springframework.data.domain.DomainEvents;
import org.springframework.data.domain.AbstractAggregateRoot;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public abstract class BaseEntity {
public abstract class BaseEntity extends AbstractAggregateRoot<BaseEntity> {

@CreatedDate
@Column(nullable = false)
Expand All @@ -25,23 +20,6 @@ public abstract class BaseEntity {
@LastModifiedDate
protected LocalDateTime updatedAt;

@Transient
private Collection<DomainEvent> domainEvents = new ArrayList<>();

@DomainEvents
public Collection<DomainEvent> events() {
return domainEvents;
}

@AfterDomainEventPublication
public void clear() {
domainEvents.clear();
}

protected void register(DomainEvent event) {
domainEvents.add(event);
}

public LocalDateTime getCreatedAt() {
return createdAt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yigongil.backend.domain.certification;

import com.yigongil.backend.domain.BaseEntity;
import com.yigongil.backend.domain.event.CertificationCreatedEvent;
import com.yigongil.backend.domain.member.Member;
import com.yigongil.backend.domain.round.Round;
import com.yigongil.backend.domain.study.Study;
Expand All @@ -11,6 +12,7 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PostPersist;
import lombok.Builder;
import lombok.Getter;

Expand Down Expand Up @@ -59,4 +61,9 @@ public Certification(
this.createdAt = createdAt;
this.round = round;
}

@PostPersist
public void registerCreatedEvent() {
registerEvent(new CertificationCreatedEvent(study.getId(), study.getName(), author.getGithubId()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yigongil.backend.domain.event;

public record CertificationCreatedEvent(
Long studyId,
String studyName,
String authorGithubId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.yigongil.backend.domain.event;

import java.time.LocalDateTime;

public record FeedPostCreatedEvent
(
Long studyId,
String studyName,
String authorGithubId,
String content,
String imageUrl,
LocalDateTime createdAt
Copy link
Member

Choose a reason for hiding this comment

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

이벤트 중에서 이 녀석만 createdAt을 가지고 있는 이유가 무엇인가요??

) implements DomainEvent {

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yigongil.backend.domain.event;

public record MemberDeletedEvent(Long memberId) implements DomainEvent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yigongil.backend.domain.event;

public record MustDoUpdatedEvent(
Long studyId,
String studyName,
String mustDo
) implements DomainEvent{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yigongil.backend.domain.event;

public record StudyAppliedEvent(Long studyMasterId, String studyName, String appliedMemberGithubId) implements DomainEvent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yigongil.backend.domain.event;

public record StudyCreatedEvent(Long studyId, Long masterId) implements DomainEvent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yigongil.backend.domain.event;

public record StudyPermittedEvent(Long permittedMemberId, Long studyId, String studyName) implements DomainEvent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yigongil.backend.domain.event;

public record StudyStartedEvent(Long studyId, String studyName) implements DomainEvent {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yigongil.backend.domain.feedpost;

import com.yigongil.backend.domain.BaseEntity;
import com.yigongil.backend.domain.event.FeedPostCreatedEvent;
import com.yigongil.backend.domain.member.Member;
import com.yigongil.backend.domain.study.Study;
import java.time.LocalDateTime;
Expand All @@ -11,6 +12,7 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PostPersist;
import lombok.Builder;
import lombok.Getter;

Expand Down Expand Up @@ -54,6 +56,18 @@ public FeedPost(
this.createdAt = createdAt;
}

@PostPersist
public void registerCreatedEvent() {
registerEvent(new FeedPostCreatedEvent(
study.getId(),
study.getName(),
author.getGithubId(),
content,
imageUrl,
createdAt
));
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.yigongil.backend.domain.meetingdayoftheweek;

import org.springframework.data.repository.Repository;

public interface MeetingDayOfTheWeekRepository extends Repository<MeetingDayOfTheWeek, Long> {

MeetingDayOfTheWeek save(MeetingDayOfTheWeek meetingDayOfTheWeek);

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.yigongil.backend.domain.member;

import com.yigongil.backend.domain.BaseEntity;
import com.yigongil.backend.domain.event.MemberDeleteEvent;
import com.yigongil.backend.domain.event.MemberDeletedEvent;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Embedded;
Expand Down Expand Up @@ -103,7 +103,7 @@ public String getIntroduction() {

@PreRemove
public void registerDeleteEvent() {
register(new MemberDeleteEvent(id));
registerEvent(new MemberDeletedEvent(id));
}

public void addExperience(int exp) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yigongil.backend.domain.round;

import com.yigongil.backend.domain.BaseEntity;
import com.yigongil.backend.domain.event.MustDoUpdatedEvent;
import com.yigongil.backend.domain.meetingdayoftheweek.MeetingDayOfTheWeek;
import com.yigongil.backend.domain.member.Member;
import com.yigongil.backend.domain.roundofmember.RoundOfMember;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class Round extends BaseEntity {
@JoinColumn(name = "master_id", nullable = false)
private Member master;

@Cascade(CascadeType.PERSIST)
@Cascade({CascadeType.PERSIST, CascadeType.MERGE})
@OnDelete(action = OnDeleteAction.CASCADE)
@OneToMany
@JoinColumn(name = "round_id", nullable = false)
Expand Down Expand Up @@ -106,6 +107,7 @@ public void updateMustDo(Member author, String content) {
validateTodoLength(content);
validateMaster(author);
mustDo = content;
registerEvent(new MustDoUpdatedEvent(study.getId(), study.getName(), content));
}

public void validateMaster(Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface RoundRepository extends Repository<Round, Long> {
Optional<Round> findById(Long id);

List<Round> findAllByStudyIdAndWeekNumber(Long studyId, Integer weekNumber);

Round save(Round round);
}
Loading