Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
Overview
Overview
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
javab_20230617
Commits
1ec6407a
Commit
1ec6407a
authored
Jul 30, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REST dla klasy Order
parent
0d04f0ab
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
0 deletions
+101
-0
a.json
PC27-SklepSpring/a.json
+49
-0
Customer.java
PC27-SklepSpring/src/main/java/sklep/model/Customer.java
+3
-0
OrderProduct.java
PC27-SklepSpring/src/main/java/sklep/model/OrderProduct.java
+3
-0
OrderRepository.java
...pring/src/main/java/sklep/repository/OrderRepository.java
+8
-0
OrderEndpoint.java
PC27-SklepSpring/src/main/java/sklep/rest/OrderEndpoint.java
+38
-0
No files found.
PC27-SklepSpring/a.json
0 → 100644
View file @
1ec6407a
{
"orderId"
:
1
,
"deliveryDate"
:
null
,
"orderDate"
:
"2021-11-20T11:30:00.000+00:00"
,
"status"
:
"PAID"
,
"orderProducts"
:
[
{
"id"
:
{
"orderId"
:
1
,
"productId"
:
2
},
"actualPrice"
:
2400.00
,
"actualVat"
:
0.23
,
"quantity"
:
3
,
"product"
:
{
"productId"
:
2
,
"description"
:
"Odkurzacz o wyglądzie przypominającym Matiza"
,
"price"
:
805.00
,
"productName"
:
"odkurzacz"
,
"vat"
:
0.23
}
},
{
"id"
:
{
"orderId"
:
1
,
"productId"
:
1
},
"actualPrice"
:
2900.00
,
"actualVat"
:
0.23
,
"quantity"
:
1
,
"product"
:
{
"productId"
:
1
,
"description"
:
"Pralka szybkoobrotowa"
,
"price"
:
2501.00
,
"productName"
:
"pralka"
,
"vat"
:
0.23
}
}
],
"customer"
:
{
"customerEmail"
:
"ala@example.com"
,
"address"
:
"Jasna 14/16"
,
"city"
:
"Warszawa"
,
"customerName"
:
"Ala Kowalska"
,
"phoneNumber"
:
"123123123"
,
"postalCode"
:
"01-235"
}
}
\ No newline at end of file
PC27-SklepSpring/src/main/java/sklep/model/Customer.java
View file @
1ec6407a
...
@@ -7,6 +7,8 @@ import jakarta.validation.constraints.Pattern;
...
@@ -7,6 +7,8 @@ import jakarta.validation.constraints.Pattern;
import
java.util.List
;
import
java.util.List
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
/**
/**
* The persistent class for the customers database table.
* The persistent class for the customers database table.
...
@@ -39,6 +41,7 @@ public class Customer implements Serializable {
...
@@ -39,6 +41,7 @@ public class Customer implements Serializable {
//bi-directional many-to-one association to Order
//bi-directional many-to-one association to Order
@OneToMany
(
mappedBy
=
"customer"
)
@OneToMany
(
mappedBy
=
"customer"
)
@JsonIgnore
private
List
<
Order
>
orders
;
private
List
<
Order
>
orders
;
public
Customer
()
{
public
Customer
()
{
...
...
PC27-SklepSpring/src/main/java/sklep/model/OrderProduct.java
View file @
1ec6407a
...
@@ -8,6 +8,8 @@ import jakarta.validation.constraints.Min;
...
@@ -8,6 +8,8 @@ import jakarta.validation.constraints.Min;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
/**
/**
* The persistent class for the order_products database table.
* The persistent class for the order_products database table.
...
@@ -37,6 +39,7 @@ public class OrderProduct implements Serializable {
...
@@ -37,6 +39,7 @@ public class OrderProduct implements Serializable {
//bi-directional many-to-one association to Order
//bi-directional many-to-one association to Order
@ManyToOne
@ManyToOne
@JoinColumn
(
name
=
"order_id"
,
insertable
=
false
,
updatable
=
false
)
@JoinColumn
(
name
=
"order_id"
,
insertable
=
false
,
updatable
=
false
)
@JsonIgnore
private
Order
order
;
private
Order
order
;
//uni-directional many-to-one association to Product
//uni-directional many-to-one association to Product
...
...
PC27-SklepSpring/src/main/java/sklep/repository/OrderRepository.java
0 → 100644
View file @
1ec6407a
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
sklep.model.Order
;
public
interface
OrderRepository
extends
JpaRepository
<
Order
,
Integer
>
{
}
PC27-SklepSpring/src/main/java/sklep/rest/OrderEndpoint.java
0 → 100644
View file @
1ec6407a
package
sklep
.
rest
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.server.ResponseStatusException
;
import
sklep.model.Order
;
import
sklep.repository.OrderRepository
;
@RestController
@RequestMapping
(
"/rest/orders"
)
public
class
OrderEndpoint
{
@Autowired
private
OrderRepository
orderRepository
;
@GetMapping
public
List
<
Order
>
readAll
()
{
return
orderRepository
.
findAll
();
}
@GetMapping
(
"/{id}"
)
public
Order
readOne
(
@PathVariable
(
"id"
)
int
id
)
{
Optional
<
Order
>
order
=
orderRepository
.
findById
(
id
);
if
(
order
.
isPresent
())
{
return
order
.
get
();
}
else
{
throw
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
"Nie ma zamówienia o numerze "
+
id
);
}
}
}
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