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
30ab04c6
Commit
30ab04c6
authored
Jun 28, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Klasy encji sklep
parent
0e4fe92c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
408 additions
and
0 deletions
+408
-0
Customer.java
PC35-RestRepo/src/main/java/sklep/model/Customer.java
+104
-0
Order.java
PC35-RestRepo/src/main/java/sklep/model/Order.java
+97
-0
OrderProduct.java
PC35-RestRepo/src/main/java/sklep/model/OrderProduct.java
+83
-0
OrderProductId.java
PC35-RestRepo/src/main/java/sklep/model/OrderProductId.java
+49
-0
Product.java
PC35-RestRepo/src/main/java/sklep/model/Product.java
+71
-0
application.properties
PC35-RestRepo/src/main/resources/application.properties
+4
-0
No files found.
PC35-RestRepo/src/main/java/sklep/model/Customer.java
0 → 100644
View file @
30ab04c6
package
sklep
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
jakarta.persistence.*
;
import
java.util.ArrayList
;
import
java.util.List
;
@Entity
@Table
(
name
=
"customers"
)
public
class
Customer
{
@Id
@Column
(
name
=
"customer_email"
,
nullable
=
false
,
length
=
100
)
private
String
customerEmail
;
@Column
(
name
=
"customer_name"
,
nullable
=
false
,
length
=
100
)
private
String
customerName
;
@Column
(
name
=
"phone_number"
,
length
=
20
)
private
String
phoneNumber
;
@Column
(
name
=
"address"
,
length
=
250
)
private
String
address
;
@Column
(
name
=
"postal_code"
,
length
=
10
)
private
String
postalCode
;
@Column
(
name
=
"city"
,
length
=
100
)
private
String
city
;
@OneToMany
(
mappedBy
=
"customer"
)
private
List
<
Order
>
orders
=
new
ArrayList
<>();
public
String
getCustomerEmail
()
{
return
customerEmail
;
}
public
void
setCustomerEmail
(
String
customerEmail
)
{
this
.
customerEmail
=
customerEmail
;
}
public
String
getCustomerName
()
{
return
customerName
;
}
public
void
setCustomerName
(
String
customerName
)
{
this
.
customerName
=
customerName
;
}
public
String
getPhoneNumber
()
{
return
phoneNumber
;
}
public
void
setPhoneNumber
(
String
phoneNumber
)
{
this
.
phoneNumber
=
phoneNumber
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
String
getPostalCode
()
{
return
postalCode
;
}
public
void
setPostalCode
(
String
postalCode
)
{
this
.
postalCode
=
postalCode
;
}
public
String
getCity
()
{
return
city
;
}
public
void
setCity
(
String
city
)
{
this
.
city
=
city
;
}
public
List
<
Order
>
getOrders
()
{
return
orders
;
}
public
void
setOrders
(
List
<
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
PC35-RestRepo/src/main/java/sklep/model/Order.java
0 → 100644
View file @
30ab04c6
package
sklep
.
model
;
import
jakarta.persistence.*
;
import
org.hibernate.annotations.ColumnDefault
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
@Entity
@Table
(
name
=
"orders"
)
public
class
Order
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@ColumnDefault
(
"nextval('orders_seq'::regclass)"
)
@Column
(
name
=
"order_id"
,
nullable
=
false
)
private
Integer
id
;
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"customer_email"
,
nullable
=
false
)
private
Customer
customer
;
@ColumnDefault
(
"CURRENT_TIMESTAMP"
)
@Column
(
name
=
"order_date"
,
nullable
=
false
)
private
Instant
orderDate
;
@Column
(
name
=
"delivery_date"
)
private
LocalDate
deliveryDate
;
@OneToMany
(
mappedBy
=
"order"
)
private
Set
<
OrderProduct
>
orderProducts
=
new
LinkedHashSet
<>();
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Customer
getCustomer
()
{
return
customer
;
}
public
void
setCustomer
(
Customer
customerEmail
)
{
this
.
customer
=
customerEmail
;
}
public
Instant
getOrderDate
()
{
return
orderDate
;
}
public
void
setOrderDate
(
Instant
orderDate
)
{
this
.
orderDate
=
orderDate
;
}
public
LocalDate
getDeliveryDate
()
{
return
deliveryDate
;
}
public
void
setDeliveryDate
(
LocalDate
deliveryDate
)
{
this
.
deliveryDate
=
deliveryDate
;
}
public
Set
<
OrderProduct
>
getOrderProducts
()
{
return
orderProducts
;
}
public
void
setOrderProducts
(
Set
<
OrderProduct
>
orderProducts
)
{
this
.
orderProducts
=
orderProducts
;
}
@ColumnDefault
(
"'NEW'::order_status"
)
@Column
(
name
=
"status"
,
columnDefinition
=
"order_status not null"
)
@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
PC35-RestRepo/src/main/java/sklep/model/OrderProduct.java
0 → 100644
View file @
30ab04c6
package
sklep
.
model
;
import
jakarta.persistence.*
;
import
org.hibernate.annotations.ColumnDefault
;
import
java.math.BigDecimal
;
@Entity
@Table
(
name
=
"order_products"
)
public
class
OrderProduct
{
@EmbeddedId
private
OrderProductId
id
;
@MapsId
(
"orderId"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"order_id"
,
nullable
=
false
)
private
Order
order
;
@MapsId
(
"productId"
)
@ManyToOne
(
fetch
=
FetchType
.
LAZY
,
optional
=
false
)
@JoinColumn
(
name
=
"product_id"
,
nullable
=
false
)
private
Product
product
;
@ColumnDefault
(
"1"
)
@Column
(
name
=
"quantity"
,
nullable
=
false
)
private
Short
quantity
;
@Column
(
name
=
"actual_price"
,
nullable
=
false
,
precision
=
10
,
scale
=
2
)
private
BigDecimal
actualPrice
;
@Column
(
name
=
"actual_vat"
,
precision
=
2
,
scale
=
2
)
private
BigDecimal
actualVat
;
public
OrderProductId
getId
()
{
return
id
;
}
public
void
setId
(
OrderProductId
id
)
{
this
.
id
=
id
;
}
public
Order
getOrder
()
{
return
order
;
}
public
void
setOrder
(
Order
order
)
{
this
.
order
=
order
;
}
public
Product
getProduct
()
{
return
product
;
}
public
void
setProduct
(
Product
product
)
{
this
.
product
=
product
;
}
public
Short
getQuantity
()
{
return
quantity
;
}
public
void
setQuantity
(
Short
quantity
)
{
this
.
quantity
=
quantity
;
}
public
BigDecimal
getActualPrice
()
{
return
actualPrice
;
}
public
void
setActualPrice
(
BigDecimal
actualPrice
)
{
this
.
actualPrice
=
actualPrice
;
}
public
BigDecimal
getActualVat
()
{
return
actualVat
;
}
public
void
setActualVat
(
BigDecimal
actualVat
)
{
this
.
actualVat
=
actualVat
;
}
}
\ No newline at end of file
PC35-RestRepo/src/main/java/sklep/model/OrderProductId.java
0 → 100644
View file @
30ab04c6
package
sklep
.
model
;
import
jakarta.persistence.Column
;
import
jakarta.persistence.Embeddable
;
import
org.hibernate.Hibernate
;
import
java.util.Objects
;
@Embeddable
public
class
OrderProductId
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
-
675988817260271390L
;
@Column
(
name
=
"order_id"
,
nullable
=
false
)
private
Integer
orderId
;
@Column
(
name
=
"product_id"
,
nullable
=
false
)
private
Integer
productId
;
public
Integer
getOrderId
()
{
return
orderId
;
}
public
void
setOrderId
(
Integer
orderId
)
{
this
.
orderId
=
orderId
;
}
public
Integer
getProductId
()
{
return
productId
;
}
public
void
setProductId
(
Integer
productId
)
{
this
.
productId
=
productId
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
Hibernate
.
getClass
(
this
)
!=
Hibernate
.
getClass
(
o
))
return
false
;
OrderProductId
entity
=
(
OrderProductId
)
o
;
return
Objects
.
equals
(
this
.
productId
,
entity
.
productId
)
&&
Objects
.
equals
(
this
.
orderId
,
entity
.
orderId
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
productId
,
orderId
);
}
}
\ No newline at end of file
PC35-RestRepo/src/main/java/sklep/model/Product.java
0 → 100644
View file @
30ab04c6
package
sklep
.
model
;
import
jakarta.persistence.*
;
import
org.hibernate.annotations.ColumnDefault
;
import
java.math.BigDecimal
;
@Entity
@Table
(
name
=
"products"
)
@NamedQuery
(
name
=
"Product.findAll"
,
query
=
"SELECT p FROM Product p ORDER BY p.id"
)
public
class
Product
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@ColumnDefault
(
"nextval('products_seq'::regclass)"
)
@Column
(
name
=
"product_id"
,
nullable
=
false
)
private
Integer
id
;
@Column
(
name
=
"product_name"
,
nullable
=
false
,
length
=
100
)
private
String
productName
;
@Column
(
name
=
"price"
,
nullable
=
false
,
precision
=
10
,
scale
=
2
)
private
BigDecimal
price
;
@Column
(
name
=
"vat"
,
precision
=
2
,
scale
=
2
)
private
BigDecimal
vat
;
@Column
(
name
=
"description"
,
length
=
Integer
.
MAX_VALUE
)
private
String
description
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getProductName
()
{
return
productName
;
}
public
void
setProductName
(
String
productName
)
{
this
.
productName
=
productName
;
}
public
BigDecimal
getPrice
()
{
return
price
;
}
public
void
setPrice
(
BigDecimal
price
)
{
this
.
price
=
price
;
}
public
BigDecimal
getVat
()
{
return
vat
;
}
public
void
setVat
(
BigDecimal
vat
)
{
this
.
vat
=
vat
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
\ No newline at end of file
PC35-RestRepo/src/main/resources/application.properties
View file @
30ab04c6
spring.application.name
=
PC35-RestRepo
spring.datasource.url
=
jdbc:postgresql://localhost/sklep
spring.datasource.username
=
alx
spring.datasource.password
=
abc123
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