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
19 changes: 19 additions & 0 deletions refrigerator/.idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class IngredientCategory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ingredient_category_pk")
private int IngredientCategoryPk;
private int ingredientCategoryPk;

@Column(name = "ingredient_category")
private String IngredientCategory;
private String ingredientCategory;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class IngredientStorage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ingredient_storage_pk")
private int IngredientStoragePk;
private int ingredientStoragePk;

@Column(name = "ingredient_storage")
private String IngredientStorage;
private String ingredientStorage;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package moja.refrigerator.controller.ingredient;

import moja.refrigerator.dto.ingredient.request.IngredientCreateRequest;
import moja.refrigerator.service.ingredient.IngredientService;
import org.springframework.beans.factory.annotation.Autowired;
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;

Expand All @@ -14,4 +17,9 @@ public class IngredientController {
public IngredientController(IngredientService ingredientService) {
this.ingredientService = ingredientService;
}

@PostMapping
public void createIngredient(@RequestBody IngredientCreateRequest request) {
ingredientService.createIngredient(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package moja.refrigerator.dto.ingredient.request;

import lombok.Data;

@Data
public class IngredientCreateRequest {
private String ingredientName;
private String expirationDate;
private String registrationDate;
private int seasonDate;

// private int ingredientCategoryPk;
// private int ingredientStoragePk;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package moja.refrigerator.repository.ingredient;

import moja.refrigerator.aggregate.ingredient.IngredientCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface IngredientCategoryRepository extends JpaRepository<IngredientCategory, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import moja.refrigerator.aggregate.ingredient.IngredientManagement;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface IngredientManagementRepository extends JpaRepository<IngredientManagement, Long> {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package moja.refrigerator.repository.ingredient;

import moja.refrigerator.aggregate.ingredient.IngredientStorage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface IngredientStorageRepository extends JpaRepository<IngredientStorage, Integer> {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package moja.refrigerator.service.ingredient;

import moja.refrigerator.dto.ingredient.request.IngredientCreateRequest;

public interface IngredientService {
void createIngredient(IngredientCreateRequest request);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
package moja.refrigerator.service.ingredient;

//import moja.refrigerator.aggregate.ingredient.IngredientCategory;
import moja.refrigerator.aggregate.ingredient.IngredientManagement;
//import moja.refrigerator.aggregate.ingredient.IngredientStorage;
import moja.refrigerator.dto.ingredient.request.IngredientCreateRequest;
//import moja.refrigerator.repository.ingredient.IngredientCategoryRepository;
import moja.refrigerator.repository.ingredient.IngredientManagementRepository;
//import moja.refrigerator.repository.ingredient.IngredientStorageRepository;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class IngredientServiceImpl implements IngredientService{

private IngredientManagementRepository ingredientManagementRepository;
// private IngredientStorageRepository ingredientStorageRepository;
// private IngredientCategoryRepository ingredientCategoryRepository;
private ModelMapper mapper;

@Autowired
public IngredientServiceImpl(IngredientManagementRepository ingredientManagementRepository,
// IngredientStorageRepository ingredientStorageRepository,
// IngredientCategoryRepository ingredientCategoryRepository,
ModelMapper mapper) {
this.ingredientManagementRepository = ingredientManagementRepository;
// this.ingredientStorageRepository = ingredientStorageRepository;
// this.ingredientCategoryRepository = ingredientCategoryRepository;
this.mapper = mapper;
}

@Override
@Transactional
public void createIngredient(IngredientCreateRequest request) {
IngredientManagement ingredient = mapper.map(request, IngredientManagement.class);

// IngredientCategory category = ingredientCategoryRepository.findById(request.getIngredientCategoryPk())
// .orElseThrow(() -> new IllegalArgumentException("카테고리를 찾을 수 없습니다."));
//
// IngredientStorage storage = ingredientStorageRepository.findById(request.getIngredientStoragePk())
// .orElseThrow(() -> new IllegalArgumentException("저장소를 찾을 수 없습니다."));
//
// ingredient.setIngredientCategory(category);
// ingredient.setIngredientStorage(storage);

ingredientManagementRepository.save(ingredient);
}
}