Skip to content

Commit

Permalink
Merge pull request #141 from Link-MIND/test
Browse files Browse the repository at this point in the history
[Merge] delete category merge
  • Loading branch information
sss4920 committed Jan 17, 2024
2 parents d491ba2 + 7156d48 commit 7d7ff7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.app.toaster.service.category.CategoryService;
import com.app.toaster.service.search.SearchService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
Expand All @@ -41,7 +43,7 @@ public ApiResponse createCateory(
@ResponseStatus(HttpStatus.OK)
public ApiResponse deleteCategory(
@UserId Long userId,
@RequestBody DeleteCategoryDto deleteCategoryDto
@NotNull @RequestParam(value = "deleteCategoryDto") ArrayList<Long> deleteCategoryDto
){
categoryService.deleteCategory(deleteCategoryDto);
return ApiResponse.success(Success.DELETE_CATEGORY_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.app.toaster.domain.Toast;
import com.app.toaster.domain.User;
import com.app.toaster.exception.Error;
import com.app.toaster.exception.model.BadRequestException;
import com.app.toaster.exception.model.CustomException;
import com.app.toaster.exception.model.NotFoundException;
import com.app.toaster.infrastructure.CategoryRepository;
Expand Down Expand Up @@ -63,11 +64,14 @@ public void createCategory(final Long userId, final CreateCategoryDto createCate
}

@Transactional
public void deleteCategory(final DeleteCategoryDto deleteCategoryDto){
public void deleteCategory(final ArrayList<Long> deleteCategoryDto){
if(deleteCategoryDto.isEmpty()){
throw new BadRequestException(Error.BAD_REQUEST_VALIDATION, Error.BAD_REQUEST_VALIDATION.getMessage());
}

toastRepository.updateCategoryIdsToNull(deleteCategoryDto.deleteCategoryList());
toastRepository.updateCategoryIdsToNull(deleteCategoryDto);

for (Long categoryId : deleteCategoryDto.deleteCategoryList()) {
for (Long categoryId : deleteCategoryDto) {
Category category = categoryRepository.findById(categoryId)
.orElseThrow(() -> new NotFoundException(Error.NOT_FOUND_CATEGORY_EXCEPTION, Error.NOT_FOUND_CATEGORY_EXCEPTION.getMessage()));

Expand Down

0 comments on commit 7d7ff7e

Please sign in to comment.