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 @@ -13,7 +13,7 @@ public record GetAllDiaryResponseDto(

) {

public static GetAllDiaryResponseDto from(List<GetDiaryInfoDto> diaryList) {
public static GetAllDiaryResponseDto from(final List<GetDiaryInfoDto> diaryList) {

List<GetDailyDiaryDto> grouped =
diaryList.stream()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/petlog/docs/S3ControllerDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Tag(name = "S3 API")
public interface S3ControllerDocs {

@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "S3 presigned URL 생성에 성공하였습니다.")
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "S3 presigned URL 발급에 성공하였습니다.")
@Operation(summary = "S3 Presigned URL 발급 API")
ResponseEntity<ApiResponse<S3PresignedUrlsResponseDto>> issueS3PresignedUrls(@Authenticated final Long memberId, @RequestBody final S3PresignedUrlsRequestDto request);
}
2 changes: 1 addition & 1 deletion src/main/java/com/petlog/docs/ScheduleControllerDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface ScheduleControllerDocs {

@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "월별 일정 전체 조회에 성공하였습니다.")
@Operation(summary = "월별 일정 전체 조회 API")
ResponseEntity<ApiResponse<GetMonthlyScheduleResponseDto>> getAllSchedule(@PathVariable final Long groupId, @RequestParam @DateTimeFormat(pattern = "yyyy-MM") final YearMonth date);
ResponseEntity<ApiResponse<GetMonthlyScheduleResponseDto>> getAllSchedule(@Authenticated final Long memberId, @PathVariable final Long groupId, @RequestParam @DateTimeFormat(pattern = "yyyy-MM") final YearMonth date);

@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "일정 상세 내용 수정에 성공하였습니다.")
@Operation(summary = "일정 상세 내용 수정 API")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/petlog/s3/controller/S3SuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@RequiredArgsConstructor
public enum S3SuccessCode implements SuccessCode {

GENERATE_S3_PRESIGNED_URLS(HttpStatus.CREATED.value(), "S3 presigned URL 생성에 성공하였습니다."),
GENERATE_S3_PRESIGNED_URLS(HttpStatus.CREATED.value(), "S3 presigned URL 발급에 성공하였습니다."),
;

private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import com.petlog.schedule.controller.dto.request.CreateScheduleRequestDto;
import com.petlog.schedule.controller.dto.request.UpdateScheduleRequestDto;
import com.petlog.schedule.controller.dto.response.GetMonthlyScheduleResponseDto;
import com.petlog.schedule.entity.ScheduleType;
import com.petlog.schedule.service.ScheduleService;
import com.petlog.schedule.service.dto.CreateScheduleDto;
import com.petlog.schedule.service.dto.GetDailyScheduleDto;
import com.petlog.schedule.service.dto.GetScheduleInfoDto;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
Expand All @@ -24,8 +22,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

Expand Down Expand Up @@ -65,15 +61,13 @@ public ResponseEntity<ApiResponse<Void>> createSchedule(

@GetMapping
public ResponseEntity<ApiResponse<GetMonthlyScheduleResponseDto>> getAllSchedule(
@Authenticated final Long memberId,
@PathVariable final Long groupId,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM") final YearMonth date
) {

final GetScheduleInfoDto dto = new GetScheduleInfoDto(1L, "병원", true, LocalDateTime.now(), LocalDateTime.now(), ScheduleType.BLUE, LocalDateTime.now(), "memo");

final GetDailyScheduleDto daily = new GetDailyScheduleDto(LocalDate.now(), List.of(dto));

final GetMonthlyScheduleResponseDto response = new GetMonthlyScheduleResponseDto(List.of(daily));
final List<GetScheduleInfoDto> schedules = scheduleService.getMonthlySchedule(memberId, groupId, date);
final GetMonthlyScheduleResponseDto response = GetMonthlyScheduleResponseDto.from(schedules);

return ResponseEntity.ok(
ApiResponse.successWithData(GET_ALL_SCHEDULE, response)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
package com.petlog.schedule.controller.dto.response;

import com.petlog.schedule.service.dto.GetDailyScheduleDto;
import com.petlog.schedule.service.dto.GetScheduleInfoDto;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public record GetMonthlyScheduleResponseDto(

List<GetDailyScheduleDto> monthlySchedules

) {

public static GetMonthlyScheduleResponseDto from(final List<GetScheduleInfoDto> schedules) {

List<GetDailyScheduleDto> grouped =
schedules.stream()
.collect(Collectors.groupingBy(s -> s.startAt().toLocalDate()))
.entrySet()
.stream()
.map(entry ->
new GetDailyScheduleDto(
entry.getKey(),
entry.getValue()
)
)
.sorted(Comparator.comparing(GetDailyScheduleDto::date))
.toList();

return new GetMonthlyScheduleResponseDto(grouped);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.petlog.schedule.repository;

import com.petlog.petgroup.entity.PetGroup;
import com.petlog.schedule.entity.Schedule;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDateTime;
import java.util.List;

public interface ScheduleRepository extends JpaRepository<Schedule, Long> {

List<Schedule> findAllByPetGroupAndStartAtBetween(final PetGroup petGroup, final LocalDateTime start, final LocalDateTime end);
}
31 changes: 31 additions & 0 deletions src/main/java/com/petlog/schedule/service/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
import com.petlog.schedule.entity.Schedule;
import com.petlog.schedule.repository.ScheduleRepository;
import com.petlog.schedule.service.dto.CreateScheduleDto;
import com.petlog.schedule.service.dto.GetScheduleInfoDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.List;

@RequiredArgsConstructor
@Service
public class ScheduleService {
Expand Down Expand Up @@ -56,4 +61,30 @@ private PetGroupMember getPetGroupMember(final Member member, final PetGroup pet
return petGroupMemberRepository.findByMemberAndPetGroup(member, petGroup)
.orElseThrow(() -> new IllegalArgumentException("그룹에 존재하지 않는 회원입니다."));
}

@Transactional(readOnly = true)
public List<GetScheduleInfoDto> getMonthlySchedule(final Long memberId, final Long groupId, final YearMonth date) {
final Member member = getMember(memberId);
final PetGroup petGroup = getPetGroup(groupId);
getPetGroupMember(member, petGroup);

final LocalDateTime start = date.atDay(1).atStartOfDay();
final LocalDateTime end = date.atEndOfMonth().atTime(23, 59, 59);

final List<Schedule> schedules =
scheduleRepository.findAllByPetGroupAndStartAtBetween(petGroup, start, end);

return schedules.stream()
.map(s -> new GetScheduleInfoDto(
s.getId(),
s.getTitle(),
s.isAllDay(),
s.getStartAt(),
s.getEndAt(),
s.getType(),
s.getRemindAt(),
s.getMemo()
))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public record GetScheduleInfoDto(

boolean isAllDay,

LocalDateTime startTime,
LocalDateTime startAt,

LocalDateTime endTime,
LocalDateTime endAt,

@Schema(description = "YELLOW/GREEN/BLUE")
ScheduleType tag,
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ spring:
password: ${DB_PASSWORD:root}

jpa:
hibernate.ddl-auto: update
hibernate.ddl-auto: create
show-sql: true
properties.hibernate.format_sql: true