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 @@ -4,6 +4,8 @@
import com.example.Midnight.Snacker.domain.Comment;
import com.example.Midnight.Snacker.domain.Member;
import com.example.Midnight.Snacker.domain.Post;
import com.example.Midnight.Snacker.domain.enums.Color;
import com.example.Midnight.Snacker.repository.CalendarRepository;
import com.example.Midnight.Snacker.repository.CommentRepository;
import com.example.Midnight.Snacker.repository.MemberRepository;
import com.example.Midnight.Snacker.repository.PostRepository;
Expand All @@ -27,6 +29,7 @@ public class PostServiceImpl implements PostService {
private final PostRepository postRepository;
private final MemberRepository memberRepository;
private final CommentRepository commentRepository;
private final CalendarRepository calendarRepository;

@Override
public Post AddPost(String title, String body, String imageUrl, LocalDateTime date, Member member) {
Expand All @@ -46,7 +49,8 @@ public Post AddPost(String title, String body, String imageUrl, LocalDateTime da

@Override
public void DeletePost(long id) {
Post post = postRepository.findById(id).orElseThrow(() ->new PostHandler(ErrorStatus.POST_NOT_FOUND));
Post post = postRepository.findById(id)
.orElseThrow(() ->new PostHandler(ErrorStatus.POST_NOT_FOUND));
postRepository.delete(post);
} // 게시글 삭제

Expand Down Expand Up @@ -82,12 +86,28 @@ public List<CommentResponseDTO.CommentInfoDTO> getComments(Long postId){
return comments.stream()
. map(comment -> new CommentResponseDTO.CommentInfoDTO(
comment.getId(),
comment.getMember().getId(),
comment.getMember().getNickname(),
getRate(comment.getMember()),
comment.getContent(),
comment.getDate().toLocalDate()
)).toList();
}

float getRate(Member member){
LocalDateTime now = LocalDateTime.now();

LocalDateTime startOfMonth = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endOfMonth = now.withHour(23).withMinute(59).withSecond(59).withNano(999999999);

int blackCount = calendarRepository.countByMemberAndColorAndDateBetween(member, Color.BLACK, startOfMonth, endOfMonth);

int totalCount = calendarRepository.countByMemberAndDateBetween(member, startOfMonth, endOfMonth);

float rating = totalCount == 0 ? 0 : ((float) blackCount / totalCount) * 100;
return rating;
}


@Override
@Transactional
Expand All @@ -96,9 +116,16 @@ public PostResponseDTO.getIndiPostResponseDTO getPost(Long postId){

Post post = postRepository.findById(postId).get();


return new PostResponseDTO.getIndiPostResponseDTO(
post.getMember().getNickname(), post.getTitle(),
post.getBody(), post.getImageUrl(), comments);
post.getMember().getId(),
post.getMember().getNickname(),
post.getTitle(),
post.getBody(),g
post.getDate().toLocalDate(),
post.getImageUrl(),
comments,
getRate(post.getMember()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ApiResponse<Long> registerCalendar(
return ApiResponse.of(SuccessStatus.ADD_CALENDAR_OK, calendarId);
}

@GetMapping("/api/calender/monthly")
@GetMapping("/monthly")
@Operation(
summary = "월별 기록 조회 API")
public ApiResponse<CalendarResponseDTO.CalendarResponseMonthlyListDTO> getMonthlyCalendar(
Expand All @@ -61,7 +61,7 @@ public ApiResponse<CalendarResponseDTO.CalendarResponseMonthlyListDTO> getMonthl
return ApiResponse.of(SuccessStatus.INQUERY_MONTH_CALENDAR_OK,response);
}

@GetMapping("/api/calender/count/daily")
@GetMapping("/daily")
@Operation(
summary = "일별 기록 조회 API")
public ApiResponse<List<CalendarResponseDTO.CalendarResponseDailyDTO>> getDailyCalendar(
Expand All @@ -83,7 +83,7 @@ public ApiResponse<Void> deleteCalendar(
}


@GetMapping("/api/calender/count")
@GetMapping("/count")
@Operation(summary = "한달 동안의 야식 카테고리 결산")
public ApiResponse<calenderCountResponseDTO.MissionPreviewListDTO> monthCategoryCount(
@Parameter(name = "user", hidden = true) @AuthUser Member member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public static class CommentPostResponseDTO{
@AllArgsConstructor
public static class CommentInfoDTO{
private Long commentId;
private Long memberId;
private String nickname;
private Float percent;
private String content;
private LocalDate date;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.Midnight.Snacker.web.dto.CommentDTO.CommentResponseDTO;
import lombok.*;

import java.time.LocalDate;
import java.util.List;

public class PostResponseDTO {
Expand All @@ -28,10 +29,13 @@ public static class getPostResponseDTO{
@NoArgsConstructor
@AllArgsConstructor
public static class getIndiPostResponseDTO{
private Long memberId;
private String nickname;
private String title;
private String body;
private LocalDate date;
private String imageUrl;
private List<CommentResponseDTO.CommentInfoDTO> comments;
private float rating;
}
}
Loading