Skip to content

Commit

Permalink
feat: update model
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaohoanq committed Dec 10, 2024
1 parent 960c266 commit 29c7f5b
Show file tree
Hide file tree
Showing 48 changed files with 1,369 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.lcaohoanq.shoppe.base.entity;

import jakarta.persistence.MappedSuperclass;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public class BaseLocation {

private String name;
private String address;
private String city;
private String country;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.lcaohoanq.shoppe.config;

import jakarta.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "vnpay.api")
@Getter
@Setter
public class VNPayConfig {

private String vnp_Version;
private String vnp_Command;
private String vnp_OrderType;
private String vnp_PayUrl;
private String vnp_Returnurl;
private String vnp_TmnCode; // kiểm tra email sau
private String vnp_HashSecret; // khi đăng ký Test
private String vnp_apiUrl;

public String hashAllFields(Map fields) {
List fieldNames = new ArrayList(fields.keySet());
Collections.sort(fieldNames);
StringBuilder sb = new StringBuilder();
Iterator itr = fieldNames.iterator();
while (itr.hasNext()) {
String fieldName = (String) itr.next();
String fieldValue = (String) fields.get(fieldName);
if ((fieldValue != null) && (fieldValue.length() > 0)) {
sb.append(fieldName);
sb.append("=");
sb.append(fieldValue);
}
if (itr.hasNext()) {
sb.append("&");
}
}
return hmacSHA512(getVnp_HashSecret(), sb.toString());
}

public static String hmacSHA512(final String key, final String data) {
try {

if (key == null || data == null) {
throw new NullPointerException();
}
final Mac hmac512 = Mac.getInstance("HmacSHA512");
byte[] hmacKeyBytes = key.getBytes();
final SecretKeySpec secretKey = new SecretKeySpec(hmacKeyBytes, "HmacSHA512");
hmac512.init(secretKey);
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
byte[] result = hmac512.doFinal(dataBytes);
StringBuilder sb = new StringBuilder(2 * result.length);
for (byte b : result) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();

} catch (Exception ex) {
return "";
}
}

public static String getIpAddress(HttpServletRequest request) {
String ipAdress;
try {
ipAdress = request.getHeader("X-FORWARDED-FOR");
if (ipAdress == null) {
ipAdress = request.getLocalAddr();
}
} catch (Exception e) {
ipAdress = "Invalid IP:" + e.getMessage();
}
return ipAdress;
}

public static String getRandomNumber(int len) {
Random rnd = new Random();
String chars = "0123456789";
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
sb.append(chars.charAt(rnd.nextInt(chars.length())));
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
String.format("%s/orders/**", apiPrefix),
String.format("%s/assets/**", apiPrefix),
String.format("%s/carts/**", apiPrefix),
String.format("%s/wallets/**", apiPrefix),
String.format("%s/inventories/**", apiPrefix),
String.format("%s/payments/**", apiPrefix),
"/error"
).permitAll()
// Swagger UI with basic auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.lcaohoanq.shoppe.base.entity.BaseEntity;
import com.lcaohoanq.shoppe.domain.subcategory.Subcategory;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.lcaohoanq.shoppe.component.LocalizationUtils;
import com.lcaohoanq.shoppe.api.ApiResponse;
import com.lcaohoanq.shoppe.domain.subcategory.CreateNewSubcategoryResponse;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryDTO;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryResponse;
import com.lcaohoanq.shoppe.exception.MethodArgumentNotValidException;
import com.lcaohoanq.shoppe.util.DTOConverter;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.lcaohoanq.shoppe.domain.subcategory.Subcategory;
import java.time.LocalDateTime;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.lcaohoanq.shoppe.domain.category;

import com.lcaohoanq.shoppe.domain.subcategory.CreateNewSubcategoryResponse;
import com.lcaohoanq.shoppe.domain.subcategory.Subcategory;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryDTO;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryRepository;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryResponse;
import com.lcaohoanq.shoppe.exception.CategoryAlreadyExistException;
import com.lcaohoanq.shoppe.exception.CategoryNotFoundException;
import com.lcaohoanq.shoppe.base.exception.DataAlreadyExistException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.lcaohoanq.shoppe.base.exception.DataAlreadyExistException;
import com.lcaohoanq.shoppe.base.exception.DataNotFoundException;
import com.lcaohoanq.shoppe.domain.subcategory.CreateNewSubcategoryResponse;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryDTO;
import com.lcaohoanq.shoppe.domain.subcategory.SubcategoryResponse;
import java.util.List;

public interface ICategoryService {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lcaohoanq.shoppe.domain.inventory;

public interface IInventoryService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.lcaohoanq.shoppe.domain.inventory;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lcaohoanq.shoppe.base.entity.BaseEntity;
import com.lcaohoanq.shoppe.domain.product.Product;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import java.util.List;
import java.util.Set;
import javax.print.event.PrintJobAttributeEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "inventories")
@Entity
public class Inventory extends BaseEntity {

@Id
@SequenceGenerator(name = "inventories_seq", sequenceName = "inventories_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "inventories_seq")
@Column(name="id", unique=true, nullable=false)
@JsonProperty("id")
private Long id;

@JsonManagedReference
@OneToMany(mappedBy = "inventory")
@JsonProperty("inventory_locations")
private Set<InventoryLocation> inventoryLocations;

@OneToMany(mappedBy = "inventory")
@JsonManagedReference
private Set<Product> products;

private Long quantity;

private Long reserved; //Reserved quantity for orders

@Column(name = "reorder_point")
private Long reorderPoint; //The quantity that triggers a reorder

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lcaohoanq.shoppe.domain.inventory;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("${api.prefix}/inventories")
@RequiredArgsConstructor
@Slf4j
public class InventoryController {



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.lcaohoanq.shoppe.domain.inventory;


import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lcaohoanq.shoppe.base.entity.BaseLocation;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "inventory_locations")
@Entity
public class InventoryLocation extends BaseLocation {

@Id
@SequenceGenerator(name = "inventory_locations_seq", sequenceName = "inventory_locations_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "inventory_locations_seq")
@Column(name="id", unique=true, nullable=false)
@JsonProperty("id")
private Long id;

@ManyToOne
@JsonBackReference
@JoinColumn(name = "inventory_id", nullable = false)
private Inventory inventory;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lcaohoanq.shoppe.domain.inventory;

import org.springframework.data.jpa.repository.JpaRepository;

public interface InventoryRepository extends JpaRepository<Inventory, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.lcaohoanq.shoppe.domain.inventory;

import org.springframework.stereotype.Service;

@Service
public class InventoryService implements IInventoryService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lcaohoanq.shoppe.domain.logistic;

public interface IOrderShippingService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lcaohoanq.shoppe.domain.logistic;

public interface IShippingCarrierService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.lcaohoanq.shoppe.domain.logistic;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.lcaohoanq.shoppe.base.entity.BaseEntity;
import com.lcaohoanq.shoppe.domain.order.Order;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Table(name = "orders_shipping")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class OrderShipping extends BaseEntity {

@Id
@SequenceGenerator(name = "orders_shipping_seq", sequenceName = "orders_shipping_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "orders_shipping_seq")
@Column(name="id", unique=true, nullable=false)
@JsonProperty("id")
private Long id;

@ManyToOne
@JoinColumn(name = "order_id", nullable = false)
private Order order;

@ManyToOne
@JoinColumn(name = "shipping_carrier_id", nullable = false)
private ShippingCarrier shippingCarrier;

@Column(name = "tracking_number")
private String trackingNumber;

@Column(name = "shipping_fee")
private Float shippingFee;

@Column(name = "shipping_status")
private String shippingStatus;

@Column(name = "shipping_date")
private Date shippingDate;

@Column(name = "estimated_delivery")
private Date estimatedDelivery;

}
Loading

0 comments on commit 29c7f5b

Please sign in to comment.