Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

필터 조회 기능, 일정 조회 기능 #150

Merged
merged 13 commits into from
Jul 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void addInterceptors(InterceptorRegistry registry) {
registry
.addInterceptor(memberAuthInterceptor())
.addPathPatterns("/api/**")
.excludePathPatterns("/api/auth/**", "/api/calendar/public/**", "/api/filter");
.excludePathPatterns("/api/auth/**", "/api/calendar/public/**", "/api/filter", "/api/calendar", "/api/calendar/**");
registry
.addInterceptor(reissueAuthInterceptor())
.addPathPatterns("/auth/reissue")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class FilterService implements


@Override
public CreateFilterResponse createFilter(CreateFilterRequest request) {
@Transactional
public CreateFilterResponse createFilter(final CreateFilterRequest request) {
FilterModel model = requestConverter.from(request);
FilterEntity entity = entityConverter.toEntity(model);
FilterEntity save = filterRepository.save(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
@Entity
@SuperBuilder(toBuilder = true)
Expand All @@ -18,7 +18,7 @@
public class FilterEntity extends BaseEntity {

@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long filterId;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.demo.schedule.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class AllPrivateCalendarResponse {
private Long eventId;
private String eventName;
private String eventStartDate;
private String eventEndDate;
private String eventPlace;
private String eventInfo;
private String eventScope;
private String scheduleType;
private String filterName;
private String filterColor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.demo.schedule.application.dto;

import com.example.demo.filter.persistence.FilterEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class AllPublicCalendarResponse {
private Long eventId;
private String eventName;
private String eventStartDate;
private String eventEndDate;
private String eventPlace;
private String eventInfo;
private String scheduleType;
private String filterName;
private String filterColor;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.demo.schedule.application.dto;

import com.example.demo.common.support.dto.AbstractDto;
import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.filter.persistence.FilterEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -20,5 +22,7 @@ public class CreateScheduleRequest implements AbstractDto {
private LocalDateTime eventEndDate;
private String eventInfo;
private String eventPlace;
private String scheduleType;
private FilterEntity filter;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import com.example.demo.common.support.AbstractModel;
import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.filter.persistence.FilterEntity;
import com.example.demo.schedule.persistence.ScheduleType;
import lombok.*;

Expand All @@ -20,6 +22,9 @@ public class ScheduleModel implements AbstractModel {
private LocalDateTime eventEndDate;
private String eventInfo;
private String eventPlace;
private String scheduleType;
private FilterEntity filter;


public ScheduleModel update(ScheduleModel requestModel) {

Expand All @@ -31,4 +36,6 @@ public ScheduleModel update(ScheduleModel requestModel) {

return this;
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.example.demo.schedule.application.model.converter;

import com.example.demo.common.support.converter.AbstractEntityConverter;
import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.filter.persistence.FilterEntity;
import com.example.demo.schedule.application.dto.CreateScheduleRequest;
import com.example.demo.schedule.application.model.ScheduleModel;
import com.example.demo.schedule.persistence.ScheduleEntity;
import org.springframework.stereotype.Component;
Expand All @@ -15,8 +18,10 @@ public ScheduleModel from(ScheduleEntity source) {
.eventName(source.getEventName())
.eventStartDate(source.getEventStartDate())
.eventEndDate(source.getEventEndDate())
.eventPlace(source.getEventPlace())
.eventInfo(source.getEventInfo())
.eventPlace(source.getEventPlace())
.scheduleType(source.getScheduleType())
.filter(source.getFilter())
.build();
}

Expand All @@ -27,8 +32,12 @@ public ScheduleEntity toEntity(ScheduleModel source) {
.eventName(source.getEventName())
.eventStartDate(source.getEventStartDate())
.eventEndDate(source.getEventEndDate())
.eventPlace(source.getEventPlace())
.eventInfo(source.getEventInfo())
.eventPlace(source.getEventPlace())
.scheduleType(source.getScheduleType())
.filter(source.getFilter())
.build();
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.schedule.application.model.converter;

import com.example.demo.common.support.converter.AbstractDtoConverter;
import com.example.demo.filter.persistence.FilterEntity;
import com.example.demo.schedule.application.dto.CreateScheduleRequest;
import com.example.demo.schedule.application.dto.UpdateScheduleRequest;
import com.example.demo.schedule.application.model.ScheduleModel;
Expand All @@ -17,6 +18,8 @@ public ScheduleModel from(CreateScheduleRequest source) {
.eventEndDate(source.getEventEndDate())
.eventInfo(source.getEventInfo())
.eventPlace(source.getEventPlace())
.scheduleType(source.getScheduleType())
.filter(source.getFilter())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
public class ScheduleResponseConverter {
Expand Down Expand Up @@ -35,6 +37,17 @@ public SpecificScheduleResopnse from(ScheduleModel model) {
.build();
}

// public interface CalendarResponseConverter<R extends CalendarResponse> {
// List<R> toModel(List<ScheduleModel> models);
// }
//
// public <T extends CalendarResponse> List<T> toModel(List<ScheduleModel> models, Function<ScheduleModel, T> responseBuilder) {
// return models.stream()
// .map(responseBuilder)
// .collect(Collectors.toList());
// }


public List<YearCalendarResponse> toYearModel(List<ScheduleModel> models) {

List<YearCalendarResponse> response = new ArrayList<>();
Expand Down Expand Up @@ -63,6 +76,52 @@ public List<AllCalendarResponse> toAllModel(List<ScheduleModel> models) {
return response;
}

public List<AllPublicCalendarResponse> toPublicModel(List<ScheduleModel> models) {
return models.stream()
.map(this::toPublicCalendarResponse)
.collect(Collectors.toList());
}

private AllPublicCalendarResponse toPublicCalendarResponse(ScheduleModel model) {
return AllPublicCalendarResponse.builder()
.eventId(model.getEventId())
.eventName(model.getEventName())
.eventStartDate(model.getEventStartDate().toString())
.eventEndDate(model.getEventEndDate().toString())
.eventPlace(model.getEventPlace())
.eventInfo(model.getEventInfo())
.scheduleType(model.getScheduleType())
.filterName(model.getFilter() != null ? model.getFilter().getFilterName() : null)
.filterColor(model.getFilter() != null ? model.getFilter().getFilterColor() : null)
.build();
}




public List<AllPrivateCalendarResponse> toPrivateModel(List<ScheduleModel> models) {
return models.stream()
.map(this::toPrivateCalendarResponse)
.collect(Collectors.toList());
}

private AllPrivateCalendarResponse toPrivateCalendarResponse(ScheduleModel model) {
return AllPrivateCalendarResponse.builder()
.eventId(model.getEventId())
.eventName(model.getEventName())
.eventStartDate(model.getEventStartDate().toString())
.eventEndDate(model.getEventEndDate().toString())
.eventPlace(model.getEventPlace())
.eventInfo(model.getEventInfo())
.scheduleType(model.getScheduleType())
.filterName(model.getFilter() != null ? model.getFilter().getFilterName() : null)
.filterColor(model.getFilter() != null ? model.getFilter().getFilterColor() : null)
.build();
}




public List<MonthCalendarResponse> toMonthModel(List<ScheduleModel> models) {

List<MonthCalendarResponse> response = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.demo.schedule.application.service;

import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.filter.persistence.FilterEntity;
import com.example.demo.schedule.application.dto.*;
import com.example.demo.schedule.application.model.ScheduleModel;
import com.example.demo.schedule.application.model.converter.ScheduleEntityConverter;
Expand All @@ -8,6 +10,7 @@
import com.example.demo.schedule.application.usecase.*;
import com.example.demo.schedule.persistence.ScheduleEntity;
import com.example.demo.schedule.persistence.ScheduleRepository;
import com.example.demo.schedule.persistence.ScheduleType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -22,14 +25,26 @@
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ScheduleService implements CreateScheduleUsecase,
GetSpecificScheduleUsecase,
GetYearScheduleUsecase,
GetMonthScheduleUsecase,
UpdateScheduleUsecase,
DeleteScheduleUsecase,
GetWeekScheduleUsecase,
GetAllScheduleUsecase {
GetSpecificScheduleUsecase,
GetYearScheduleUsecase,
GetMonthScheduleUsecase,
UpdateScheduleUsecase,
DeleteScheduleUsecase,
GetWeekScheduleUsecase,
GetAllScheduleUsecase
//GetAllPrivateScheduleUsecase,
//GetAllPublicScheduleUsecase
{

@Override
public List<MonthCalendarResponse> getMonthSchedule(int year, int month) {
return null;
}

@Override
public List<YearCalendarResponse> getYearSchedule(int year) {
return null;
}

private final ScheduleRequestConverter requestConverter;
private final ScheduleEntityConverter entityConverter;
Expand All @@ -39,13 +54,12 @@ public class ScheduleService implements CreateScheduleUsecase,

@Override
@Transactional
public CreateScheduleResponse create(final CreateScheduleRequest request){
public CreateScheduleResponse create(final CreateScheduleRequest request) {
ScheduleModel model = requestConverter.from(request);
Long saveId = createSchedule(model);
return responseConverter.from(saveId);
}


private Long createSchedule(ScheduleModel model) {
ScheduleEntity entity = entityConverter.toEntity(model);
ScheduleEntity save = scheduleRepository.save(entity);
Expand Down Expand Up @@ -100,35 +114,41 @@ public List<AllCalendarResponse> getAllSchedule() {
return responseConverter.toAllModel(model);
}

@Override
public List<AllPublicCalendarResponse> getPublicSchedule() {
List<ScheduleModel> model = filterPublic();
return responseConverter.toPublicModel(model);
}

private List<ScheduleModel> filterEntitiesByAll() {
Stream<ScheduleEntity> entities = scheduleRepository.streamAll();
return entities
private List<ScheduleModel> filterPublic() {
Stream<ScheduleEntity> entity = scheduleRepository.streamAllPublic();
return entity
.map(entityConverter::from)
.collect(Collectors.toList());
}


@Override
public List<YearCalendarResponse> getYearSchedule(final int year) {
List<ScheduleModel> model = filterEntitiesByYear(year);
return responseConverter.toYearModel(model);
public List<AllPrivateCalendarResponse> getPrivateSchedule() {
List<ScheduleModel> model = filterPrivate();
return responseConverter.toPrivateModel(model);
}

private List<ScheduleModel> filterPrivate() {
Stream<ScheduleEntity> entity = scheduleRepository.streamAllPrivate();
return entity
.map(entityConverter::from)
.collect(Collectors.toList());
}

private List<ScheduleModel> filterEntitiesByYear(final int year) {

private List<ScheduleModel> filterEntitiesByAll() {
Stream<ScheduleEntity> entities = scheduleRepository.streamAll();
return entities
.filter(entity -> entity.getEventStartDate().getYear() == year)
.map(entityConverter::from)
.collect(Collectors.toList());
}


@Override
public List<MonthCalendarResponse> getMonthSchedule(final int year, final int month) {
List<ScheduleModel> model = filterEntitiesByMonth(year, month);
return responseConverter.toMonthModel(model);
}


private List<ScheduleModel> filterEntitiesByMonth(final int year, final int month) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.example.demo.schedule.application.usecase;

import com.example.demo.schedule.application.dto.AllCalendarResponse;
import com.example.demo.schedule.application.dto.AllPrivateCalendarResponse;
import com.example.demo.schedule.application.dto.AllPublicCalendarResponse;

import java.util.List;

public interface GetAllScheduleUsecase {
List<AllCalendarResponse> getAllSchedule();

List<AllPublicCalendarResponse> getPublicSchedule();

List<AllPrivateCalendarResponse> getPrivateSchedule();
}
Loading
Loading