Skip to content

Commit

Permalink
Filter 생성 기능 개발
Browse files Browse the repository at this point in the history
* feat: filter 생성 controller 기능 개발

* feat: 필터 entity 생성

* feat: filter repository 생성

* feat: filter 생성 dto 추가

* feat: filter 생성 converter 기능 개발

* feat: filter model 추가

* feat: filter 생성 서비스 기능 개발

* feat: create filter usecase 추가

* fix: CreateFilterUsecase path 수정

* fix: CreateFilterUsecase path 수정
  • Loading branch information
capDoYeonLee authored Jul 23, 2024
1 parent 3c43a86 commit f81cccf
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.demo.filter.application.dto;


import com.example.demo.common.support.dto.AbstractDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class CreateFilterRequest implements AbstractDto {
private Long filterId;
private String filterName;
private String filterColor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.demo.filter.application.dto;

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


@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class CreateFilterResponse {
private Long filterId;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.demo.filter.application.model;

import com.example.demo.common.support.AbstractModel;
import lombok.*;

@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class FilterModel implements AbstractModel {
private Long filterId;
private String filterName;
private String filterColor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.demo.filter.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 org.springframework.stereotype.Component;

@Component
public class FilterEntityConverter implements AbstractEntityConverter<FilterEntity, FilterModel> {

@Override
public FilterModel from(FilterEntity source) {
return FilterModel.builder()
.filterId(source.getFilterId())
.filterName(source.getFilterName())
.filterColor(source.getFilterColor())
.build();
}

@Override
public FilterEntity toEntity(FilterModel source) {
return FilterEntity.builder()
.filterId(source.getFilterId())
.filterName(source.getFilterName())
.filterColor(source.getFilterColor())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.demo.filter.application.model.converter;

import com.example.demo.common.support.converter.AbstractDtoConverter;
import com.example.demo.filter.application.dto.CreateFilterRequest;
import com.example.demo.filter.application.dto.CreateFilterResponse;
import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.schedule.application.model.ScheduleModel;
import org.springframework.stereotype.Component;

@Component
public class FilterRequestConverter implements AbstractDtoConverter<CreateFilterRequest, FilterModel> {


@Override
public FilterModel from(CreateFilterRequest source) {
return FilterModel.builder()
.filterId(source.getFilterId())
.filterName(source.getFilterName())
.filterColor(source.getFilterColor())
.build();
}






}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.demo.filter.application.model.converter;

import com.example.demo.filter.application.dto.CreateFilterResponse;
import org.springframework.stereotype.Component;

@Component
public class FilterResponseConverter {

public CreateFilterResponse from(Long filterId) {
return CreateFilterResponse.builder().filterId(filterId).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.demo.filter.application.service;

import com.example.demo.filter.application.dto.CreateFilterRequest;
import com.example.demo.filter.application.dto.CreateFilterResponse;
import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.filter.application.model.converter.FilterEntityConverter;
import com.example.demo.filter.application.model.converter.FilterRequestConverter;
import com.example.demo.filter.application.model.converter.FilterResponseConverter;
import com.example.demo.filter.persistence.FilterEntity;
import com.example.demo.filter.persistence.FilterRepository;
import com.example.demo.filter.application.usecase.CreateFilterUsecase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FilterService implements CreateFilterUsecase {

private final FilterRepository filterRepository;
private final FilterRequestConverter requestConverter;
private final FilterEntityConverter entityConverter;
private final FilterResponseConverter responseConverter;


@Override
public CreateFilterResponse createFilter(CreateFilterRequest request) {
FilterModel model = requestConverter.from(request);
FilterEntity entity = entityConverter.toEntity(model);
FilterEntity save = filterRepository.save(entity);
return responseConverter.from(save.getFilterId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.demo.filter.application.usecase;

import com.example.demo.filter.application.dto.CreateFilterRequest;
import com.example.demo.filter.application.dto.CreateFilterResponse;

public interface CreateFilterUsecase {
CreateFilterResponse createFilter(CreateFilterRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.demo.filter.persistence;

import com.example.demo.common.persistence.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;


@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ToString
@Entity
@SuperBuilder(toBuilder = true)
@Table(name = "filter")
@EntityListeners(AuditingEntityListener.class)
public class FilterEntity extends BaseEntity {

@Id
@GeneratedValue
@Column(nullable = false)
private Long filterId;

@Column(nullable = false)
private String filterName;

@Column(nullable = false)
private String filterColor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.demo.filter.persistence;

import com.example.demo.schedule.persistence.ScheduleEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface FilterRepository extends JpaRepository<FilterEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.demo.filter.presentation;

import com.example.demo.common.presentation.response.ApiResponse;
import com.example.demo.common.presentation.response.ApiResponseBody;
import com.example.demo.common.presentation.response.ApiResponseGenerator;
import com.example.demo.common.presentation.response.MessageCode;
import com.example.demo.filter.application.dto.CreateFilterRequest;
import com.example.demo.filter.application.dto.CreateFilterResponse;
import com.example.demo.filter.application.usecase.CreateFilterUsecase;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/filter")
public class FilterController {

private final CreateFilterUsecase createFilterUsecase;

@PostMapping
public ApiResponse<ApiResponseBody.SuccessBody<CreateFilterResponse>> createFilter(
@RequestBody CreateFilterRequest request) {
CreateFilterResponse response = createFilterUsecase.createFilter(request);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.CREATE);
}



























}

0 comments on commit f81cccf

Please sign in to comment.