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

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

8 changes: 8 additions & 0 deletions refrigerator/.idea/modules.xml

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

8 changes: 8 additions & 0 deletions refrigerator/.idea/modules/refrigerator.main.iml

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 @@ -34,7 +34,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// URL 별 접근 권한 설정
http
.authorizeHttpRequests((auth) -> auth
.requestMatchers("/login", "/", "/join").permitAll() // 이 경로들은 모두 접근 가능
.requestMatchers("/login", "/", "/join", "/ingredient").permitAll() // 이 경로들은 모두 접근 가능
.requestMatchers("/admin").hasRole("ADMIN") // admin 경로는 ADMIN 역할을 가진 사용자만
.anyRequest().authenticated()); // 나머지는 인증된 사용자만

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
import moja.refrigerator.dto.ingredient.request.IngredientCreateRequest;
import moja.refrigerator.dto.ingredient.request.IngredientUpdateRequest;
import moja.refrigerator.dto.ingredient.request.RequestRegistIngredientBookmark;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;
import moja.refrigerator.dto.ingredient.response.ResponseRegistIngredientBookmark;
import moja.refrigerator.service.ingredient.IngredientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;
import moja.refrigerator.service.ingredient.IngredientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -36,16 +30,6 @@ public void createIngredient(@RequestBody IngredientCreateRequest request) {
ingredientService.createIngredient(request);
}


@PostMapping("/bookmark/regist")
public ResponseEntity<ResponseRegistIngredientBookmark> createIngredientBookmark(
@RequestBody RequestRegistIngredientBookmark requestBookmark
) {
ResponseRegistIngredientBookmark responseBookmark =
ingredientService.createIngredientBookmark(requestBookmark);

return ResponseEntity.status(HttpStatus.CREATED).body(responseBookmark);

// 재료 조회
@GetMapping
public List<IngredientResponse> getIngredient() {
Expand All @@ -61,8 +45,18 @@ public void updateIngredient(@RequestBody IngredientUpdateRequest request) {

// 재료 삭제
@DeleteMapping
public void deleteIngredient(@RequestParam long ingredientManagementPK) {
ingredientService.deleteIngredient(ingredientManagementPK);
public void deleteIngredient(@RequestParam long ingredientManagementPk) {
ingredientService.deleteIngredient(ingredientManagementPk);
}

@PostMapping("/bookmark/regist")
public ResponseEntity<ResponseRegistIngredientBookmark> createIngredientBookmark(
@RequestBody RequestRegistIngredientBookmark requestBookmark
) {
ResponseRegistIngredientBookmark responseBookmark =
ingredientService.createIngredientBookmark(requestBookmark);

return ResponseEntity.status(HttpStatus.CREATED).body(responseBookmark);
}

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

import moja.refrigerator.dto.ingredient.request.IngredientCreateRequest;
import moja.refrigerator.dto.ingredient.request.IngredientUpdateRequest;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;
import moja.refrigerator.dto.ingredient.request.RequestRegistIngredientBookmark;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;
import moja.refrigerator.dto.ingredient.response.ResponseRegistIngredientBookmark;

import java.util.List;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;

public interface IngredientService {
// void createIngredient(IngredientCreateRequest request);
Expand All @@ -17,5 +17,5 @@ public interface IngredientService {

List<IngredientResponse> getIngredient(); // 재료 조회 메서드
void updateIngredient(IngredientUpdateRequest request);
void deleteIngredient(long ingredientManagementPK);
void deleteIngredient(long ingredientManagementPk);
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package moja.refrigerator.service.ingredient;

import jakarta.persistence.EntityNotFoundException;
import moja.refrigerator.aggregate.ingredient.IngredientBookmark;
import moja.refrigerator.aggregate.ingredient.IngredientCategory;
import moja.refrigerator.aggregate.ingredient.IngredientManagement;
import moja.refrigerator.aggregate.ingredient.IngredientStorage;
import moja.refrigerator.aggregate.user.User;
import moja.refrigerator.dto.ingredient.request.IngredientCreateRequest;
import moja.refrigerator.repository.ingredient.IngredientCategoryRepository;
import moja.refrigerator.dto.ingredient.request.IngredientUpdateRequest;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;
import moja.refrigerator.repository.ingredient.IngredientManagementRepository;
import moja.refrigerator.repository.ingredient.IngredientStorageRepository;
import jakarta.persistence.EntityNotFoundException;
import moja.refrigerator.aggregate.ingredient.IngredientBookmark;
import moja.refrigerator.aggregate.user.User;
import moja.refrigerator.dto.ingredient.request.RequestRegistIngredientBookmark;
import moja.refrigerator.dto.ingredient.response.IngredientResponse;
import moja.refrigerator.dto.ingredient.response.ResponseRegistIngredientBookmark;
import moja.refrigerator.repository.ingredient.IngredientBookmarkRepository;
import moja.refrigerator.repository.ingredient.IngredientCategoryRepository;
import moja.refrigerator.repository.ingredient.IngredientManagementRepository;
import moja.refrigerator.repository.ingredient.IngredientStorageRepository;
import moja.refrigerator.repository.user.UserRepository;

import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -69,28 +68,6 @@ public void createIngredient(IngredientCreateRequest request) {
ingredientManagementRepository.save(ingredient);
}

@Override

public ResponseRegistIngredientBookmark createIngredientBookmark(RequestRegistIngredientBookmark requestBookmark) {
User user = userRepository.findById(requestBookmark.getUserPk())
.orElseThrow(() -> new EntityNotFoundException("회원을 찾을 수 없습니다."));

IngredientManagement ingredientManagement = ingredientManagementRepository
.findById(requestBookmark.getIngredientPk())
.orElseThrow(() -> new EntityNotFoundException("재료를 찾을 수 없습니다."));

IngredientBookmark ingredientBookmark = new IngredientBookmark();

ingredientBookmark.setUser(user);
ingredientBookmark.setIngredientManagement(ingredientManagement);

ingredientBookmarkRepository.save(ingredientBookmark);

mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);

return mapper.map(ingredientBookmark, ResponseRegistIngredientBookmark.class);
}

@Transactional(readOnly = true)
public List<IngredientResponse> getIngredient() {
List<IngredientManagement> ingredients = ingredientManagementRepository.findAll();
Expand Down Expand Up @@ -128,12 +105,34 @@ public void updateIngredient(IngredientUpdateRequest request) {

@Override
@Transactional
public void deleteIngredient(long ingredientManagementPK) {
public void deleteIngredient(long ingredientManagementPk) {
IngredientManagement ingredient = ingredientManagementRepository
.findById(ingredientManagementPK)
.findById(ingredientManagementPk)
.orElseThrow(() -> new IllegalArgumentException("삭제할 재료를 찾을 수 없습니다."));

ingredientManagementRepository.delete(ingredient);
}

@Override
public ResponseRegistIngredientBookmark createIngredientBookmark(RequestRegistIngredientBookmark requestBookmark) {
User user = userRepository.findById(requestBookmark.getUserPk())
.orElseThrow(() -> new EntityNotFoundException("회원을 찾을 수 없습니다."));

IngredientManagement ingredientManagement = ingredientManagementRepository
.findById(requestBookmark.getIngredientPk())
.orElseThrow(() -> new EntityNotFoundException("재료를 찾을 수 없습니다."));

IngredientBookmark ingredientBookmark = new IngredientBookmark();

ingredientBookmark.setUser(user);
ingredientBookmark.setIngredientManagement(ingredientManagement);

ingredientBookmarkRepository.save(ingredientBookmark);

mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);

return mapper.map(ingredientBookmark, ResponseRegistIngredientBookmark.class);
}


}