Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20240528-BJava
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
20240528-BJava
Commits
d286d9d1
Commit
d286d9d1
authored
Jun 28, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Poprawki modelu m.in. aby JSON działał
parent
426f5be8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
14 deletions
+80
-14
Order.java
PC30-Hibernate/src/main/java/sklep/model/Order.java
+21
-5
Customer.java
PC33-SklepSpring/src/main/java/sklep/model/Customer.java
+21
-3
Order.java
PC33-SklepSpring/src/main/java/sklep/model/Order.java
+21
-5
OrderProduct.java
PC33-SklepSpring/src/main/java/sklep/model/OrderProduct.java
+2
-0
application.properties
PC33-SklepSpring/src/main/resources/application.properties
+2
-0
index.jsp
PC33-SklepSpring/src/main/webapp/WEB-INF/templates/index.jsp
+13
-1
No files found.
PC30-Hibernate/src/main/java/sklep/model/Order.java
View file @
d286d9d1
...
...
@@ -71,11 +71,26 @@ public class Order {
this
.
orderProducts
=
orderProducts
;
}
/*
TODO [Reverse Engineering] create field to map the 'status' column
Available actions: Define target Java type | Uncomment as is | Remove column mapping
@ColumnDefault
(
"'NEW'::order_status"
)
@Column
(
name
=
"status"
,
columnDefinition
=
"order_status not null"
)
private Object status;
*/
@Enumerated
(
EnumType
.
STRING
)
private
Status
status
;
public
Status
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Status
status
)
{
this
.
status
=
status
;
}
public
enum
Status
{
NEW
,
CONFIRMED
,
PAID
,
SHIPPED
,
DELIVERED
,
CLOSED
,
RETURNED
;
}
}
\ No newline at end of file
PC33-SklepSpring/src/main/java/sklep/model/Customer.java
View file @
d286d9d1
...
...
@@ -5,7 +5,9 @@ import jakarta.persistence.*;
import
jakarta.validation.constraints.Email
;
import
jakarta.validation.constraints.Pattern
;
import
java.util.ArrayList
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
@Entity
...
...
@@ -34,7 +36,9 @@ public class Customer {
@OneToMany
(
mappedBy
=
"customer"
)
@JsonIgnore
private
Set
<
Order
>
orders
=
new
LinkedHashSet
<>();
// W danych klienta zwracanych w JSONie nie będzie listy zamówień.
// Można by pomyśleć o stworzeniu dwóch wersji tej klasy - jedna z zamówieniami, jedna bez.
private
List
<
Order
>
orders
=
new
ArrayList
<>();
public
String
getCustomerEmail
()
{
return
customerEmail
;
...
...
@@ -84,12 +88,25 @@ public class Customer {
this
.
city
=
city
;
}
public
Se
t
<
Order
>
getOrders
()
{
public
Lis
t
<
Order
>
getOrders
()
{
return
orders
;
}
public
void
setOrders
(
Se
t
<
Order
>
orders
)
{
public
void
setOrders
(
Lis
t
<
Order
>
orders
)
{
this
.
orders
=
orders
;
}
public
Order
addOrder
(
Order
order
)
{
getOrders
().
add
(
order
);
order
.
setCustomer
(
this
);
return
order
;
}
public
Order
removeOrder
(
Order
order
)
{
getOrders
().
remove
(
order
);
order
.
setCustomer
(
null
);
return
order
;
}
}
\ No newline at end of file
PC33-SklepSpring/src/main/java/sklep/model/Order.java
View file @
d286d9d1
...
...
@@ -71,11 +71,26 @@ public class Order {
this
.
orderProducts
=
orderProducts
;
}
/*
TODO [Reverse Engineering] create field to map the 'status' column
Available actions: Define target Java type | Uncomment as is | Remove column mapping
@ColumnDefault
(
"'NEW'::order_status"
)
@Column
(
name
=
"status"
,
columnDefinition
=
"order_status not null"
)
private Object status;
*/
@Enumerated
(
EnumType
.
STRING
)
private
Status
status
;
public
Status
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Status
status
)
{
this
.
status
=
status
;
}
public
enum
Status
{
NEW
,
CONFIRMED
,
PAID
,
SHIPPED
,
DELIVERED
,
CLOSED
,
RETURNED
;
}
}
\ No newline at end of file
PC33-SklepSpring/src/main/java/sklep/model/OrderProduct.java
View file @
d286d9d1
package
sklep
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
jakarta.persistence.*
;
import
org.hibernate.annotations.ColumnDefault
;
...
...
@@ -14,6 +15,7 @@ public class OrderProduct {
@MapsId
(
"orderId"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"order_id"
,
nullable
=
false
)
@JsonIgnore
private
Order
order
;
@MapsId
(
"productId"
)
...
...
PC33-SklepSpring/src/main/resources/application.properties
View file @
d286d9d1
...
...
@@ -6,4 +6,6 @@ spring.datasource.url=jdbc:postgresql://localhost/sklep
spring.datasource.username
=
alx
spring.datasource.password
=
abc123
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS
=
false
alx.photo_dir
=
/home/patryk/sklep/foto
PC33-SklepSpring/src/main/webapp/WEB-INF/templates/index.jsp
View file @
d286d9d1
...
...
@@ -35,13 +35,25 @@
<li><a
href=
"/products/2/photo"
>
przykładowe zdjęcie
</a></li>
</ul>
<h2>
Edycja klienta
</h2>
<h2>
Klienci
</h2>
<ul>
<li><a
href=
"/customers"
>
lista klientów
</a>
<li><a
href=
"/customers/new"
>
nowy klient
</a>
<li><a
href=
"/customers/ala@example.com/edit"
>
edycja klienta
</a>
</ul>
<h2>
Zapytania RESTowe
</h2>
<ul>
<li><a
href=
"/rest/products"
>
products
</a></li>
<li><a
href=
"/rest/products/1"
>
products/1
</a></li>
<li><a
href=
"/rest/products/1/price"
>
products/1/price
</a></li>
<li><a
href=
"/rest/products/1/photo"
>
products/1/photo
</a></li>
<li><a
href=
"/rest/orders"
>
orders
</a></li>
<li><a
href=
"/rest/orders/1"
>
orders/1
</a></li>
<li><a
href=
"/rest/customers"
>
customers
</a></li>
<li><a
href=
"/rest/customers/ala@example.com"
>
customers/ala
</a></li>
</ul>
<h2>
Alternatywne dostępy do bazy danych
</h2>
<ul>
<li><a
href=
"/alt0/products"
>
Dostęp JDBC
</a>
(klasyczne getConnection)
</li>
...
...
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