diff --git a/src/main/java/com/example/demo/app/domain/service/FixedCostService.java b/src/main/java/com/example/demo/app/domain/service/FixedCostService.java new file mode 100644 index 0000000..52ba6fd --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/FixedCostService.java @@ -0,0 +1,16 @@ +package com.example.demo.app.domain.service; + +import java.util.List; + +import com.example.demo.app.domain.model.FixedCostModel; + +public interface FixedCostService { + + public List findAllByUserId(Long userId); + + public FixedCostModel save(FixedCostModel fixedCostModel); + + public void delete(Long fixedCostId); + + public FixedCostModel findById(Long fixedCostId); +} diff --git a/src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java new file mode 100644 index 0000000..e79597d --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java @@ -0,0 +1,48 @@ +package com.example.demo.app.domain.service.impl; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.example.demo.app.domain.model.FixedCostModel; +import com.example.demo.app.domain.service.FixedCostService; +import com.example.demo.app.infra.repository.CategoryRepository; +import com.example.demo.app.infra.repository.FixedCostRepository; +import com.example.demo.app.infra.repository.UserRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class FixedCostServiceImpl implements FixedCostService{ + + + private final FixedCostRepository fixedCostRepository; + private final UserRepository userRepository; + private final CategoryRepository categoryRepository; + + + public List findAllByUserId(Long userId) { + + return FixedCostModel.convertFrom(fixedCostRepository.findByUserId(userId)); + + } + + public FixedCostModel save(FixedCostModel fixedCostModel) { + + return FixedCostModel.convertFrom(fixedCostRepository.save( FixedCostModel.convertTo(fixedCostModel, userRepository.findById(fixedCostModel.getUserId()).get(), categoryRepository.findById(fixedCostModel.getCategoryId()).get()))); + + } + + public void delete(Long fixedCostId) { + + fixedCostRepository.deleteById(fixedCostId); + + } + + public FixedCostModel findById(Long fixedCostId) { + return FixedCostModel.convertFrom(fixedCostRepository.findById(fixedCostId).get()); + } + + +} diff --git a/src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java b/src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java new file mode 100644 index 0000000..fe7279d --- /dev/null +++ b/src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java @@ -0,0 +1,15 @@ +package com.example.demo.app.infra.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import com.example.demo.app.infra.entity.FixedCostEntity; + +public interface FixedCostRepository extends JpaRepository { + + @Query("select f from FixedCostEntity f where f.userEntity.userId = :userId") + public List findByUserId(Long userId); + +}