-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcdaba2
commit d56e2c6
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
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
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 net.skhu.tastyinventory_be.controller.inventory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import net.skhu.tastyinventory_be.dto.InventoryDto; | ||
import net.skhu.tastyinventory_be.service.Inventory.InventoryService; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/inventory") | ||
public class InventoryController { | ||
|
||
private final InventoryService inventoryService; | ||
|
||
@PostMapping("/") | ||
public Long save(@RequestBody InventoryDto requestDto){ | ||
return inventoryService.save(requestDto); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/net/skhu/tastyinventory_be/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 |
---|---|---|
@@ -1,4 +1,31 @@ | ||
package net.skhu.tastyinventory_be.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import net.skhu.tastyinventory_be.domain.inventory.Inventory; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class InventoryDto { | ||
private Long id; | ||
private String name; | ||
private String unit; | ||
private String imageUrl; | ||
|
||
@Builder | ||
public InventoryDto(String name, String unit, String imageUrl) { | ||
this.name = name; | ||
this.unit = unit; | ||
this.imageUrl = imageUrl; | ||
} | ||
public Inventory toEntity(){ | ||
return Inventory.builder() | ||
.name(name) | ||
.unit(unit) | ||
.imageUrl(imageUrl) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/net/skhu/tastyinventory_be/service/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 |
---|---|---|
@@ -1,5 +1,19 @@ | ||
package net.skhu.tastyinventory_be.service.Inventory; | ||
|
||
import jakarta.transaction.Transactional; | ||
import net.skhu.tastyinventory_be.domain.inventory.InventoryRepository; | ||
import net.skhu.tastyinventory_be.dto.InventoryDto; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
// 엔티티를 처리하는 비즈니스 로직, ex 재고 업데이트, 평균 사용량 계산 등 | ||
@Service | ||
public class InventoryService { | ||
@Autowired | ||
private InventoryRepository inventoryRepository; | ||
|
||
@Transactional | ||
public Long save(InventoryDto requestDto){ | ||
return inventoryRepository.save(requestDto.toEntity()).getId(); | ||
} | ||
} |