Skip to content

Commit

Permalink
Merge pull request #8 from 1223v/userdelete
Browse files Browse the repository at this point in the history
Feat: 재고관리 기능 추가
  • Loading branch information
1223v authored Nov 25, 2023
2 parents 2ed6cd6 + 6083d7b commit 96f7c5b
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.readyvery.readyverydemo.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.readyvery.readyverydemo.domain.Foodie;

public interface InventoryRepository extends JpaRepository<Foodie, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.readyvery.readyverydemo.src.inventory;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.readyvery.readyverydemo.security.jwt.dto.CustomUserDetails;
import com.readyvery.readyverydemo.src.inventory.dto.InventoryStockRes;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class InventoryController {

private final InventoryService inventoryServiceImpl;

@GetMapping("/inventory")
public InventoryStockRes getInventorys(@AuthenticationPrincipal CustomUserDetails userDetails) {
return inventoryServiceImpl.getInventorys(userDetails.getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.readyvery.readyverydemo.src.inventory;

import com.readyvery.readyverydemo.src.inventory.dto.InventoryStockRes;

public interface InventoryService {
InventoryStockRes getInventorys(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.readyvery.readyverydemo.src.inventory;

import java.util.List;

import org.springframework.stereotype.Service;

import com.readyvery.readyverydemo.domain.CeoInfo;
import com.readyvery.readyverydemo.domain.FoodieCategory;
import com.readyvery.readyverydemo.domain.repository.CeoRepository;
import com.readyvery.readyverydemo.global.exception.BusinessLogicException;
import com.readyvery.readyverydemo.global.exception.ExceptionCode;
import com.readyvery.readyverydemo.src.inventory.dto.InventoryMapper;
import com.readyvery.readyverydemo.src.inventory.dto.InventoryStockRes;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Log4j2
@Service
@RequiredArgsConstructor
public class InventoryServiceImpl implements InventoryService {

private final CeoRepository ceoRepository;
private final InventoryMapper inventoryMapper;

@Override
public InventoryStockRes getInventorys(Long id) {
CeoInfo ceoInfo = getCeoInfo(id);
List<FoodieCategory> foodieCategories = ceoInfo.getStore().getFoodieCategories();

return inventoryMapper.foodiesToInventoryStockRes(foodieCategories);
}

private CeoInfo getCeoInfo(Long id) {
return ceoRepository.findById(id).orElseThrow(
() -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.readyvery.readyverydemo.src.inventory.dto;

import java.util.List;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class InventoryDto {
private String name;
private List<InventoryStockDto> foodies;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.readyvery.readyverydemo.src.inventory.dto;

import java.util.List;

import org.springframework.stereotype.Component;

import com.readyvery.readyverydemo.domain.Foodie;
import com.readyvery.readyverydemo.domain.FoodieCategory;

@Component
public class InventoryMapper {

public InventoryStockRes foodiesToInventoryStockRes(List<FoodieCategory> foodieCategories) {
if (foodieCategories.isEmpty()) {
return InventoryStockRes.builder()
.categorys(null)
.build();
}

return InventoryStockRes.builder()
.categorys(foodieCategories.stream().map(this::toInventoryDto).toList())
.build();
}

private InventoryDto toInventoryDto(FoodieCategory foodieCategories) {
return InventoryDto.builder()
.name(foodieCategories.getName())
.foodies(foodieCategories.getFoodies().stream().map(this::toInventoryStockDto).toList())
.build();
}

private InventoryStockDto toInventoryStockDto(Foodie foodie) {
return InventoryStockDto.builder()
.idx(foodie.getId())
.name(foodie.getName())
.isSoldOut(foodie.isSoldOut())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.readyvery.readyverydemo.src.inventory.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class InventoryStockDto {

private Long idx;
private String name;
private boolean isSoldOut;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.readyvery.readyverydemo.src.inventory.dto;

import java.util.List;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class InventoryStockRes {
List<InventoryDto> categorys;
}

0 comments on commit 96f7c5b

Please sign in to comment.