Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
Orders
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Vladimir Trubachoff
Orders
Commits
592e3a75
Commit
592e3a75
authored
Jun 28, 2024
by
Vladimir Trubachoff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix order-line api
parent
10e22f38
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
105 additions
and
34 deletions
+105
-34
Goods.java
src/main/java/com/example/testj/domain/Goods.java
+8
-16
Order.java
src/main/java/com/example/testj/domain/Order.java
+0
-2
OrderLineService.java
...main/java/com/example/testj/service/OrderLineService.java
+25
-3
GoodsDto.java
src/main/java/com/example/testj/service/dto/GoodsDto.java
+4
-4
OrderLineRequestDto.java
...va/com/example/testj/service/dto/OrderLineRequestDto.java
+31
-0
MappingUtils.java
src/main/java/com/example/testj/utils/MappingUtils.java
+2
-0
OrderLineController.java
.../java/com/example/testj/web/rest/OrderLineController.java
+18
-5
add-product-modal.component.html
...onents/add-product-modal/add-product-modal.component.html
+6
-1
order-page.component.html
...webapp/src/app/pages/order-page/order-page.component.html
+1
-1
order-page.component.ts
...n/webapp/src/app/pages/order-page/order-page.component.ts
+10
-2
No files found.
src/main/java/com/example/testj/domain/Goods.java
View file @
592e3a75
package
com
.
example
.
testj
.
domain
;
package
com
.
example
.
testj
.
domain
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
com.example.testj.service.dto.GoodsDto
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
jakarta.persistence.CascadeType
;
import
jakarta.persistence.Column
;
import
jakarta.persistence.Column
;
import
jakarta.persistence.Entity
;
import
jakarta.persistence.Entity
;
import
jakarta.persistence.GeneratedValue
;
import
jakarta.persistence.GeneratedValue
;
import
jakarta.persistence.Id
;
import
jakarta.persistence.Id
;
import
jakarta.persistence.OneToMany
;
import
jakarta.persistence.Table
;
import
jakarta.persistence.Table
;
import
jakarta.validation.constraints.Digits
;
import
jakarta.validation.constraints.NotEmpty
;
import
jakarta.validation.constraints.NotEmpty
;
@Entity
@Entity
...
@@ -30,16 +21,17 @@ public class Goods {
...
@@ -30,16 +21,17 @@ public class Goods {
@NotEmpty
@NotEmpty
@Column
(
name
=
"price"
)
@Column
(
name
=
"price"
)
private
BigDecimal
price
;
private
double
price
;
// @JsonIgnore
// @JsonIgnore
// @OneToMany(mappedBy= "goods", cascade = CascadeType.ALL, orphanRemoval = true)
// @OneToMany(mappedBy= "goods", cascade = CascadeType.ALL, orphanRemoval =
// true)
// private List<OrderLine> orderLine;
// private List<OrderLine> orderLine;
public
Goods
()
{
public
Goods
()
{
}
}
public
Goods
(
Long
id
,
String
name
,
BigDecimal
price
)
{
public
Goods
(
Long
id
,
String
name
,
Double
price
)
{
this
.
id
=
id
;
this
.
id
=
id
;
this
.
name
=
name
;
this
.
name
=
name
;
this
.
price
=
price
;
this
.
price
=
price
;
...
@@ -66,19 +58,19 @@ public class Goods {
...
@@ -66,19 +58,19 @@ public class Goods {
this
.
name
=
name
;
this
.
name
=
name
;
}
}
public
BigDecimal
getPrice
()
{
public
Double
getPrice
()
{
return
price
;
return
price
;
}
}
public
void
setPrice
(
BigDecimal
price
)
{
public
void
setPrice
(
Double
price
)
{
this
.
price
=
price
;
this
.
price
=
price
;
}
}
// public List<OrderLine> getOrderLine() {
// public List<OrderLine> getOrderLine() {
//
return orderLine;
// return orderLine;
// }
// }
// public void setOrderLine(List<OrderLine> orderLine) {
// public void setOrderLine(List<OrderLine> orderLine) {
//
this.orderLine = orderLine;
// this.orderLine = orderLine;
// }
// }
}
}
src/main/java/com/example/testj/domain/Order.java
View file @
592e3a75
...
@@ -4,8 +4,6 @@ import java.util.List;
...
@@ -4,8 +4,6 @@ import java.util.List;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
com.fasterxml.jackson.annotation.JsonManagedReference
;
import
jakarta.persistence.CascadeType
;
import
jakarta.persistence.CascadeType
;
import
jakarta.persistence.Column
;
import
jakarta.persistence.Column
;
import
jakarta.persistence.Entity
;
import
jakarta.persistence.Entity
;
...
...
src/main/java/com/example/testj/service/OrderLineService.java
View file @
592e3a75
...
@@ -5,25 +5,47 @@ import org.springframework.stereotype.Service;
...
@@ -5,25 +5,47 @@ import org.springframework.stereotype.Service;
import
com.example.testj.domain.OrderLine
;
import
com.example.testj.domain.OrderLine
;
import
com.example.testj.exception.ResourceNotFoundException
;
import
com.example.testj.exception.ResourceNotFoundException
;
import
com.example.testj.repository.OrderLineRepository
;
import
com.example.testj.repository.OrderLineRepository
;
import
com.example.testj.service.dto.GoodsDto
;
import
com.example.testj.service.dto.OrderDto
;
import
com.example.testj.service.dto.OrderLineDto
;
import
com.example.testj.service.dto.OrderLineDto
;
import
com.example.testj.service.dto.OrderLineRequestDto
;
import
com.example.testj.utils.MappingUtils
;
import
com.example.testj.utils.MappingUtils
;
@Service
@Service
public
class
OrderLineService
{
public
class
OrderLineService
{
private
final
MappingUtils
mappingUtils
;
private
final
MappingUtils
mappingUtils
;
private
final
OrderLineRepository
orderLineRepository
;
private
final
OrderLineRepository
orderLineRepository
;
private
final
OrderService
orderService
;
private
final
GoodsService
goodsService
;
public
OrderLineService
(
OrderLineRepository
orderLineRepository
,
MappingUtils
mappingUtils
)
{
public
OrderLineService
(
OrderLineRepository
orderLineRepository
,
MappingUtils
mappingUtils
,
OrderService
orderService
,
GoodsService
goodsService
)
{
this
.
orderLineRepository
=
orderLineRepository
;
this
.
orderLineRepository
=
orderLineRepository
;
this
.
mappingUtils
=
mappingUtils
;
this
.
mappingUtils
=
mappingUtils
;
this
.
orderService
=
orderService
;
this
.
goodsService
=
goodsService
;
}
}
public
OrderLineDto
createOrUpdateOrderLine
(
OrderLine
orderLine
)
{
public
OrderLineDto
createOrderLine
(
OrderLineRequestDto
orderLineRequest
)
{
OrderDto
order
=
orderService
.
getOrder
(
orderLineRequest
.
getOrderId
());
GoodsDto
goods
=
goodsService
.
getGoods
(
orderLineRequest
.
getGoodsId
());
OrderLine
orderLine
=
new
OrderLine
();
orderLine
.
setOrder
(
mappingUtils
.
toOrder
(
order
));
orderLine
.
setGoods
(
mappingUtils
.
toGoods
(
goods
));
orderLine
.
setCount
(
orderLineRequest
.
getCount
());
return
mappingUtils
.
toOrderLineDto
(
orderLineRepository
.
save
(
orderLine
));
return
mappingUtils
.
toOrderLineDto
(
orderLineRepository
.
save
(
orderLine
));
}
}
public
OrderLineDto
updateOrderLine
(
OrderLine
orderLine
,
Long
id
)
{
OrderLine
updatedOrderLine
=
orderLineRepository
.
findById
(
id
).
orElseThrow
(
ResourceNotFoundException:
:
new
);
updatedOrderLine
.
setCount
(
orderLine
.
getCount
());
return
mappingUtils
.
toOrderLineDto
(
orderLineRepository
.
save
(
updatedOrderLine
));
}
public
OrderLineDto
getOrderLine
(
Long
id
)
throws
ResourceNotFoundException
{
public
OrderLineDto
getOrderLine
(
Long
id
)
throws
ResourceNotFoundException
{
return
mappingUtils
.
toOrderLineDto
(
orderLineRepository
.
findById
(
id
).
orElseThrow
(
ResourceNotFoundException:
:
new
));
return
mappingUtils
.
toOrderLineDto
(
orderLineRepository
.
findById
(
id
).
orElseThrow
(
ResourceNotFoundException:
:
new
));
}
}
public
void
deleteOrderLine
(
Long
id
)
{
public
void
deleteOrderLine
(
Long
id
)
{
...
...
src/main/java/com/example/testj/service/dto/GoodsDto.java
View file @
592e3a75
package
com
.
example
.
testj
.
service
.
dto
;
package
com
.
example
.
testj
.
service
.
dto
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
com.example.testj.domain.Goods
;
import
com.example.testj.domain.Goods
;
...
@@ -11,7 +10,7 @@ import com.example.testj.domain.Goods;
...
@@ -11,7 +10,7 @@ import com.example.testj.domain.Goods;
public
class
GoodsDto
implements
Serializable
{
public
class
GoodsDto
implements
Serializable
{
private
Long
id
;
private
Long
id
;
private
String
name
;
private
String
name
;
private
BigDecimal
price
;
private
double
price
;
public
GoodsDto
()
{
public
GoodsDto
()
{
}
}
...
@@ -38,11 +37,11 @@ public class GoodsDto implements Serializable {
...
@@ -38,11 +37,11 @@ public class GoodsDto implements Serializable {
this
.
name
=
name
;
this
.
name
=
name
;
}
}
public
BigDecimal
getPrice
()
{
public
double
getPrice
()
{
return
price
;
return
price
;
}
}
public
void
setPrice
(
BigDecimal
price
)
{
public
void
setPrice
(
double
price
)
{
this
.
price
=
price
;
this
.
price
=
price
;
}
}
}
}
\ No newline at end of file
src/main/java/com/example/testj/service/dto/OrderLineRequestDto.java
0 → 100644
View file @
592e3a75
package
com
.
example
.
testj
.
service
.
dto
;
public
class
OrderLineRequestDto
{
private
Long
order_id
;
private
Long
goods_id
;
private
int
count
;
public
Long
getOrderId
()
{
return
order_id
;
}
public
void
setOrderId
(
Long
orderId
)
{
order_id
=
orderId
;
}
public
Long
getGoodsId
()
{
return
goods_id
;
}
public
void
setGoodsId
(
Long
goodsId
)
{
goods_id
=
goodsId
;
}
public
int
getCount
()
{
return
count
;
}
public
void
setCount
(
int
count
)
{
this
.
count
=
count
;
}
}
src/main/java/com/example/testj/utils/MappingUtils.java
View file @
592e3a75
...
@@ -31,6 +31,8 @@ public class MappingUtils {
...
@@ -31,6 +31,8 @@ public class MappingUtils {
public
OrderLine
toOrderLine
(
OrderLineDto
orderLineDto
)
{
public
OrderLine
toOrderLine
(
OrderLineDto
orderLineDto
)
{
OrderLine
orderLine
=
new
OrderLine
();
OrderLine
orderLine
=
new
OrderLine
();
orderLine
.
setGoods
(
orderLineDto
.
getGoods
());
orderLine
.
setOrder
(
orderLineDto
.
getOrder
());
orderLine
.
setCount
(
orderLineDto
.
getCount
());
orderLine
.
setCount
(
orderLineDto
.
getCount
());
return
orderLine
;
return
orderLine
;
}
}
...
...
src/main/java/com/example/testj/web/rest/OrderLineController.java
View file @
592e3a75
package
com
.
example
.
testj
.
web
.
rest
;
package
com
.
example
.
testj
.
web
.
rest
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
@@ -9,8 +12,10 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -9,8 +12,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.example.testj.exception.ResourceNotFoundException
;
import
com.example.testj.service.OrderLineService
;
import
com.example.testj.service.OrderLineService
;
import
com.example.testj.service.dto.OrderLineDto
;
import
com.example.testj.service.dto.OrderLineDto
;
import
com.example.testj.service.dto.OrderLineRequestDto
;
import
com.example.testj.utils.MappingUtils
;
import
com.example.testj.utils.MappingUtils
;
import
jakarta.validation.Valid
;
import
jakarta.validation.Valid
;
...
@@ -33,15 +38,23 @@ public class OrderLineController {
...
@@ -33,15 +38,23 @@ public class OrderLineController {
}
}
@PostMapping
@PostMapping
public
OrderLineDto
create
Order
(
@Valid
@RequestBody
OrderLineDto
orderLine
)
{
public
OrderLineDto
create
(
@Valid
@RequestBody
OrderLineRequestDto
orderLineRequest
)
{
return
orderLineService
.
createOr
UpdateOrderLine
(
mappingUtils
.
toOrderLine
(
orderLine
)
);
return
orderLineService
.
createOr
derLine
(
orderLineRequest
);
}
}
@PutMapping
(
"/{id}"
)
@PutMapping
(
"/{id}"
)
public
OrderLineDto
updateOrder
(
@PathVariable
Long
id
,
@Valid
@RequestBody
OrderLineDto
orderLine
)
{
public
OrderLineDto
updateOrder
(
@PathVariable
Long
id
,
@Valid
@RequestBody
OrderLineDto
orderLine
)
{
OrderLineDto
updateOrderLine
=
orderLineService
.
getOrderLine
(
id
);
return
orderLineService
.
updateOrderLine
(
mappingUtils
.
toOrderLine
(
orderLine
),
id
);
updateOrderLine
.
setCount
(
orderLine
.
getCount
());
}
return
orderLineService
.
createOrUpdateOrderLine
(
mappingUtils
.
toOrderLine
(
updateOrderLine
));
@DeleteMapping
(
"/{id}"
)
public
ResponseEntity
<
HttpStatus
>
delete
(
@PathVariable
Long
id
)
throws
ResourceNotFoundException
{
try
{
orderLineService
.
deleteOrderLine
(
id
);
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
catch
(
ResourceNotFoundException
e
)
{
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_FOUND
);
}
}
}
}
}
src/main/webapp/src/app/pages/order-page/components/add-product-modal/add-product-modal.component.html
View file @
592e3a75
<div
class=
"modal-header"
>
<div
class=
"modal-header"
>
<h4
class=
"modal-title"
id=
"modal-basic-title"
>
Add product
</h4>
<h4
class=
"modal-title"
id=
"modal-basic-title"
>
Edit products
</h4>
<button
<button
type=
"button"
type=
"button"
class=
"btn-close"
class=
"btn-close"
...
@@ -64,3 +64,8 @@
...
@@ -64,3 +64,8 @@
}
}
<ng-template
#
loading
>
loading...
</ng-template>
<ng-template
#
loading
>
loading...
</ng-template>
</div>
</div>
<div
class=
"modal-footer"
>
<button
class=
"btn btn-outline-secondary"
(
click
)="
modal
?.
close
()"
>
Close
</button>
</div>
src/main/webapp/src/app/pages/order-page/order-page.component.html
View file @
592e3a75
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
class=
"btn btn-outline-secondary me-2"
class=
"btn btn-outline-secondary me-2"
(
click
)="
openAddProductModal
()"
(
click
)="
openAddProductModal
()"
>
>
Add
products
Edit
products
</button>
</button>
</div>
</div>
...
...
src/main/webapp/src/app/pages/order-page/order-page.component.ts
View file @
592e3a75
...
@@ -97,6 +97,7 @@ export class OrderPageComponent
...
@@ -97,6 +97,7 @@ export class OrderPageComponent
orderModalRef
.
componentInstance
.
orderLineChange
orderModalRef
.
componentInstance
.
orderLineChange
.
pipe
(
.
pipe
(
takeUntil
(
this
.
destroy$
),
concatMap
((
v
:
UpdateCount
)
=>
{
concatMap
((
v
:
UpdateCount
)
=>
{
const
orderLineId
=
this
.
order
.
orderLines
.
find
(
const
orderLineId
=
this
.
order
.
orderLines
.
find
(
(
ol
)
=>
ol
.
goods
.
id
===
v
.
goods_id
,
(
ol
)
=>
ol
.
goods
.
id
===
v
.
goods_id
,
...
@@ -116,8 +117,15 @@ export class OrderPageComponent
...
@@ -116,8 +117,15 @@ export class OrderPageComponent
});
});
}),
}),
)
)
.
subscribe
((
resp
:
any
)
=>
{
.
subscribe
({
console
.
dir
(
resp
);
next
:
(
res
:
any
)
=>
{
this
.
getData
(
this
.
order
.
id
);
},
error
:
(
err
:
any
)
=>
{
if
(
DEV
)
{
console
.
dir
(
`Error:
${
err
}
`
);
}
},
});
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment