Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main.spring.login.demo2.controller;

import main.spring.login.demo2.entity.CStorage;
import main.spring.login.demo2.service.CStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/cstorage")
public class CStorageController {

private final CStorageService cStorageService;

@Autowired
public CStorageController(CStorageService cStorageService) {
this.cStorageService = cStorageService;
}

@PostMapping("/addOrUpdate")
public CStorage addOrUpdateCStorage(@RequestBody CStorage cStorage) {
return cStorageService.addOrUpdateCStorage(cStorage.getCustomerCode(), cStorage.getStorageCode());
}

@DeleteMapping("/delete/{customerCode}/{storageCode}")
public ResponseEntity<?> deleteCStorage(@PathVariable String customerCode, @PathVariable String storageCode) {
boolean isDeleted = cStorageService.deleteCStorage(customerCode, storageCode);

if (isDeleted) {
// 성공적으로 삭제되었다면, HTTP 200 OK 응답을 리턴
return ResponseEntity.ok().build();
} else {
// 삭제에 실패했다면, HTTP 404 Not Found 또는 다른 적절한 에러 응답을 리턴
return ResponseEntity.notFound().build();
}
}

@GetMapping("/list")
public List<CStorage> getAllCStorages() {
return cStorageService.findAllCStorages();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main.spring.login.demo2.controller;

import main.spring.login.demo2.entity.Inventory;
import main.spring.login.demo2.dto.InventoryDTO;
import main.spring.login.demo2.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,19 +22,18 @@ public InventoryController(InventoryService inventoryService) {
}

@GetMapping
public List<Inventory> getAllInventories() {
public List<InventoryDTO> getAllInventories() {
return inventoryService.findAll();
}



// @GetMapping("/read/{storageCode}")
// public List<Inventory> findByStorageCode(@PathVariable String storageCode) {
// return inventoryService.findByStorageCode(storageCode);
// }

@GetMapping("/read/{storageCode}")
public List<Inventory> findByStorageCode(@PathVariable String storageCode) {
public List<InventoryDTO> findByStorageCode(@PathVariable String storageCode) {
return inventoryService.findByStorageCode(storageCode);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main.spring.login.demo2.dto;

import lombok.Data;

@Data
public class GradePriceInfo {
private String goodsCode;
private String goodsGrade;
private int inputStock;

public GradePriceInfo(String goodsCode, String goodsGrade, int inputStock) {
this.goodsCode = goodsCode;
this.goodsGrade = goodsGrade;
this.inputStock = inputStock;
}

}
19 changes: 19 additions & 0 deletions demo2/src/main/java/main/spring/login/demo2/dto/InventoryDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main.spring.login.demo2.dto;

import lombok.Data;

import java.time.LocalDateTime;

@Data
public class InventoryDTO {
private LocalDateTime firstStockDate;
private String goodsCode;
private String goodsGrade;
private String inventoryQuantity;
private int salesPrice;
private LocalDateTime gradeEvaluationDates;
private String storageCode;
private String goodsName; // GoodsMaster로부터 가져온 상품 이름

// 생성자, Getter 및 Setter 생략
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@NoArgsConstructor
@Data
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@IdClass(CStorageId.class) // 복합 키 클래스를 지정
public class CStorage {
@Id
@Column(name = "storage_code")
Expand Down
19 changes: 19 additions & 0 deletions demo2/src/main/java/main/spring/login/demo2/entity/CStorageId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main.spring.login.demo2.entity;

import java.io.Serializable;

public class CStorageId implements Serializable {
private String storageCode;
private String customerCode;

// 기본 생성자
public CStorageId() {
}

// 모든 필드를 포함하는 생성자
public CStorageId(String storageCode, String customerCode) {
this.storageCode = storageCode;
this.customerCode = customerCode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@IdClass(GradePriceId.class)
public class GradePrice {
@Id
@Column(name = "goods_grade", length = 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main.spring.login.demo2.entity;

import java.io.Serializable;

public class GradePriceId implements Serializable {
private String goodsGrade;
private String goodsCode;
}
22 changes: 15 additions & 7 deletions demo2/src/main/java/main/spring/login/demo2/entity/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ public class Inventory {
@JoinColumn(name = "storage_code", referencedColumnName = "contact_code", insertable = false, updatable = false)
private Contact contact;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "goods_code", referencedColumnName = "goods_code", insertable = false, updatable = false)
private GradePrice gradePriceC;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "goods_grade", referencedColumnName = "goods_grade", insertable = false, updatable = false)
private GradePrice gradePriceG;
// @OneToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "goods_code", referencedColumnName = "goods_code", insertable = false, updatable = false)
// private GradePrice gradePriceC;
//
// @OneToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "goods_grade", referencedColumnName = "goods_grade", insertable = false, updatable = false)
// private GradePrice gradePriceG;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "goods_code", referencedColumnName = "goods_code", insertable = false, updatable = false),
@JoinColumn(name = "goods_grade", referencedColumnName = "goods_grade", insertable = false, updatable = false)
})
private GradePrice gradePrice;
// Getters and Setters
// test

Expand All @@ -69,4 +75,6 @@ public static class InventoryId implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "goods_code", referencedColumnName = "goods_code", insertable = false, updatable = false)
private GoodsMaster goodsMaster;


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main.spring.login.demo2.repository;

import main.spring.login.demo2.entity.CStorage;
import main.spring.login.demo2.entity.CStorageId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CStorageRepository extends JpaRepository<CStorage, CStorageId> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

public interface InventoryRepository extends JpaRepository<Inventory, InventoryId> {
List<Inventory> findByStorageCode(String storageCode);
// 추가적으로 필요한 쿼리 메소드를 정의할 수 있습니다.


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main.spring.login.demo2.service;

import main.spring.login.demo2.entity.CStorage;
import main.spring.login.demo2.entity.CStorageId;
import main.spring.login.demo2.repository.CStorageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class CStorageService {

private final CStorageRepository cStorageRepository;

@Autowired
public CStorageService(CStorageRepository cStorageRepository) {
this.cStorageRepository = cStorageRepository;
}

public CStorage addOrUpdateCStorage(String customerCode, String storageCode) {
CStorage cStorage = new CStorage();
cStorage.setCustomerCode(customerCode);
cStorage.setStorageCode(storageCode);
return cStorageRepository.save(cStorage);
}

public List<CStorage> findAllCStorages() {
return cStorageRepository.findAll();
}

// 거래처의 창고 코드 삭제 로직
public boolean deleteCStorage(String customerCode, String storageCode) {
CStorageId id = new CStorageId(storageCode, customerCode);
Optional<CStorage> cStorage = cStorageRepository.findById(id);

if (cStorage.isPresent()) {
cStorageRepository.delete(cStorage.get()); // 엔티티가 존재하면 삭제
return true;
} else {
return false; // 해당하는 CStorage가 없는 경우
}
}

}
Loading