Skip to content

Commit

Permalink
Merge pull request #98 from xdorro/minh
Browse files Browse the repository at this point in the history
Minh
  • Loading branch information
mizhm authored Jul 12, 2022
2 parents b730bdf + 25c447d commit 7f93d1c
Show file tree
Hide file tree
Showing 48 changed files with 1,297 additions and 377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class CategoryRequestDTO {
private Long categoryId;
@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class CustomerRequestDTO {
private Long customerId;
@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Setter
@Builder
public class PaymentRequestDTO {
private Long paymentId;
@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Setter
@Builder
public class ProductRequestDTO {
private Long productId;
@NotBlank
private String name;
@NotBlank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Setter
@Builder
public class SupplierRequestDTO {
private Long supplierId;
@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Setter
@Builder
public class TransportRequestDTO {
private Long transportId;
@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Setter
@Builder
public class UnitRequestDTO {
private Long unitId;
@NotBlank
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class UserRequestDTO {
private Long userId;
private Long roleId;

@NotBlank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String storeCategory(CategoryRequestDTO input, BindingResult result, Mode
return "backend/category/create";
}

var count = categoryRepository.findBySlugAndStatusNot(input.getSlug(), DefaultStatus.DELETED);
var count = categoryRepository.countBySlugAndStatusNot(input.getSlug().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("slug", "", "Đường dẫn đã được sử dụng");
}
Expand Down Expand Up @@ -96,13 +96,14 @@ public String updateCategory(Long id, CategoryRequestDTO input, BindingResult re
}

if (result.hasErrors()) {
input.setCategoryId(id);
model.addAttribute("category", input);

return "backend/category/create";
return "backend/category/edit";
}

if (!category.getSlug().equals(input.getSlug())) {
var count = categoryRepository.countBySlugAndStatusNot(input.getSlug(), DefaultStatus.DELETED);
var count = categoryRepository.countBySlugAndStatusNot(input.getSlug().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("slug", "", "Đường dẫn đã được sử dụng");
}
Expand All @@ -111,9 +112,10 @@ public String updateCategory(Long id, CategoryRequestDTO input, BindingResult re
}

if (result.hasErrors()) {
input.setCategoryId(id);
model.addAttribute("category", input);

return "backend/category/create";
return "backend/category/edit";
}

category.setName(input.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String storeCustomer(CustomerRequestDTO input, BindingResult result, Mode
}

input.setPassword(bcryptPasswordEncoder.encode(input.getPassword()));
var count = customerRepository.countByEmailAndStatusNot(input.getEmail(), DefaultStatus.DELETED);
var count = customerRepository.countByEmailAndStatusNot(input.getEmail().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("email", "email.required", "Email đã được sử dụng");
}
Expand Down Expand Up @@ -86,17 +86,18 @@ public String updateCustomer(Long id, CustomerRequestDTO input, BindingResult re
}

if (result.hasErrors()) {
input.setCustomerId(id);
model.addAttribute("customer", input);

return "backend/customer/create";
return "backend/customer/edit";
}

if (!input.getPassword().isEmpty()) {
customer.setPassword(bcryptPasswordEncoder.encode(input.getPassword()));
}

if (!customer.getEmail().equals(input.getEmail())) {
var count = customerRepository.countByEmailAndStatusNot(input.getEmail(), DefaultStatus.DELETED);
var count = customerRepository.countByEmailAndStatusNot(input.getEmail().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("email", "email.required", "Email đã được sử dụng");
}
Expand All @@ -105,9 +106,10 @@ public String updateCustomer(Long id, CustomerRequestDTO input, BindingResult re
}

if (result.hasErrors()) {
input.setCustomerId(id);
model.addAttribute("customer", input);

return "backend/customer/create";
return "backend/customer/edit";
}

customer.setName(input.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String storePayment(PaymentRequestDTO input, BindingResult result, Model
return "backend/payment/create";
}

var count = paymentRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = paymentRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand Down Expand Up @@ -82,13 +82,14 @@ public String updatePayment(Long id, PaymentRequestDTO input, BindingResult resu
}

if (result.hasErrors()) {
input.setPaymentId(id);
model.addAttribute("payment", input);

return "backend/payment/create";
return "backend/payment/edit";
}

if (!payment.getName().equals(input.getName())) {
var count = paymentRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = paymentRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand All @@ -97,9 +98,10 @@ public String updatePayment(Long id, PaymentRequestDTO input, BindingResult resu
}

if (result.hasErrors()) {
input.setPaymentId(id);
model.addAttribute("payment", input);

return "backend/payment/create";
return "backend/payment/edit";
}

payment.setStatus(input.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public String storeProduct(ProductRequestDTO input, BindingResult result, Model
return "backend/product/create";
}

var count = productRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = productRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên sản phẩm đã được sử dụng");
}

var countSlug = productRepository.countBySlugAndStatusNot(input.getSlug(), DefaultStatus.DELETED);
var countSlug = productRepository.countBySlugAndStatusNot(input.getSlug().trim(), DefaultStatus.DELETED);
if (countSlug > 0) {
result.rejectValue("slug", "", "Đường dẫn đã được sử dụng");
}
Expand Down Expand Up @@ -154,6 +154,7 @@ public String updateProduct(Long id, ProductRequestDTO input, BindingResult resu
}

if (result.hasErrors()) {
input.setProductId(id);
model.addAttribute("product", input);
model.addAttribute("categories", categoryRepository.findAllByStatus(DefaultStatus.ACTIVE));
model.addAttribute("units", unitRepository.findAllByStatus(DefaultStatus.ACTIVE));
Expand All @@ -162,15 +163,15 @@ public String updateProduct(Long id, ProductRequestDTO input, BindingResult resu
}

if (!product.getName().equals(input.getName())) {
var count = productRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = productRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên sản phẩm đã được sử dụng");
} else {
product.setName(input.getName());
}
}
if (!product.getSlug().equals(input.getSlug())) {
var countSlug = productRepository.countBySlugAndStatusNot(input.getSlug(), DefaultStatus.DELETED);
var countSlug = productRepository.countBySlugAndStatusNot(input.getSlug().trim(), DefaultStatus.DELETED);
if (countSlug > 0) {
result.rejectValue("slug", "", "Đường dẫn đã được sử dụng");
} else {
Expand All @@ -193,6 +194,7 @@ public String updateProduct(Long id, ProductRequestDTO input, BindingResult resu
}

if (result.hasErrors()) {
input.setProductId(id);
model.addAttribute("product", input);
model.addAttribute("categories", categoryRepository.findAllByStatus(DefaultStatus.ACTIVE));
model.addAttribute("units", unitRepository.findAllByStatus(DefaultStatus.ACTIVE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String storeSupplier(SupplierRequestDTO input, BindingResult result, Mode
return "backend/supplier/create";
}

var count = supplierRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = supplierRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand Down Expand Up @@ -82,13 +82,14 @@ public String updateSupplier(Long id, SupplierRequestDTO input, BindingResult re
}

if (result.hasErrors()) {
input.setSupplierId(id);
model.addAttribute("supplier", input);

return "backend/supplier/create";
return "backend/supplier/edit";
}

if (!supplier.getName().equals(input.getName())) {
var count = supplierRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = supplierRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand All @@ -97,9 +98,10 @@ public String updateSupplier(Long id, SupplierRequestDTO input, BindingResult re
}

if (result.hasErrors()) {
input.setSupplierId(id);
model.addAttribute("supplier", input);

return "backend/supplier/create";
return "backend/supplier/edit";
}

supplier.setStatus(input.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String storeTransport(TransportRequestDTO input, BindingResult result, Mo
return "backend/transport/create";
}

var count = transportRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = transportRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand Down Expand Up @@ -82,13 +82,14 @@ public String updateTransport(Long id, TransportRequestDTO input, BindingResult
}

if (result.hasErrors()) {
input.setTransportId(id);
model.addAttribute("transport", input);

return "backend/transport/create";
return "backend/transport/edit";
}

if (!transport.getName().equals(input.getName())) {
var count = transportRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = transportRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand All @@ -97,9 +98,10 @@ public String updateTransport(Long id, TransportRequestDTO input, BindingResult
}

if (result.hasErrors()) {
input.setTransportId(id);
model.addAttribute("transport", input);

return "backend/transport/create";
return "backend/transport/edit";
}

transport.setStatus(input.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String storeUnit(UnitRequestDTO input, BindingResult result, Model model,
return "backend/unit/create";
}

var count = unitRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = unitRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand Down Expand Up @@ -82,13 +82,14 @@ public String updateUnit(Long id, UnitRequestDTO input, BindingResult result, Mo
}

if (result.hasErrors()) {
input.setUnitId(id);
model.addAttribute("unit", input);

return "backend/unit/create";
return "backend/unit/edit";
}

if (!unit.getName().equals(input.getName())) {
var count = unitRepository.countByNameAndStatusNot(input.getName(), DefaultStatus.DELETED);
var count = unitRepository.countByNameAndStatusNot(input.getName().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("name", "", "Tên đơn vị đã được sử dụng");
}
Expand All @@ -97,9 +98,10 @@ public String updateUnit(Long id, UnitRequestDTO input, BindingResult result, Mo
}

if (result.hasErrors()) {
input.setUnitId(id);
model.addAttribute("unit", input);

return "backend/unit/create";
return "backend/unit/edit";
}

unit.setStatus(input.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String storeUser(UserRequestDTO input, BindingResult result, Model model,
return "backend/user/create";
}

var count = userRepository.countByEmailAndStatusNot(input.getEmail(), DefaultStatus.DELETED);
var count = userRepository.countByEmailAndStatusNot(input.getEmail().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("email", "email.required", "Email đã được sử dụng");
}
Expand Down Expand Up @@ -93,18 +93,19 @@ public String updateUser(Long id, UserRequestDTO input, BindingResult result, Mo
}

if (result.hasErrors()) {
input.setUserId(id);
model.addAttribute("user", input);
model.addAttribute("roles", roleRepository.findAllByStatus(DefaultStatus.ACTIVE));

return "backend/user/create";
return "backend/user/edit";
}

if (!input.getPassword().isEmpty()) {
user.setPassword(bcryptPasswordEncoder.encode(input.getPassword()));
}

if (!user.getEmail().equals(input.getEmail())) {
var count = userRepository.countByEmailAndStatusNot(input.getEmail(), DefaultStatus.DELETED);
var count = userRepository.countByEmailAndStatusNot(input.getEmail().trim(), DefaultStatus.DELETED);
if (count > 0) {
result.rejectValue("email", "email.required", "Email đã được sử dụng");
}
Expand All @@ -113,10 +114,11 @@ public String updateUser(Long id, UserRequestDTO input, BindingResult result, Mo
}

if (result.hasErrors()) {
input.setUserId(id);
model.addAttribute("user", input);
model.addAttribute("roles", roleRepository.findAllByStatus(DefaultStatus.ACTIVE));

return "backend/user/create";
return "backend/user/edit";
}

user.setName(input.getName());
Expand Down
Loading

0 comments on commit 7f93d1c

Please sign in to comment.