Skip to content
Open
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
@@ -1,7 +1,11 @@
package com.likelion.monday.domain.mygarden.controller;

import com.likelion.monday.domain.account.auth.LoginAccountId;
import com.likelion.monday.domain.mygarden.dto.LikedStoryResDto;
import com.likelion.monday.domain.mygarden.dto.MyActivitySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.MyStorySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.ReceivedLikeResDto;
import com.likelion.monday.domain.mygarden.dto.SentStoryResDto;
import com.likelion.monday.domain.mygarden.service.MyGardenService;
import com.likelion.monday.domain.story.entity.StoryStatus;
import com.likelion.monday.global.response.ApiResponse;
Expand Down Expand Up @@ -30,4 +34,28 @@ public ApiResponse<List<MyStorySummaryResDto>> getMyStories(
@RequestParam(required = false) StoryStatus status) {
return ApiResponse.success(myGardenService.getMyStories(accountId, status));
}

@Override
@GetMapping("/summary")
public ApiResponse<MyActivitySummaryResDto> getActivitySummary(@LoginAccountId Long accountId) {
return ApiResponse.success(myGardenService.getActivitySummary(accountId));
}

@Override
@GetMapping("/sent-stories")
public ApiResponse<List<SentStoryResDto>> getSentStories(@LoginAccountId Long accountId) {
return ApiResponse.success(myGardenService.getSentStories(accountId));
}

@Override
@GetMapping("/received-likes")
public ApiResponse<List<ReceivedLikeResDto>> getReceivedLikes(@LoginAccountId Long accountId) {
return ApiResponse.success(myGardenService.getReceivedLikes(accountId));
}

@Override
@GetMapping("/liked-stories")
public ApiResponse<List<LikedStoryResDto>> getLikedStories(@LoginAccountId Long accountId) {
return ApiResponse.success(myGardenService.getLikedStories(accountId));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.likelion.monday.domain.mygarden.controller;

import com.likelion.monday.domain.mygarden.dto.LikedStoryResDto;
import com.likelion.monday.domain.mygarden.dto.MyActivitySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.MyStorySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.ReceivedLikeResDto;
import com.likelion.monday.domain.mygarden.dto.SentStoryResDto;
import com.likelion.monday.domain.story.entity.StoryStatus;
import com.likelion.monday.global.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -27,4 +31,32 @@ public interface MyGardenControllerDocs {
security = @SecurityRequirement(name = "bearerAuth")
)
ApiResponse<List<MyStorySummaryResDto>> getMyStories(@Parameter(hidden = true) Long accountId, StoryStatus status);

@Operation(
summary = "내 정원 홈 - 활동 요약 조회",
description = "보낸 사연 수, 공감받은 수, 공감한 사연 수를 개수로만 조회한다.",
security = @SecurityRequirement(name = "bearerAuth")
)
ApiResponse<MyActivitySummaryResDto> getActivitySummary(@Parameter(hidden = true) Long accountId);

@Operation(
summary = "보낸 사연 조회",
description = "내가 작성한 사연 전체를 최신순으로 조회한다.",
security = @SecurityRequirement(name = "bearerAuth")
)
ApiResponse<List<SentStoryResDto>> getSentStories(@Parameter(hidden = true) Long accountId);

@Operation(
summary = "받은 공감 조회",
description = "내가 쓴 사연들에 달린 공감을 최신순으로 조회한다.",
security = @SecurityRequirement(name = "bearerAuth")
)
ApiResponse<List<ReceivedLikeResDto>> getReceivedLikes(@Parameter(hidden = true) Long accountId);

@Operation(
summary = "공감한 사연 조회",
description = "내가 다른 사연에 남긴 공감을 최신순으로 조회한다.",
security = @SecurityRequirement(name = "bearerAuth")
)
ApiResponse<List<LikedStoryResDto>> getLikedStories(@Parameter(hidden = true) Long accountId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.likelion.monday.domain.mygarden.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

@Schema(description = "내 정원 - 공감한 사연 목록 항목")
public record LikedStoryResDto(

@Schema(description = "사연 ID", example = "1")
Long storyId,

@Schema(description = "사연 제목", example = "우리 집 귀염둥이에게")
String storyTitle,

@Schema(description = "공감한 일시")
LocalDateTime likedAt
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.likelion.monday.domain.mygarden.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "내 정원 홈 - 활동 요약")
public record MyActivitySummaryResDto(

@Schema(description = "내가 보낸 사연 수", example = "3")
long sentStoryCount,

@Schema(description = "내가 쓴 사연들이 받은 공감 수", example = "24")
long receivedLikeCount,

@Schema(description = "내가 남긴 공감 수", example = "10")
long likedStoryCount
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.likelion.monday.domain.mygarden.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "내 정원 - 받은 공감 목록 항목")
public record ReceivedLikeResDto(

@Schema(description = "공감 ID", example = "1")
Long likeId,

@Schema(description = "공감이 달린 사연 ID", example = "1")
Long storyId,

@Schema(description = "공감이 달린 사연 제목", example = "우리 집 귀염둥이에게")
String storyTitle
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.likelion.monday.domain.mygarden.dto;

import com.likelion.monday.domain.story.entity.StoryStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

@Schema(description = "내 정원 - 보낸 사연 목록 항목")
public record SentStoryResDto(

@Schema(description = "사연 ID", example = "1")
Long storyId,

@Schema(description = "사연 제목", example = "우리 집 귀염둥이에게")
String title,

@Schema(description = "사연 상태", example = "PENDING")
StoryStatus status,

@Schema(description = "제출 일시")
LocalDateTime createdAt
) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.likelion.monday.domain.mygarden.mapper;

import com.likelion.monday.domain.mygarden.dto.LikedStoryResDto;
import com.likelion.monday.domain.mygarden.dto.MyStorySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.ReceivedLikeResDto;
import com.likelion.monday.domain.mygarden.dto.SentStoryResDto;
import com.likelion.monday.domain.story.entity.Story;
import com.likelion.monday.domain.story.entity.StoryLike;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -16,4 +20,26 @@ public MyStorySummaryResDto toSummaryResDto(Story story) {
story.getLikeCount(),
story.getCreatedAt());
}

public SentStoryResDto toSentStoryResDto(Story story) {
return new SentStoryResDto(
story.getId(),
story.getTitle(),
story.getStatus(),
story.getCreatedAt());
}

public ReceivedLikeResDto toReceivedLikeResDto(StoryLike like) {
return new ReceivedLikeResDto(
like.getId(),
like.getStory().getId(),
like.getStory().getTitle());
}

public LikedStoryResDto toLikedStoryResDto(StoryLike like) {
return new LikedStoryResDto(
like.getStory().getId(),
like.getStory().getTitle(),
like.getCreatedAt());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.likelion.monday.domain.mygarden.service;

import com.likelion.monday.domain.mygarden.dto.LikedStoryResDto;
import com.likelion.monday.domain.mygarden.dto.MyActivitySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.MyStorySummaryResDto;
import com.likelion.monday.domain.mygarden.dto.ReceivedLikeResDto;
import com.likelion.monday.domain.mygarden.dto.SentStoryResDto;
import com.likelion.monday.domain.mygarden.mapper.MyGardenMapper;
import com.likelion.monday.domain.story.entity.Story;
import com.likelion.monday.domain.story.entity.StoryStatus;
import com.likelion.monday.domain.story.repository.StoryLikeRepository;
import com.likelion.monday.domain.story.repository.StoryRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +21,7 @@
public class MyGardenService {

private final StoryRepository storyRepository;
private final StoryLikeRepository storyLikeRepository;
private final MyGardenMapper myGardenMapper;

public List<MyStorySummaryResDto> getMyStoriesPreview(Long accountId) {
Expand All @@ -33,4 +39,31 @@ public List<MyStorySummaryResDto> getMyStories(Long accountId, StoryStatus statu
.map(myGardenMapper::toSummaryResDto)
.toList();
}

public MyActivitySummaryResDto getActivitySummary(Long accountId) {
long sentStoryCount = storyRepository.countByAccountId(accountId);
long receivedLikeCount = storyLikeRepository.countByStory_AccountId(accountId);
long likedStoryCount = storyLikeRepository.countByAccountId(accountId);

return new MyActivitySummaryResDto(sentStoryCount, receivedLikeCount, likedStoryCount);
}

public List<SentStoryResDto> getSentStories(Long accountId) {
return storyRepository.findAllByAccountIdOrderByCreatedAtDesc(accountId).stream()
.map(myGardenMapper::toSentStoryResDto)
.toList();
}

// 받은 공감: 내가 쓴 사연들에 달린 공감
public List<ReceivedLikeResDto> getReceivedLikes(Long accountId) {
return storyLikeRepository.findAllByStory_AccountIdOrderByCreatedAtDesc(accountId).stream()
.map(myGardenMapper::toReceivedLikeResDto)
.toList();
}

public List<LikedStoryResDto> getLikedStories(Long accountId) {
return storyLikeRepository.findAllByAccountIdOrderByCreatedAtDesc(accountId).stream()
.map(myGardenMapper::toLikedStoryResDto)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface NotificationRepository extends JpaRepository<Notification, Long> {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.likelion.monday.domain.story.repository;

import com.likelion.monday.domain.story.entity.StoryLike;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StoryLikeRepository extends JpaRepository<StoryLike, Long> {

long countByStory_AccountId(Long accountId);

long countByAccountId(Long accountId);

List<StoryLike> findAllByStory_AccountIdOrderByCreatedAtDesc(Long accountId);

List<StoryLike> findAllByAccountIdOrderByCreatedAtDesc(Long accountId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface StoryRepository extends JpaRepository<Story, Long> {

long countByStatus(StoryStatus status);

long countByAccountId(Long accountId);

Page<Story> findAllByStatus(StoryStatus status, Pageable pageable);

List<Story> findTop2ByAccountIdOrderByCreatedAtDesc(Long accountId);
Expand Down