Skip to content

Commit

Permalink
create total_price (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
woals00 authored Jan 27, 2023
1 parent b792d7f commit 97458a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/noriton/team9/domain/Item.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.noriton.team9.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -29,6 +30,7 @@ public class Item {
private int count;

@OneToMany(mappedBy = "item")
@JsonIgnore(value = false)
private List<Orders> fundingList = new ArrayList<>();
public void removeStockQuantity(int count) {
int resStock = this.stockQuantity - count;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/noriton/team9/domain/Orders.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.noriton.team9.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -29,6 +30,7 @@ public class Orders {

@ManyToOne
@JoinColumn(name = "item_id")
@JsonIgnore
private Item item;
private LocalDateTime orderDate;

Expand All @@ -38,6 +40,7 @@ public class Orders {

@ManyToOne
@JoinColumn(name = "member_id")
@JsonIgnore
private Member member;

private String fundStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
@Data
public class ItemCreationRequest {
private String name;
private int price;
private Long sampleId;
private int laborCost;
private int materialCost;

private Long sampleId;
private int stockQuantity;
}
6 changes: 4 additions & 2 deletions src/main/java/com/noriton/team9/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public Item createItem(ItemCreationRequest item) {
}
Item itemToCreate = new Item();
BeanUtils.copyProperties(item, itemToCreate);
int totalCost = (item.getLaborCost() + item.getMaterialCost());
itemToCreate.setPrice(totalCost);
itemToCreate.setCount(0);
itemToCreate.setSample(sample.get());
return itemRepository.save(itemToCreate);
Expand All @@ -65,10 +67,10 @@ public Item updateItem(Long itemId, ItemCreationRequest request){
if(!getItem.isPresent()){
throw new EntityNotFoundException("Item is not present in the database");
}

Item item = getItem.get();
item.setName(request.getName());
item.setPrice(request.getPrice());
int totalPrice = (request.getLaborCost() + request.getMaterialCost());
item.setPrice(totalPrice);
item.setStockQuantity(request.getStockQuantity());
Optional<Sample> getSample = sampleRepository.findById(request.getSampleId());
if(getSample.isPresent()){
Expand Down

0 comments on commit 97458a8

Please sign in to comment.