Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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
java_dzienna_15_09
Commits
e22cc28d
Commit
e22cc28d
authored
Oct 07, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CustomerController i @JsonIgnore
parent
dca054b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
0 deletions
+44
-0
Customer.java
PC37-RestSpring/src/main/java/sklep/model/Customer.java
+3
-0
OrderProduct.java
PC37-RestSpring/src/main/java/sklep/model/OrderProduct.java
+3
-0
OrderController.java
...-RestSpring/src/main/java/sklep/rest/OrderController.java
+38
-0
No files found.
PC37-RestSpring/src/main/java/sklep/model/Customer.java
View file @
e22cc28d
...
@@ -4,6 +4,8 @@ import java.io.Serializable;
...
@@ -4,6 +4,8 @@ import java.io.Serializable;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
javax.validation.constraints.Pattern
;
import
javax.validation.constraints.Pattern
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
java.util.List
;
import
java.util.List
;
...
@@ -37,6 +39,7 @@ public class Customer implements Serializable {
...
@@ -37,6 +39,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
()
{
...
...
PC37-RestSpring/src/main/java/sklep/model/OrderProduct.java
View file @
e22cc28d
...
@@ -4,6 +4,8 @@ import java.io.Serializable;
...
@@ -4,6 +4,8 @@ import java.io.Serializable;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.Min
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
...
@@ -29,6 +31,7 @@ public class OrderProduct implements Serializable {
...
@@ -29,6 +31,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
...
...
PC37-RestSpring/src/main/java/sklep/rest/OrderController.java
0 → 100644
View file @
e22cc28d
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
(
"/orders"
)
public
class
OrderController
{
@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