-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from 1223v/userdelete
Feat: 재고관리 기능 추가
- Loading branch information
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/com/readyvery/readyverydemo/domain/repository/InventoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/readyvery/readyverydemo/src/inventory/InventoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/readyvery/readyverydemo/src/inventory/InventoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/readyvery/readyverydemo/src/inventory/InventoryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/readyvery/readyverydemo/src/inventory/dto/InventoryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/readyvery/readyverydemo/src/inventory/dto/InventoryMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/readyvery/readyverydemo/src/inventory/dto/InventoryStockDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/readyvery/readyverydemo/src/inventory/dto/InventoryStockRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |