Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Samuel Dudík
PA165 Winery Management System
Commits
d3857b9b
Commit
d3857b9b
authored
May 18, 2022
by
Ondřej Pavlica
Browse files
Fixes
parent
4187d534
Changes
10
Hide whitespace changes
Inline
Side-by-side
winery/dao/src/main/java/cz/muni/fi/pa165/winery/persistence/entities/WineBottle.java
View file @
d3857b9b
...
...
@@ -31,7 +31,7 @@ public class WineBottle extends EntityBase{
*/
@Column
(
nullable
=
false
)
@NotNull
@Pattern
(
regexp
=
"^[\\w0-9]*$"
,
message
=
"Only alphanumerical characters"
)
@Pattern
(
regexp
=
"^[\\w0-9
]*$"
,
message
=
"Only alphanumerical characters"
)
private
String
name
;
/**
...
...
@@ -46,7 +46,7 @@ public class WineBottle extends EntityBase{
* attribute of type BigDecimal representing price
*/
@Column
(
nullable
=
false
)
@Positive
@Positive
OrZero
private
BigDecimal
price
;
/**
...
...
@@ -54,7 +54,7 @@ public class WineBottle extends EntityBase{
*/
@Column
(
nullable
=
false
)
@NotNull
@Positive
@Positive
OrZero
private
BigDecimal
volume
;
/**
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/CartController.java
View file @
d3857b9b
...
...
@@ -21,6 +21,7 @@ import org.springframework.web.servlet.ModelAndView;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
...
...
@@ -99,16 +100,25 @@ public class CartController extends ControllerBase {
@ResponseBody
public
String
add
()
{
var
cart
=
cartService
.
loadFromCookie
();
var
cartItems
=
cart
.
getCartItems
();
var
cartItems
=
new
HashMap
<>(
cart
.
getCartItems
());
for
(
Map
.
Entry
<
Long
,
Integer
>
entry
:
cartItems
.
entrySet
().
stream
().
collect
(
Collectors
.
toList
()))
{
if
(
entry
.
getValue
()
<
0
)
{
throw
new
ResponseStatusException
(
GONE
,
"Cannot order a negative number of items."
);
}
if
(
entry
.
getValue
()
==
0
)
{
cartItems
.
remove
(
entry
.
getKey
());
continue
;
}
for
(
Map
.
Entry
<
Long
,
Integer
>
entry
:
cartItems
.
entrySet
())
{
var
bottle
=
wineBottleService
.
get
(
entry
.
getKey
());
if
(
bottle
==
null
)
{
continue
;
}
if
(
bottle
.
getStock
()
<
entry
.
getValue
())
if
(
bottle
.
getStock
()
<
entry
.
getValue
())
{
throw
new
ResponseStatusException
(
GONE
,
"Not enough products on stock."
);
}
}
var
order
=
new
OrderDto
();
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/grape/GrapeUpsertViewModel.java
View file @
d3857b9b
...
...
@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
import
lombok.Setter
;
import
org.modelmapper.ModelMapper
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
/**
...
...
@@ -29,7 +30,7 @@ public class GrapeUpsertViewModel extends ViewModelBase {
/**
* name of grape variety
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Not
Blank
(
message
=
"Cannot be empty"
)
private
String
name
;
public
GrapeDto
toDto
()
{
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/orders/OrdersUpsertViewModel.java
View file @
d3857b9b
...
...
@@ -13,10 +13,7 @@ import one.util.streamex.StreamEx;
import
org.modelmapper.ModelMapper
;
import
org.modelmapper.convention.MatchingStrategies
;
import
javax.validation.constraints.Max
;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.PositiveOrZero
;
import
javax.validation.constraints.*
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.util.HashSet
;
...
...
@@ -52,19 +49,19 @@ public class OrdersUpsertViewModel extends ViewModelBase {
/**
* The order creation timestamp
*/
@NotNull
@NotNull
(
message
=
"Cannot be empty"
)
private
LocalDateTime
dateTime
;
/**
* Whether the order is already shipped
*/
@NotNull
@NotNull
(
message
=
"Cannot be empty"
)
private
boolean
shipped
;
/**
* The order creator's user ID
*/
@
NotNull
@
Positive
(
message
=
"Cannot be empty"
)
private
long
userId
;
/**
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/user/UserInsertViewModel.java
View file @
d3857b9b
...
...
@@ -30,20 +30,20 @@ public class UserInsertViewModel extends ViewModelBase {
/**
* User's first name (forename).
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Not
Blank
(
message
=
"Cannot be empty"
)
private
String
firstName
;
/**
* User's last name (surname)
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Not
Blank
(
message
=
"Cannot be empty"
)
private
String
lastName
;
/**
* User's email address
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Email
@Not
Blank
(
message
=
"Cannot be empty"
)
@Email
(
message
=
"Not a valid email format"
)
private
String
email
;
/**
...
...
@@ -51,7 +51,7 @@ public class UserInsertViewModel extends ViewModelBase {
*
* Not stored directly
*/
@NotBlank
@NotBlank
(
message
=
"Cannot be empty"
)
private
String
password
;
public
UserDto
toDto
(
PasswordEncoder
encoder
)
{
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/user/UserUpdateViewModel.java
View file @
d3857b9b
...
...
@@ -11,6 +11,7 @@ import org.modelmapper.convention.MatchingStrategies;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
javax.validation.constraints.Email
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
/**
...
...
@@ -43,20 +44,20 @@ public class UserUpdateViewModel extends ViewModelBase {
/**
* User's first name (forename).
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Not
Blank
(
message
=
"Cannot be empty"
)
private
String
firstName
;
/**
* User's last name (surname)
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Not
Blank
(
message
=
"Cannot be empty"
)
private
String
lastName
;
/**
* User's email address
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Email
@Not
Blank
(
message
=
"Cannot be empty"
)
@Email
(
message
=
"Not a valid email format"
)
private
String
email
;
/**
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/wineBottle/WineBottleUpsertViewModel.java
View file @
d3857b9b
...
...
@@ -11,6 +11,7 @@ import org.modelmapper.ModelMapper;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
import
javax.validation.constraints.PositiveOrZero
;
import
java.math.BigDecimal
;
import
java.util.List
;
...
...
@@ -37,6 +38,7 @@ public class WineBottleUpsertViewModel extends ViewModelBase {
* name of wine bottle
*/
@NotNull
(
message
=
"Cannot be empty"
)
@Pattern
(
regexp
=
"^[\\w0-9 ]*$"
,
message
=
"Only alphanumerical characters"
)
private
String
name
;
/**
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/models/wineType/WineTypeUpsertViewModel.java
View file @
d3857b9b
...
...
@@ -9,6 +9,7 @@ import lombok.Setter;
import
org.modelmapper.ModelMapper
;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.util.List
;
...
...
@@ -32,7 +33,7 @@ public class WineTypeUpsertViewModel extends ViewModelBase {
/**
* name of wine type
*/
@Not
Null
(
message
=
"Cannot be empty"
)
@Not
Blank
(
message
=
"Cannot be empty"
)
private
String
name
;
/**
...
...
winery/webapp/src/main/resources/templates/cart/index.html
View file @
d3857b9b
...
...
@@ -26,7 +26,7 @@
<tbody>
<tr
th:each=
"item : ${model.cart}"
>
<td
th:text=
"${model.productNames[__${item.productId}__]}"
>
Product Name
</td>
<td><input
th:onchange=
"'setCartAmount(' + ${item.productId} + ', document.getElementById(\'quantity\').value)'"
type=
"number"
id=
"quantity"
name=
"quantity"
min=
"1"
th:value=
"${item.count}"
/></td>
<td><input
th:onchange=
"'setCartAmount(' + ${item.productId} + ', document.getElementById(\'quantity
' + ${item.productId} + '
\').value)'"
type=
"number"
th:
id=
"
'
quantity
' + ${item.productId}
"
name=
"quantity"
th:value=
"${item.count}"
/></td>
<td><a
href=
"#"
th:onclick=
"'removeFromCart(' + ${item.productId} + ').then(x => refreshPage())'"
>
Delete
</a></td>
</tr>
</tbody>
...
...
winery/webapp/src/main/resources/templates/fragments/header.html
View file @
d3857b9b
...
...
@@ -37,7 +37,7 @@
Username
</a>
<div
class=
"dropdown-menu"
aria-labelledby=
"navbarDropdown"
>
<a
class=
"dropdown-item"
th:href=
"@{/myorder}"
>
Orders
</a>
<a
class=
"dropdown-item"
th:href=
"@{/myorder}"
>
My
Orders
</a>
<a
class=
"dropdown-item"
th:href=
"@{/cart}"
>
Cart
</a>
<div
class=
"dropdown-divider"
></div>
<a
class=
"dropdown-item"
th:href=
"@{/logout}"
>
Logout
</a>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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