Skip to content

Commit

Permalink
feat: 재고 등록(#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinheekim committed Apr 10, 2024
1 parent bcdaba2 commit d56e2c6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing //추가
@SpringBootApplication
public class TastyInventoryBeApplication {

Expand Down
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import lombok.NoArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventoryVolume.InventoryVolume;
import net.skhu.tastyinventory_be.domain.recipe.Recipe;
import org.springframework.data.annotation.TypeAlias;

import java.util.HashSet;
import java.util.Set;

@Getter
@NoArgsConstructor
@Table(name = "Inventory")
@Table(name = "inventory")
@Entity
public class Inventory {
@Id
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/net/skhu/tastyinventory_be/dto/InventoryDto.java
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();
}
}
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();
}
}

0 comments on commit d56e2c6

Please sign in to comment.