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 @@ -2,9 +2,13 @@

import com.sillim.recordit.calendar.domain.Calendar;

public record CalendarResponse(Long id, String title, String colorHex) {
public record CalendarResponse(Long id, String title, String colorHex, Long categoryId) {

public static CalendarResponse from(Calendar calendar) {
return new CalendarResponse(calendar.getId(), calendar.getTitle(), calendar.getColorHex());
return new CalendarResponse(
calendar.getId(),
calendar.getTitle(),
calendar.getColorHex(),
calendar.getCategory().getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class FeedCommandService {
public Long addFeed(FeedAddRequest request, List<MultipartFile> images, Long memberId) {
Long feedId = feedRepository.save(request.toFeed(memberId)).getId();

if (images == null || images.isEmpty()) {
return feedId;
}
messagePublisher.send(
new Message<>(
MessageType.IMAGES.name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.sillim.recordit.feed.repository.FeedRepository;
import com.sillim.recordit.global.exception.ErrorCode;
import com.sillim.recordit.global.exception.common.RecordNotFoundException;
import com.sillim.recordit.member.service.MemberQueryService;
import com.sillim.recordit.pushalarm.dto.PushMessage;
import com.sillim.recordit.pushalarm.service.AlarmService;
import jakarta.persistence.OptimisticLockException;
import lombok.RequiredArgsConstructor;
import org.hibernate.StaleObjectStateException;
Expand All @@ -22,14 +25,16 @@ public class FeedLikeService {

private final FeedLikeRepository feedLikeRepository;
private final FeedRepository feedRepository;
private final AlarmService alarmService;
private final MemberQueryService memberQueryService;

@Retryable(
retryFor = {
OptimisticLockException.class,
ObjectOptimisticLockingFailureException.class,
StaleObjectStateException.class
},
maxAttempts = 15,
maxAttempts = 20,
backoff = @Backoff(delay = 30))
public void feedLike(Long feedId, Long memberId) {
Feed feed =
Expand All @@ -38,6 +43,16 @@ public void feedLike(Long feedId, Long memberId) {
.orElseThrow(() -> new RecordNotFoundException(ErrorCode.FEED_NOT_FOUND));
feed.like();
feedLikeRepository.save(new FeedLike(feed, memberId));

if (!feed.isOwner(memberId)) {
alarmService.pushAlarm(
memberId,
feed.getMemberId(),
PushMessage.fromFeedLike(
feed.getId(),
memberQueryService.findByMemberId(memberId).getPersonalId(),
feed.getTitle()));
}
}

@Retryable(
Expand All @@ -46,7 +61,7 @@ public void feedLike(Long feedId, Long memberId) {
ObjectOptimisticLockingFailureException.class,
StaleObjectStateException.class
},
maxAttempts = 15,
maxAttempts = 20,
backoff = @Backoff(delay = 30))
public void feedUnlike(Long feedId, Long memberId) {
feedRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

import com.sillim.recordit.goal.domain.MonthlyGoal;

public record MonthlyGoalListResponse(
Long id,
String title,
Long categoryId,
String colorHex,
Boolean achieved,
Long calendarId) {
public record MonthlyGoalListResponse(Long id, String title, String colorHex, Boolean achieved) {

public static MonthlyGoalListResponse from(final MonthlyGoal monthlyGoal) {

return new MonthlyGoalListResponse(
monthlyGoal.getId(),
monthlyGoal.getTitle(),
monthlyGoal.getCategory().getId(),
monthlyGoal.getColorHex(),
monthlyGoal.isAchieved(),
monthlyGoal.getCalendar().getId());
monthlyGoal.isAchieved());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static WeeklyGoalDetailsResponse from(final WeeklyGoal weeklyGoal) {
.week(weeklyGoal.getWeek())
.startDate(weeklyGoal.getStartDate())
.endDate(weeklyGoal.getEndDate())
.calendarId(weeklyGoal.getCalendar().getId())
.categoryId(weeklyGoal.getCategory().getId())
.colorHex(weeklyGoal.getColorHex())
.build();
Expand All @@ -38,6 +39,7 @@ public static WeeklyGoalDetailsResponse from(final WeeklyGoal weeklyGoal) {
.week(weeklyGoal.getWeek())
.startDate(weeklyGoal.getStartDate())
.endDate(weeklyGoal.getEndDate())
.calendarId(weeklyGoal.getCalendar().getId())
.categoryId(weeklyGoal.getCategory().getId())
.colorHex(weeklyGoal.getColorHex())
.relatedMonthlyGoal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
public record WeeklyGoalResponse(
Long id,
String title,
Long categoryId,
Integer week,
String colorHex,
Boolean achieved,
Long calendarId,
RelatedMonthlyGoalResponse relatedMonthlyGoal) {

public static WeeklyGoalResponse from(final WeeklyGoal weeklyGoal) {
Expand All @@ -19,19 +18,17 @@ public static WeeklyGoalResponse from(final WeeklyGoal weeklyGoal) {
return WeeklyGoalResponse.builder()
.id(weeklyGoal.getId())
.title(weeklyGoal.getTitle())
.categoryId(weeklyGoal.getCategory().getId())
.week(weeklyGoal.getWeek())
.colorHex(weeklyGoal.getColorHex())
.achieved(weeklyGoal.isAchieved())
.calendarId(weeklyGoal.getCalendar().getId())
.build();
}
return WeeklyGoalResponse.builder()
.id(weeklyGoal.getId())
.title(weeklyGoal.getTitle())
.categoryId(weeklyGoal.getCategory().getId())
.week(weeklyGoal.getWeek())
.colorHex(weeklyGoal.getColorHex())
.achieved(weeklyGoal.isAchieved())
.calendarId(weeklyGoal.getCalendar().getId())
.relatedMonthlyGoal(
RelatedMonthlyGoalResponse.from(weeklyGoal.getRelatedMonthlyGoal().get()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface CustomWeeklyGoalRepository {

List<WeeklyGoal> findWeeklyGoalInMonth(Integer year, Integer month, Long calendarId);

@Query("select wg from WeeklyGoal wg left join fetch wg.calendar where wg.id = :id")
@Query(
"select wg from WeeklyGoal wg left join fetch wg.calendar left join fetch wg.category left join fetch wg.relatedMonthlyGoal where wg.id = :id")
Optional<WeeklyGoal> findWeeklyGoalById(@Param("id") Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import com.sillim.recordit.invite.dto.response.InviteLinkResponse;
import com.sillim.recordit.invite.service.InviteService;
import com.sillim.recordit.member.domain.Member;
import com.sillim.recordit.member.dto.response.MemberListResponse;
import com.sillim.recordit.member.service.MemberQueryService;
import java.io.IOException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -37,6 +39,17 @@ public ResponseEntity<InviteInfoResponse> getInviteInfo(@PathVariable String inv
calendar.getId(), calendar.getTitle(), member.getId(), member.getName()));
}

@GetMapping("/followings")
public ResponseEntity<List<MemberListResponse>> myFollowingList(
@RequestParam Long calendarId, @CurrentMember Member member) {
return ResponseEntity.ok(
inviteService
.searchFollowingsNotInvited(calendarId, member.getPersonalId())
.stream()
.map(MemberListResponse::of)
.toList());
}

@PostMapping("/members/{inviteMemberId}")
public ResponseEntity<Void> inviteMember(
@PathVariable Long inviteMemberId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sillim.recordit.invite.service;

import com.sillim.recordit.calendar.domain.Calendar;
import com.sillim.recordit.calendar.dto.response.CalendarMemberResponse;
import com.sillim.recordit.calendar.service.CalendarMemberService;
import com.sillim.recordit.calendar.service.CalendarQueryService;
import com.sillim.recordit.global.exception.ErrorCode;
Expand All @@ -12,10 +13,12 @@
import com.sillim.recordit.invite.repository.InviteLinkRepository;
import com.sillim.recordit.invite.repository.InviteLogRepository;
import com.sillim.recordit.member.domain.Member;
import com.sillim.recordit.member.service.MemberQueryService;
import com.sillim.recordit.pushalarm.dto.PushMessage;
import com.sillim.recordit.pushalarm.service.AlarmService;
import java.time.LocalDateTime;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand All @@ -32,6 +35,7 @@ public class InviteService {
private final InviteLogRepository inviteLogRepository;
private final AlarmService alarmService;
private final CalendarMemberService calendarMemberService;
private final MemberQueryService memberQueryService;

public String getOrGenerateInviteLink(Long calendarId) {
Optional<InviteLink> inviteLink =
Expand Down Expand Up @@ -74,6 +78,23 @@ public InviteLink searchInviteInfo(String inviteCode) {
new String(Base64.getUrlDecoder().decode(inviteCode)));
}

@Transactional(readOnly = true)
public List<Member> searchFollowingsNotInvited(Long calendarId, String personalId) {
List<CalendarMemberResponse> calendarMembers =
calendarMemberService.searchCalendarMembers(calendarId);
return memberQueryService.searchFollowings(personalId).stream()
.filter(
follow -> {
for (var calendarMember : calendarMembers) {
if (calendarMember.memberId().equals(follow.getId())) {
return false;
}
}
return true;
})
.toList();
}

public void inviteMember(Long calendarId, Long invitedMemberId, Member inviter) {
Calendar calendar = calendarQueryService.searchByCalendarId(calendarId);
calendar.validateAuthenticatedMember(inviter.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ public ResponseEntity<List<FollowRecommendResponse>> recommendMemberList(
return ResponseEntity.ok(body);
}

@GetMapping("/me/followings")
public ResponseEntity<List<MemberListResponse>> myFollowingList(@CurrentMember Member member) {
return ResponseEntity.ok(
memberQueryService.searchFollowings(member.getPersonalId()).stream()
.map(MemberListResponse::of)
.toList());
}

@PostMapping("/{memberId}/follow")
public ResponseEntity<Void> follow(@PathVariable Long memberId, @CurrentMember Member member)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void unfollow(Long followerId, Long followedId) {
Member followed = memberQueryService.findByMemberId(followedId);

follower.unfollow(followed);
memberRepository.save(follower);
memberRepository.save(followed);
memberRepository.save(follower);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public enum AlarmType {
SCHEDULE,
INVITE,
FOLLOWING,
FEED_LIKE,
}
10 changes: 10 additions & 0 deletions src/main/java/com/sillim/recordit/pushalarm/dto/PushMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ public static PushMessage fromAlarmLog(AlarmLog alarmLog) {
alarmLog.getTitle(),
alarmLog.getBody());
}

public static PushMessage fromFeedLike(
Long feedLikeId, String likerPersonalId, String feedTitle) {
return new PushMessage(
null,
AlarmType.FEED_LIKE,
feedLikeId,
likerPersonalId + "님이 " + feedTitle + " 피드에 좋아요를 눌렀습니다.",
"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.sillim.recordit.feed.dto.request.FeedAddRequest;
import com.sillim.recordit.feed.fixture.FeedFixture;
import com.sillim.recordit.feed.repository.FeedRepository;
import com.sillim.recordit.member.domain.Member;
import com.sillim.recordit.member.service.MemberQueryService;
import com.sillim.recordit.rabbitmq.service.MessagePublisher;
import java.io.IOException;
Expand All @@ -37,7 +36,6 @@ class FeedCommandServiceTest {
@Test
@DisplayName("피드를 추가할 수 있다.")
void addFeed() throws IOException {
Member member = mock(Member.class);
Feed feed = mock(Feed.class);
MockMultipartFile multipartFile =
new MockMultipartFile(
Expand All @@ -54,6 +52,19 @@ void addFeed() throws IOException {
assertThat(feedId).isEqualTo(1L);
}

@Test
@DisplayName("이미지 없이 피드를 추가할 수 있다.")
void addFeedWithoutImage() throws IOException {
Feed feed = mock(Feed.class);
given(feed.getId()).willReturn(1L);
given(feedRepository.save(any(Feed.class))).willReturn(feed);

FeedAddRequest feedAddRequest = new FeedAddRequest("title", "content");
Long feedId = feedCommandService.addFeed(feedAddRequest, null, 1L);

assertThat(feedId).isEqualTo(1L);
}

@Test
@DisplayName("피드를 지울 수 있다.")
void removeFeed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sillim.recordit.member.domain.Member;
import com.sillim.recordit.member.fixture.MemberFixture;
import com.sillim.recordit.member.service.MemberQueryService;
import com.sillim.recordit.pushalarm.service.AlarmService;
import java.util.Optional;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -28,6 +29,7 @@ class FeedLikeServiceTest {
@Mock FeedLikeRepository feedLikeRepository;
@Mock FeedRepository feedRepository;
@Mock MemberQueryService memberQueryService;
@Mock AlarmService alarmService;
@InjectMocks FeedLikeService feedLikeService;

@Test
Expand All @@ -37,7 +39,9 @@ void feedLike() {
long memberId = 1L;
Member member = MemberFixture.DEFAULT.getMember();
Feed feed = spy(FeedFixture.DEFAULT.getFeed(memberId));
FeedLike feedLike = mock(FeedLike.class);
given(feedRepository.findById(eq(feedId))).willReturn(Optional.of(feed));
given(feedLikeRepository.save(any())).willReturn(feedLike);

feedLikeService.feedLike(feedId, memberId);

Expand Down
Loading
Loading