-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
252 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/com/kimgreen/backend/domain/community/repository/PostImgRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.kimgreen.backend.domain.community.repository; | ||
|
||
import com.kimgreen.backend.domain.community.entity.Post; | ||
import com.kimgreen.backend.domain.community.entity.PostImg; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface PostImgRepository extends JpaRepository<PostImg, Long> { | ||
|
||
public PostImg findByPost(Post post); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.kimgreen.backend.domain.profile.dto.Calendar; | ||
|
||
import com.kimgreen.backend.domain.community.entity.Post; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CalendarDetailDto { | ||
private Long postId; | ||
private String writerNickname; | ||
private String profileImg; | ||
private String writerBadge; | ||
private String content; | ||
private int likeCount; | ||
private Long commentCount; | ||
private String imgUrl; | ||
private Boolean isLiked; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.kimgreen.backend.domain.profile.dto.Calendar; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CalendarDetailRequestDto { | ||
private Long memberId; | ||
private String date; | ||
} |
25 changes: 25 additions & 0 deletions
25
...main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.kimgreen.backend.domain.profile.dto.Calendar; | ||
|
||
import com.kimgreen.backend.domain.community.entity.Post; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CalendarDetailResponseDto { | ||
private int postCount; | ||
private List<CalendarDetailDto> contents; | ||
|
||
public static CalendarDetailResponseDto toDto(int count, List<CalendarDetailDto> contents) { | ||
return CalendarDetailResponseDto.builder() | ||
.postCount(count) | ||
.contents(contents) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.kimgreen.backend.domain.profile.dto.Calendar; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CalendarResponseDto { | ||
private String date; | ||
private int postCount; | ||
} |
146 changes: 146 additions & 0 deletions
146
src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,155 @@ | ||
package com.kimgreen.backend.domain.profile.service; | ||
|
||
import com.kimgreen.backend.domain.community.entity.Comment; | ||
import com.kimgreen.backend.domain.community.entity.Likes; | ||
import com.kimgreen.backend.domain.community.entity.Post; | ||
import com.kimgreen.backend.domain.community.entity.PostImg; | ||
import com.kimgreen.backend.domain.community.repository.CommentRepository; | ||
import com.kimgreen.backend.domain.community.repository.LikeRepository; | ||
import com.kimgreen.backend.domain.community.repository.PostImgRepository; | ||
import com.kimgreen.backend.domain.community.repository.PostRepository; | ||
import com.kimgreen.backend.domain.community.service.S3Service; | ||
import com.kimgreen.backend.domain.member.entity.Member; | ||
import com.kimgreen.backend.domain.member.entity.MemberProfileImg; | ||
import com.kimgreen.backend.domain.member.repository.MemberProfileImgRepository; | ||
import com.kimgreen.backend.domain.member.repository.MemberRepository; | ||
import com.kimgreen.backend.domain.member.service.MemberService; | ||
import com.kimgreen.backend.domain.profile.dto.Calendar.CalendarDetailDto; | ||
import com.kimgreen.backend.domain.profile.dto.Calendar.CalendarDetailRequestDto; | ||
import com.kimgreen.backend.domain.profile.dto.Calendar.CalendarDetailResponseDto; | ||
import com.kimgreen.backend.domain.profile.dto.Calendar.CalendarResponseDto; | ||
import com.kimgreen.backend.domain.profile.entity.RepresentativeBadge; | ||
import com.kimgreen.backend.domain.profile.repository.RepresentativeBadgeRepository; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.swing.text.DateFormatter; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.*; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class CalendarService { | ||
private final PostRepository postRepository; | ||
private final MemberService memberService; | ||
private final RepresentativeBadgeRepository representativeBadgeRepository; | ||
private final PostImgRepository postImgRepository; | ||
private final MemberProfileImgRepository memberProfileImgRepository; | ||
private final S3Service s3Service; | ||
private final LikeRepository likeRepository; | ||
private final CommentRepository commentRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
public List<CalendarResponseDto> getCalendar(Long memberId, String date) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
LocalDateTime localDateTime = LocalDate.parse(date, formatter).withDayOfMonth(1).atStartOfDay(); | ||
LocalDateTime start = localDateTime; | ||
LocalDateTime end = localDateTime.withDayOfMonth(start.toLocalDate().lengthOfMonth()).withHour(23).withMinute(59).withSecond(59); | ||
|
||
List<Post> postList = postRepository.findAllBetweenDate(memberId,start,end); | ||
return getDtoList(postList); | ||
} | ||
|
||
public CalendarDetailResponseDto getCalendarDetails(CalendarDetailRequestDto dto) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
LocalDateTime start = LocalDate.parse(dto.getDate(), formatter).atStartOfDay(); | ||
LocalDateTime end = start.withHour(23).withMinute(59).withSecond(59); | ||
List<Post> postList = postRepository.findAllByCreatedAtBetween(start,end); | ||
return CalendarDetailResponseDto.toDto(postList.size(),getResult(postList)); | ||
|
||
} | ||
|
||
public List<CalendarResponseDto> getDtoList(List<Post> postList) { | ||
Map<String,Integer> resultMap = new HashMap<>(); | ||
for(Post post:postList) { | ||
String key = post.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | ||
if(!resultMap.containsKey(key)) { | ||
resultMap.put(key,1); | ||
} else { | ||
Integer value =resultMap.get(key); | ||
resultMap.put(key,++value); | ||
} | ||
} | ||
|
||
return toList(resultMap); | ||
} | ||
|
||
public List<CalendarResponseDto> toList(Map<String, Integer> maps) { | ||
List<CalendarResponseDto> result = new ArrayList<>(); | ||
for(Map.Entry<String, Integer> map :maps.entrySet()) { | ||
result.add(CalendarResponseDto.builder() | ||
.date(map.getKey()) | ||
.postCount(map.getValue()) | ||
.build()); | ||
} | ||
return result; | ||
} | ||
|
||
public List<CalendarDetailDto> getResult(List<Post> postList) { | ||
CalendarDetailDto dto; | ||
List<CalendarDetailDto> result = new ArrayList<>(); | ||
for(Post post : postList) { | ||
Long postId = post.getPostId(); | ||
Member member = post.getMember(); | ||
RepresentativeBadge badge = representativeBadgeRepository.findByMember(member); | ||
MemberProfileImg profileImg = memberProfileImgRepository.findByMember(member); | ||
PostImg postImg = postImgRepository.findByPost(post); | ||
List<Likes> likeList = post.getLikes(); | ||
boolean isLiked = isLiked(likeList,member); | ||
//Long likes = likeRepository.countLike(postId); | ||
Long comments = commentRepository.countComment(postId); | ||
|
||
|
||
if(postImg==null) { | ||
dto = dtoBuilderWithNoImg(postId,member.getNickname(),s3Service.getFullUrl(profileImg.getImgUrl()),badge.getRepresentativeBadge().name | ||
,post.getContent(),likeList.size(),comments,isLiked); | ||
} else { | ||
dto = dtoBuilderWithImg(postId, member.getNickname(), s3Service.getFullUrl(profileImg.getImgUrl()), badge.getRepresentativeBadge().name | ||
, post.getContent(), likeList.size(), comments, s3Service.getFullUrl(postImg.getImgUrl()),isLiked); | ||
} | ||
|
||
result.add(dto); | ||
} | ||
return result; | ||
} | ||
|
||
public CalendarDetailDto dtoBuilderWithImg(Long postId, String nickname, String profileImg,String name,String content | ||
,int likes, Long comments, String postImg, boolean isLiked) { | ||
return CalendarDetailDto.builder() | ||
.postId(postId) | ||
.writerNickname(nickname) | ||
.profileImg(profileImg) | ||
.writerBadge(name) | ||
.content(content) | ||
.likeCount(likes) | ||
.commentCount(comments) | ||
.imgUrl(postImg) | ||
.isLiked(isLiked) | ||
.build(); | ||
} | ||
|
||
public CalendarDetailDto dtoBuilderWithNoImg(Long postId, String nickname, String profileImg,String name,String content | ||
,int likes, Long comments, boolean isLiked) { | ||
return CalendarDetailDto.builder() | ||
.postId(postId) | ||
.writerNickname(nickname) | ||
.profileImg(profileImg) | ||
.writerBadge(name) | ||
.content(content) | ||
.likeCount(likes) | ||
.commentCount(comments) | ||
.isLiked(isLiked) | ||
.build(); | ||
} | ||
|
||
public boolean isLiked(List<Likes> likesList,Member member) { | ||
for(Likes like : likesList) { | ||
if(like.getLikeId().equals(member.getMemberId())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |