[ADD] ショートカットのためのサービスとレポジトリを作成しました。
This commit is contained in:
@@ -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<FixedCostModel> findAllByUserId(Long userId);
|
||||||
|
|
||||||
|
public FixedCostModel save(FixedCostModel fixedCostModel);
|
||||||
|
|
||||||
|
public void delete(Long fixedCostId);
|
||||||
|
|
||||||
|
public FixedCostModel findById(Long fixedCostId);
|
||||||
|
}
|
||||||
@@ -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<FixedCostModel> 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<FixedCostEntity, Long> {
|
||||||
|
|
||||||
|
@Query("select f from FixedCostEntity f where f.userEntity.userId = :userId")
|
||||||
|
public List<FixedCostEntity> findByUserId(Long userId);
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user