From 90197ededd4658aee336702f2bc4308d9a106876 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Thu, 5 Mar 2026 16:39:57 -0700 Subject: [PATCH] Align backend schema with desktop application --- docker-compose.yml | 1 + .../backend/controller/AuthController.java | 35 --- .../backend/controller/RefundController.java | 27 --- .../backend/dto/auth/RegisterRequest.java | 91 ------- .../backend/dto/refund/RefundItemRequest.java | 52 ---- .../backend/dto/refund/RefundRequest.java | 52 ---- .../backend/dto/refund/RefundResponse.java | 227 ------------------ .../petshop/backend/entity/ActivityLog.java | 90 +++++++ .../com/petshop/backend/entity/Adoption.java | 57 ++--- .../petshop/backend/entity/Appointment.java | 70 ++---- .../com/petshop/backend/entity/Category.java | 40 +-- .../com/petshop/backend/entity/Customer.java | 86 +++---- .../com/petshop/backend/entity/Employee.java | 158 ++++++++++++ .../petshop/backend/entity/EmployeeStore.java | 148 ++++++++++++ .../com/petshop/backend/entity/Inventory.java | 66 +---- .../java/com/petshop/backend/entity/Pet.java | 47 ++-- .../com/petshop/backend/entity/Product.java | 85 +++---- .../backend/entity/ProductSupplier.java | 50 +--- .../petshop/backend/entity/PurchaseOrder.java | 93 ++----- .../com/petshop/backend/entity/Refund.java | 148 ------------ .../petshop/backend/entity/RefundItem.java | 104 -------- .../java/com/petshop/backend/entity/Sale.java | 126 ++++------ .../com/petshop/backend/entity/SaleItem.java | 41 ++-- .../com/petshop/backend/entity/Service.java | 69 +++--- .../petshop/backend/entity/StoreLocation.java | 132 ++++++++++ .../com/petshop/backend/entity/Supplier.java | 115 ++++----- .../java/com/petshop/backend/entity/User.java | 2 +- .../backend/repository/RefundRepository.java | 9 - .../backend/security/SecurityConfig.java | 2 +- .../backend/service/RefundService.java | 121 ---------- src/main/resources/application.yml | 2 +- 31 files changed, 885 insertions(+), 1461 deletions(-) delete mode 100644 src/main/java/com/petshop/backend/controller/RefundController.java delete mode 100644 src/main/java/com/petshop/backend/dto/auth/RegisterRequest.java delete mode 100644 src/main/java/com/petshop/backend/dto/refund/RefundItemRequest.java delete mode 100644 src/main/java/com/petshop/backend/dto/refund/RefundRequest.java delete mode 100644 src/main/java/com/petshop/backend/dto/refund/RefundResponse.java create mode 100644 src/main/java/com/petshop/backend/entity/ActivityLog.java create mode 100644 src/main/java/com/petshop/backend/entity/Employee.java create mode 100644 src/main/java/com/petshop/backend/entity/EmployeeStore.java delete mode 100644 src/main/java/com/petshop/backend/entity/Refund.java delete mode 100644 src/main/java/com/petshop/backend/entity/RefundItem.java create mode 100644 src/main/java/com/petshop/backend/entity/StoreLocation.java delete mode 100644 src/main/java/com/petshop/backend/repository/RefundRepository.java delete mode 100644 src/main/java/com/petshop/backend/service/RefundService.java diff --git a/docker-compose.yml b/docker-compose.yml index f82b2d8e..6eb0cf4e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: - "3306:3306" volumes: - db_data:/var/lib/mysql + - ./sql:/docker-entrypoint-initdb.d healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"] interval: 5s diff --git a/src/main/java/com/petshop/backend/controller/AuthController.java b/src/main/java/com/petshop/backend/controller/AuthController.java index 491c4833..2b1faa98 100644 --- a/src/main/java/com/petshop/backend/controller/AuthController.java +++ b/src/main/java/com/petshop/backend/controller/AuthController.java @@ -2,7 +2,6 @@ package com.petshop.backend.controller; import com.petshop.backend.dto.auth.LoginRequest; import com.petshop.backend.dto.auth.LoginResponse; -import com.petshop.backend.dto.auth.RegisterRequest; import com.petshop.backend.dto.auth.UserInfoResponse; import com.petshop.backend.entity.User; import com.petshop.backend.repository.UserRepository; @@ -39,40 +38,6 @@ public class AuthController { this.passwordEncoder = passwordEncoder; } - @PostMapping("/register") - public ResponseEntity register(@Valid @RequestBody RegisterRequest request) { - if (userRepository.findByUsername(request.getEmail()).isPresent()) { - Map error = new HashMap<>(); - error.put("message", "Email already registered"); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(error); - } - - User user = new User(); - user.setUsername(request.getEmail()); - user.setEmail(request.getEmail()); - user.setPassword(passwordEncoder.encode(request.getPassword())); - user.setFullName(request.getFirstName() + " " + request.getLastName()); - user.setRole(User.Role.CUSTOMER); - user.setActive(true); - - user = userRepository.save(user); - - UserDetails userDetails = new org.springframework.security.core.userdetails.User( - user.getUsername(), - user.getPassword(), - java.util.Collections.emptyList() - ); - - String token = jwtUtil.generateToken(userDetails); - - return ResponseEntity.status(HttpStatus.CREATED).body(new LoginResponse( - token, - user.getUsername(), - user.getFullName(), - user.getRole().name() - )); - } - @PostMapping("/login") public ResponseEntity login(@Valid @RequestBody LoginRequest request) { try { diff --git a/src/main/java/com/petshop/backend/controller/RefundController.java b/src/main/java/com/petshop/backend/controller/RefundController.java deleted file mode 100644 index 1086b9af..00000000 --- a/src/main/java/com/petshop/backend/controller/RefundController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.petshop.backend.controller; - -import com.petshop.backend.dto.refund.RefundRequest; -import com.petshop.backend.dto.refund.RefundResponse; -import com.petshop.backend.service.RefundService; -import jakarta.validation.Valid; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping("/api/v1/sales") -public class RefundController { - - private final RefundService refundService; - - public RefundController(RefundService refundService) { - this.refundService = refundService; - } - - @PostMapping("/{saleId}/refunds") - public ResponseEntity createRefund( - @PathVariable Long saleId, - @Valid @RequestBody RefundRequest request) { - return ResponseEntity.status(HttpStatus.CREATED).body(refundService.createRefund(saleId, request)); - } -} diff --git a/src/main/java/com/petshop/backend/dto/auth/RegisterRequest.java b/src/main/java/com/petshop/backend/dto/auth/RegisterRequest.java deleted file mode 100644 index ae3f5a56..00000000 --- a/src/main/java/com/petshop/backend/dto/auth/RegisterRequest.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.petshop.backend.dto.auth; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import java.util.Objects; - -public class RegisterRequest { - @NotBlank(message = "First name is required") - private String firstName; - - @NotBlank(message = "Last name is required") - private String lastName; - - @NotBlank(message = "Email is required") - @Email(message = "Email must be valid") - private String email; - - @NotBlank(message = "Phone is required") - private String phone; - - @NotBlank(message = "Password is required") - private String password; - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RegisterRequest that = (RegisterRequest) o; - return Objects.equals(firstName, that.firstName) && - Objects.equals(lastName, that.lastName) && - Objects.equals(email, that.email) && - Objects.equals(phone, that.phone) && - Objects.equals(password, that.password); - } - - @Override - public int hashCode() { - return Objects.hash(firstName, lastName, email, phone, password); - } - - @Override - public String toString() { - return "RegisterRequest{" + - "firstName='" + firstName + '\'' + - ", lastName='" + lastName + '\'' + - ", email='" + email + '\'' + - ", phone='" + phone + '\'' + - ", password='[PROTECTED]'" + - '}'; - } -} diff --git a/src/main/java/com/petshop/backend/dto/refund/RefundItemRequest.java b/src/main/java/com/petshop/backend/dto/refund/RefundItemRequest.java deleted file mode 100644 index 5c28c3f3..00000000 --- a/src/main/java/com/petshop/backend/dto/refund/RefundItemRequest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.petshop.backend.dto.refund; - -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Positive; -import java.util.Objects; - -public class RefundItemRequest { - @NotNull(message = "Sale item ID is required") - private Long saleItemId; - - @NotNull(message = "Quantity is required") - @Positive(message = "Quantity must be positive") - private Integer quantity; - - public Long getSaleItemId() { - return saleItemId; - } - - public void setSaleItemId(Long saleItemId) { - this.saleItemId = saleItemId; - } - - public Integer getQuantity() { - return quantity; - } - - public void setQuantity(Integer quantity) { - this.quantity = quantity; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RefundItemRequest that = (RefundItemRequest) o; - return Objects.equals(saleItemId, that.saleItemId) && - Objects.equals(quantity, that.quantity); - } - - @Override - public int hashCode() { - return Objects.hash(saleItemId, quantity); - } - - @Override - public String toString() { - return "RefundItemRequest{" + - "saleItemId=" + saleItemId + - ", quantity=" + quantity + - '}'; - } -} diff --git a/src/main/java/com/petshop/backend/dto/refund/RefundRequest.java b/src/main/java/com/petshop/backend/dto/refund/RefundRequest.java deleted file mode 100644 index 154e838f..00000000 --- a/src/main/java/com/petshop/backend/dto/refund/RefundRequest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.petshop.backend.dto.refund; - -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import java.util.List; -import java.util.Objects; - -public class RefundRequest { - @NotEmpty(message = "At least one item is required") - @Valid - private List items; - - private String refundReason; - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public String getRefundReason() { - return refundReason; - } - - public void setRefundReason(String refundReason) { - this.refundReason = refundReason; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RefundRequest that = (RefundRequest) o; - return Objects.equals(items, that.items) && - Objects.equals(refundReason, that.refundReason); - } - - @Override - public int hashCode() { - return Objects.hash(items, refundReason); - } - - @Override - public String toString() { - return "RefundRequest{" + - "items=" + items + - ", refundReason='" + refundReason + '\'' + - '}'; - } -} diff --git a/src/main/java/com/petshop/backend/dto/refund/RefundResponse.java b/src/main/java/com/petshop/backend/dto/refund/RefundResponse.java deleted file mode 100644 index a502fb25..00000000 --- a/src/main/java/com/petshop/backend/dto/refund/RefundResponse.java +++ /dev/null @@ -1,227 +0,0 @@ -package com.petshop.backend.dto.refund; - -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Objects; - -public class RefundResponse { - private Long id; - private Long saleId; - private LocalDateTime refundDate; - private BigDecimal refundAmount; - private String refundReason; - private Long processedBy; - private String processedByName; - private List items; - private LocalDateTime createdAt; - - public RefundResponse() { - } - - public RefundResponse(Long id, Long saleId, LocalDateTime refundDate, BigDecimal refundAmount, String refundReason, Long processedBy, String processedByName, List items, LocalDateTime createdAt) { - this.id = id; - this.saleId = saleId; - this.refundDate = refundDate; - this.refundAmount = refundAmount; - this.refundReason = refundReason; - this.processedBy = processedBy; - this.processedByName = processedByName; - this.items = items; - this.createdAt = createdAt; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getSaleId() { - return saleId; - } - - public void setSaleId(Long saleId) { - this.saleId = saleId; - } - - public LocalDateTime getRefundDate() { - return refundDate; - } - - public void setRefundDate(LocalDateTime refundDate) { - this.refundDate = refundDate; - } - - public BigDecimal getRefundAmount() { - return refundAmount; - } - - public void setRefundAmount(BigDecimal refundAmount) { - this.refundAmount = refundAmount; - } - - public String getRefundReason() { - return refundReason; - } - - public void setRefundReason(String refundReason) { - this.refundReason = refundReason; - } - - public Long getProcessedBy() { - return processedBy; - } - - public void setProcessedBy(Long processedBy) { - this.processedBy = processedBy; - } - - public String getProcessedByName() { - return processedByName; - } - - public void setProcessedByName(String processedByName) { - this.processedByName = processedByName; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public LocalDateTime getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RefundResponse that = (RefundResponse) o; - return Objects.equals(id, that.id) && Objects.equals(saleId, that.saleId) && Objects.equals(refundDate, that.refundDate) && Objects.equals(refundAmount, that.refundAmount) && Objects.equals(refundReason, that.refundReason) && Objects.equals(processedBy, that.processedBy) && Objects.equals(processedByName, that.processedByName) && Objects.equals(items, that.items) && Objects.equals(createdAt, that.createdAt); - } - - @Override - public int hashCode() { - return Objects.hash(id, saleId, refundDate, refundAmount, refundReason, processedBy, processedByName, items, createdAt); - } - - @Override - public String toString() { - return "RefundResponse{" + - "id=" + id + - ", saleId=" + saleId + - ", refundDate=" + refundDate + - ", refundAmount=" + refundAmount + - ", refundReason='" + refundReason + '\'' + - ", processedBy=" + processedBy + - ", processedByName='" + processedByName + '\'' + - ", items=" + items + - ", createdAt=" + createdAt + - '}'; - } - - public static class RefundItemResponse { - private Long id; - private Long saleItemId; - private Long productId; - private String productName; - private Integer quantity; - private BigDecimal refundAmount; - - public RefundItemResponse() { - } - - public RefundItemResponse(Long id, Long saleItemId, Long productId, String productName, Integer quantity, BigDecimal refundAmount) { - this.id = id; - this.saleItemId = saleItemId; - this.productId = productId; - this.productName = productName; - this.quantity = quantity; - this.refundAmount = refundAmount; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getSaleItemId() { - return saleItemId; - } - - public void setSaleItemId(Long saleItemId) { - this.saleItemId = saleItemId; - } - - public Long getProductId() { - return productId; - } - - public void setProductId(Long productId) { - this.productId = productId; - } - - public String getProductName() { - return productName; - } - - public void setProductName(String productName) { - this.productName = productName; - } - - public Integer getQuantity() { - return quantity; - } - - public void setQuantity(Integer quantity) { - this.quantity = quantity; - } - - public BigDecimal getRefundAmount() { - return refundAmount; - } - - public void setRefundAmount(BigDecimal refundAmount) { - this.refundAmount = refundAmount; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RefundItemResponse that = (RefundItemResponse) o; - return Objects.equals(id, that.id) && Objects.equals(saleItemId, that.saleItemId) && Objects.equals(productId, that.productId) && Objects.equals(productName, that.productName) && Objects.equals(quantity, that.quantity) && Objects.equals(refundAmount, that.refundAmount); - } - - @Override - public int hashCode() { - return Objects.hash(id, saleItemId, productId, productName, quantity, refundAmount); - } - - @Override - public String toString() { - return "RefundItemResponse{" + - "id=" + id + - ", saleItemId=" + saleItemId + - ", productId=" + productId + - ", productName='" + productName + '\'' + - ", quantity=" + quantity + - ", refundAmount=" + refundAmount + - '}'; - } - } -} diff --git a/src/main/java/com/petshop/backend/entity/ActivityLog.java b/src/main/java/com/petshop/backend/entity/ActivityLog.java new file mode 100644 index 00000000..211f75de --- /dev/null +++ b/src/main/java/com/petshop/backend/entity/ActivityLog.java @@ -0,0 +1,90 @@ +package com.petshop.backend.entity; + +import jakarta.persistence.*; + +import java.time.LocalDateTime; +import java.util.Objects; + +@Entity +@Table(name = "activityLog") +public class ActivityLog { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long logId; + + @ManyToOne + @JoinColumn(name = "employeeId", nullable = false) + private Employee employee; + + @Column(nullable = false, columnDefinition = "TEXT") + private String activity; + + @Column(nullable = false) + private LocalDateTime logTimestamp = LocalDateTime.now(); + + public ActivityLog() { + } + + public ActivityLog(Long logId, Employee employee, String activity, LocalDateTime logTimestamp) { + this.logId = logId; + this.employee = employee; + this.activity = activity; + this.logTimestamp = logTimestamp; + } + + public Long getLogId() { + return logId; + } + + public void setLogId(Long logId) { + this.logId = logId; + } + + public Employee getEmployee() { + return employee; + } + + public void setEmployee(Employee employee) { + this.employee = employee; + } + + public String getActivity() { + return activity; + } + + public void setActivity(String activity) { + this.activity = activity; + } + + public LocalDateTime getLogTimestamp() { + return logTimestamp; + } + + public void setLogTimestamp(LocalDateTime logTimestamp) { + this.logTimestamp = logTimestamp; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ActivityLog that = (ActivityLog) o; + return Objects.equals(logId, that.logId); + } + + @Override + public int hashCode() { + return Objects.hash(logId); + } + + @Override + public String toString() { + return "ActivityLog{" + + "logId=" + logId + + ", employee=" + employee + + ", activity='" + activity + '\'' + + ", logTimestamp=" + logTimestamp + + '}'; + } +} diff --git a/src/main/java/com/petshop/backend/entity/Adoption.java b/src/main/java/com/petshop/backend/entity/Adoption.java index da005d5f..84912ba9 100644 --- a/src/main/java/com/petshop/backend/entity/Adoption.java +++ b/src/main/java/com/petshop/backend/entity/Adoption.java @@ -10,29 +10,26 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "adoptions") +@Table(name = "adoption") public class Adoption { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long adoptionId; @ManyToOne - @JoinColumn(name = "pet_id", nullable = false) + @JoinColumn(name = "petId", nullable = false) private Pet pet; @ManyToOne - @JoinColumn(name = "customer_id", nullable = false) + @JoinColumn(name = "customerId", nullable = false) private Customer customer; - @Column(name = "adoption_date", nullable = false) + @Column(nullable = false) private LocalDate adoptionDate; - @Column(name = "adoption_fee", nullable = false, precision = 10, scale = 2) - private BigDecimal adoptionFee; - - @Column(columnDefinition = "TEXT") - private String notes; + @Column(nullable = false, length = 20) + private String adoptionStatus; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -45,23 +42,22 @@ public class Adoption { public Adoption() { } - public Adoption(Long id, Pet pet, Customer customer, LocalDate adoptionDate, BigDecimal adoptionFee, String notes, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public Adoption(Long adoptionId, Pet pet, Customer customer, LocalDate adoptionDate, String adoptionStatus, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.adoptionId = adoptionId; this.pet = pet; this.customer = customer; this.adoptionDate = adoptionDate; - this.adoptionFee = adoptionFee; - this.notes = notes; + this.adoptionStatus = adoptionStatus; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getAdoptionId() { + return adoptionId; } - public void setId(Long id) { - this.id = id; + public void setAdoptionId(Long adoptionId) { + this.adoptionId = adoptionId; } public Pet getPet() { @@ -88,20 +84,12 @@ public class Adoption { this.adoptionDate = adoptionDate; } - public BigDecimal getAdoptionFee() { - return adoptionFee; + public String getAdoptionStatus() { + return adoptionStatus; } - public void setAdoptionFee(BigDecimal adoptionFee) { - this.adoptionFee = adoptionFee; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; + public void setAdoptionStatus(String adoptionStatus) { + this.adoptionStatus = adoptionStatus; } public LocalDateTime getCreatedAt() { @@ -125,23 +113,22 @@ public class Adoption { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Adoption adoption = (Adoption) o; - return Objects.equals(id, adoption.id); + return Objects.equals(adoptionId, adoption.adoptionId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(adoptionId); } @Override public String toString() { return "Adoption{" + - "id=" + id + + "adoptionId=" + adoptionId + ", pet=" + pet + ", customer=" + customer + ", adoptionDate=" + adoptionDate + - ", adoptionFee=" + adoptionFee + - ", notes='" + notes + '\'' + + ", adoptionStatus='" + adoptionStatus + '\'' + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/Appointment.java b/src/main/java/com/petshop/backend/entity/Appointment.java index 358c137b..c31a94ff 100644 --- a/src/main/java/com/petshop/backend/entity/Appointment.java +++ b/src/main/java/com/petshop/backend/entity/Appointment.java @@ -12,39 +12,35 @@ import java.util.Objects; import java.util.Set; @Entity -@Table(name = "appointments") +@Table(name = "appointment") public class Appointment { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long appointmentId; @ManyToOne - @JoinColumn(name = "customer_id", nullable = false) + @JoinColumn(name = "customerId", nullable = false) private Customer customer; @ManyToOne - @JoinColumn(name = "service_id", nullable = false) + @JoinColumn(name = "serviceId", nullable = false) private Service service; - @Column(name = "appointment_date", nullable = false) + @Column(nullable = false) private LocalDate appointmentDate; - @Column(name = "appointment_time", nullable = false) + @Column(nullable = false) private LocalTime appointmentTime; - @Enumerated(EnumType.STRING) - @Column(nullable = false) - private AppointmentStatus status = AppointmentStatus.Scheduled; - - @Column(columnDefinition = "TEXT") - private String notes; + @Column(nullable = false, length = 20) + private String appointmentStatus; @ManyToMany @JoinTable( - name = "appointment_pets", - joinColumns = @JoinColumn(name = "appointment_id"), - inverseJoinColumns = @JoinColumn(name = "pet_id") + name = "appointmentPet", + joinColumns = @JoinColumn(name = "appointmentId"), + inverseJoinColumns = @JoinColumn(name = "petId") ) private Set pets = new HashSet<>(); @@ -56,32 +52,27 @@ public class Appointment { @Column(name = "updated_at") private LocalDateTime updatedAt; - public enum AppointmentStatus { - Scheduled, Completed, Cancelled - } - public Appointment() { } - public Appointment(Long id, Customer customer, Service service, LocalDate appointmentDate, LocalTime appointmentTime, AppointmentStatus status, String notes, Set pets, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public Appointment(Long appointmentId, Customer customer, Service service, LocalDate appointmentDate, LocalTime appointmentTime, String appointmentStatus, Set pets, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.appointmentId = appointmentId; this.customer = customer; this.service = service; this.appointmentDate = appointmentDate; this.appointmentTime = appointmentTime; - this.status = status; - this.notes = notes; + this.appointmentStatus = appointmentStatus; this.pets = pets; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getAppointmentId() { + return appointmentId; } - public void setId(Long id) { - this.id = id; + public void setAppointmentId(Long appointmentId) { + this.appointmentId = appointmentId; } public Customer getCustomer() { @@ -116,20 +107,12 @@ public class Appointment { this.appointmentTime = appointmentTime; } - public AppointmentStatus getStatus() { - return status; + public String getAppointmentStatus() { + return appointmentStatus; } - public void setStatus(AppointmentStatus status) { - this.status = status; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; + public void setAppointmentStatus(String appointmentStatus) { + this.appointmentStatus = appointmentStatus; } public Set getPets() { @@ -161,24 +144,23 @@ public class Appointment { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Appointment that = (Appointment) o; - return Objects.equals(id, that.id); + return Objects.equals(appointmentId, that.appointmentId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(appointmentId); } @Override public String toString() { return "Appointment{" + - "id=" + id + + "appointmentId=" + appointmentId + ", customer=" + customer + ", service=" + service + ", appointmentDate=" + appointmentDate + ", appointmentTime=" + appointmentTime + - ", status=" + status + - ", notes='" + notes + '\'' + + ", appointmentStatus='" + appointmentStatus + '\'' + ", pets=" + pets + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + diff --git a/src/main/java/com/petshop/backend/entity/Category.java b/src/main/java/com/petshop/backend/entity/Category.java index 47a9963a..ee79207e 100644 --- a/src/main/java/com/petshop/backend/entity/Category.java +++ b/src/main/java/com/petshop/backend/entity/Category.java @@ -8,18 +8,18 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "categories") +@Table(name = "category") public class Category { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long categoryId; - @Column(name = "category_name", nullable = false, unique = true, length = 100) + @Column(nullable = false, length = 100) private String categoryName; - @Column(name = "category_description", columnDefinition = "TEXT") - private String categoryDescription; + @Column(nullable = false, length = 50) + private String categoryType; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -32,20 +32,20 @@ public class Category { public Category() { } - public Category(Long id, String categoryName, String categoryDescription, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public Category(Long categoryId, String categoryName, String categoryType, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.categoryId = categoryId; this.categoryName = categoryName; - this.categoryDescription = categoryDescription; + this.categoryType = categoryType; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getCategoryId() { + return categoryId; } - public void setId(Long id) { - this.id = id; + public void setCategoryId(Long categoryId) { + this.categoryId = categoryId; } public String getCategoryName() { @@ -56,12 +56,12 @@ public class Category { this.categoryName = categoryName; } - public String getCategoryDescription() { - return categoryDescription; + public String getCategoryType() { + return categoryType; } - public void setCategoryDescription(String categoryDescription) { - this.categoryDescription = categoryDescription; + public void setCategoryType(String categoryType) { + this.categoryType = categoryType; } public LocalDateTime getCreatedAt() { @@ -85,20 +85,20 @@ public class Category { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Category category = (Category) o; - return Objects.equals(id, category.id); + return Objects.equals(categoryId, category.categoryId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(categoryId); } @Override public String toString() { return "Category{" + - "id=" + id + + "categoryId=" + categoryId + ", categoryName='" + categoryName + '\'' + - ", categoryDescription='" + categoryDescription + '\'' + + ", categoryType='" + categoryType + '\'' + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/Customer.java b/src/main/java/com/petshop/backend/entity/Customer.java index b0b319a6..661f9d80 100644 --- a/src/main/java/com/petshop/backend/entity/Customer.java +++ b/src/main/java/com/petshop/backend/entity/Customer.java @@ -8,24 +8,24 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "customers") +@Table(name = "customer") public class Customer { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long customerId; - @Column(name = "customer_name", nullable = false, length = 100) - private String customerName; + @Column(nullable = false, length = 50) + private String firstName; - @Column(name = "customer_email", length = 100) - private String customerEmail; + @Column(nullable = false, length = 50) + private String lastName; - @Column(name = "customer_phone", length = 20) - private String customerPhone; + @Column(nullable = false, length = 100) + private String email; - @Column(name = "customer_address", columnDefinition = "TEXT") - private String customerAddress; + @Column(nullable = false, length = 20) + private String phone; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -38,54 +38,54 @@ public class Customer { public Customer() { } - public Customer(Long id, String customerName, String customerEmail, String customerPhone, String customerAddress, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; - this.customerName = customerName; - this.customerEmail = customerEmail; - this.customerPhone = customerPhone; - this.customerAddress = customerAddress; + public Customer(Long customerId, String firstName, String lastName, String email, String phone, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.customerId = customerId; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.phone = phone; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getCustomerId() { + return customerId; } - public void setId(Long id) { - this.id = id; + public void setCustomerId(Long customerId) { + this.customerId = customerId; } - public String getCustomerName() { - return customerName; + public String getFirstName() { + return firstName; } - public void setCustomerName(String customerName) { - this.customerName = customerName; + public void setFirstName(String firstName) { + this.firstName = firstName; } - public String getCustomerEmail() { - return customerEmail; + public String getLastName() { + return lastName; } - public void setCustomerEmail(String customerEmail) { - this.customerEmail = customerEmail; + public void setLastName(String lastName) { + this.lastName = lastName; } - public String getCustomerPhone() { - return customerPhone; + public String getEmail() { + return email; } - public void setCustomerPhone(String customerPhone) { - this.customerPhone = customerPhone; + public void setEmail(String email) { + this.email = email; } - public String getCustomerAddress() { - return customerAddress; + public String getPhone() { + return phone; } - public void setCustomerAddress(String customerAddress) { - this.customerAddress = customerAddress; + public void setPhone(String phone) { + this.phone = phone; } public LocalDateTime getCreatedAt() { @@ -109,22 +109,22 @@ public class Customer { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Customer customer = (Customer) o; - return Objects.equals(id, customer.id); + return Objects.equals(customerId, customer.customerId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(customerId); } @Override public String toString() { return "Customer{" + - "id=" + id + - ", customerName='" + customerName + '\'' + - ", customerEmail='" + customerEmail + '\'' + - ", customerPhone='" + customerPhone + '\'' + - ", customerAddress='" + customerAddress + '\'' + + "customerId=" + customerId + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", email='" + email + '\'' + + ", phone='" + phone + '\'' + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/Employee.java b/src/main/java/com/petshop/backend/entity/Employee.java new file mode 100644 index 00000000..573a446f --- /dev/null +++ b/src/main/java/com/petshop/backend/entity/Employee.java @@ -0,0 +1,158 @@ +package com.petshop.backend.entity; + +import jakarta.persistence.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.LocalDateTime; +import java.util.Objects; + +@Entity +@Table(name = "employee") +public class Employee { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long employeeId; + + @Column(nullable = false, length = 50) + private String firstName; + + @Column(nullable = false, length = 50) + private String lastName; + + @Column(nullable = false, length = 100) + private String email; + + @Column(nullable = false, length = 20) + private String phone; + + @Column(nullable = false, length = 50) + private String role; + + @Column(nullable = false) + private Boolean isActive = true; + + @CreationTimestamp + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + public Employee() { + } + + public Employee(Long employeeId, String firstName, String lastName, String email, String phone, String role, Boolean isActive, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.employeeId = employeeId; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.phone = phone; + this.role = role; + this.isActive = isActive; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public Long getEmployeeId() { + return employeeId; + } + + public void setEmployeeId(Long employeeId) { + this.employeeId = employeeId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public Boolean getIsActive() { + return isActive; + } + + public void setIsActive(Boolean isActive) { + this.isActive = isActive; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Employee employee = (Employee) o; + return Objects.equals(employeeId, employee.employeeId); + } + + @Override + public int hashCode() { + return Objects.hash(employeeId); + } + + @Override + public String toString() { + return "Employee{" + + "employeeId=" + employeeId + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", email='" + email + '\'' + + ", phone='" + phone + '\'' + + ", role='" + role + '\'' + + ", isActive=" + isActive + + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + + '}'; + } +} diff --git a/src/main/java/com/petshop/backend/entity/EmployeeStore.java b/src/main/java/com/petshop/backend/entity/EmployeeStore.java new file mode 100644 index 00000000..d6d29b98 --- /dev/null +++ b/src/main/java/com/petshop/backend/entity/EmployeeStore.java @@ -0,0 +1,148 @@ +package com.petshop.backend.entity; + +import jakarta.persistence.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Objects; + +@Entity +@Table(name = "employeeStore") +@IdClass(EmployeeStore.EmployeeStoreId.class) +public class EmployeeStore { + + @Id + @ManyToOne + @JoinColumn(name = "employeeId", nullable = false) + private Employee employee; + + @Id + @ManyToOne + @JoinColumn(name = "storeId", nullable = false) + private StoreLocation store; + + @CreationTimestamp + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + public EmployeeStore() { + } + + public EmployeeStore(Employee employee, StoreLocation store, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.employee = employee; + this.store = store; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public Employee getEmployee() { + return employee; + } + + public void setEmployee(Employee employee) { + this.employee = employee; + } + + public StoreLocation getStore() { + return store; + } + + public void setStore(StoreLocation store) { + this.store = store; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EmployeeStore that = (EmployeeStore) o; + return Objects.equals(employee, that.employee) && Objects.equals(store, that.store); + } + + @Override + public int hashCode() { + return Objects.hash(employee, store); + } + + @Override + public String toString() { + return "EmployeeStore{" + + "employee=" + employee + + ", store=" + store + + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + + '}'; + } + + public static class EmployeeStoreId implements Serializable { + private Long employee; + private Long store; + + public EmployeeStoreId() { + } + + public EmployeeStoreId(Long employee, Long store) { + this.employee = employee; + this.store = store; + } + + public Long getEmployee() { + return employee; + } + + public void setEmployee(Long employee) { + this.employee = employee; + } + + public Long getStore() { + return store; + } + + public void setStore(Long store) { + this.store = store; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EmployeeStoreId that = (EmployeeStoreId) o; + return Objects.equals(employee, that.employee) && Objects.equals(store, that.store); + } + + @Override + public int hashCode() { + return Objects.hash(employee, store); + } + + @Override + public String toString() { + return "EmployeeStoreId{" + + "employee=" + employee + + ", store=" + store + + '}'; + } + } +} diff --git a/src/main/java/com/petshop/backend/entity/Inventory.java b/src/main/java/com/petshop/backend/entity/Inventory.java index 4b167c91..07b93501 100644 --- a/src/main/java/com/petshop/backend/entity/Inventory.java +++ b/src/main/java/com/petshop/backend/entity/Inventory.java @@ -8,32 +8,20 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "inventory", uniqueConstraints = { - @UniqueConstraint(name = "unique_product_store", columnNames = {"product_id", "store_id"}) -}) +@Table(name = "inventory") public class Inventory { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long inventoryId; @ManyToOne - @JoinColumn(name = "product_id", nullable = false) + @JoinColumn(name = "prodId", nullable = false) private Product product; - @ManyToOne - @JoinColumn(name = "store_id", nullable = true) - private Store store; - @Column(nullable = false) private Integer quantity = 0; - @Column(name = "reorder_level") - private Integer reorderLevel = 10; - - @Column(name = "last_restocked") - private LocalDateTime lastRestocked; - @CreationTimestamp @Column(name = "created_at", updatable = false) private LocalDateTime createdAt; @@ -45,23 +33,20 @@ public class Inventory { public Inventory() { } - public Inventory(Long id, Product product, Store store, Integer quantity, Integer reorderLevel, LocalDateTime lastRestocked, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public Inventory(Long inventoryId, Product product, Integer quantity, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.inventoryId = inventoryId; this.product = product; - this.store = store; this.quantity = quantity; - this.reorderLevel = reorderLevel; - this.lastRestocked = lastRestocked; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getInventoryId() { + return inventoryId; } - public void setId(Long id) { - this.id = id; + public void setInventoryId(Long inventoryId) { + this.inventoryId = inventoryId; } public Product getProduct() { @@ -72,14 +57,6 @@ public class Inventory { this.product = product; } - public Store getStore() { - return store; - } - - public void setStore(Store store) { - this.store = store; - } - public Integer getQuantity() { return quantity; } @@ -88,22 +65,6 @@ public class Inventory { this.quantity = quantity; } - public Integer getReorderLevel() { - return reorderLevel; - } - - public void setReorderLevel(Integer reorderLevel) { - this.reorderLevel = reorderLevel; - } - - public LocalDateTime getLastRestocked() { - return lastRestocked; - } - - public void setLastRestocked(LocalDateTime lastRestocked) { - this.lastRestocked = lastRestocked; - } - public LocalDateTime getCreatedAt() { return createdAt; } @@ -125,23 +86,20 @@ public class Inventory { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Inventory inventory = (Inventory) o; - return Objects.equals(id, inventory.id); + return Objects.equals(inventoryId, inventory.inventoryId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(inventoryId); } @Override public String toString() { return "Inventory{" + - "id=" + id + + "inventoryId=" + inventoryId + ", product=" + product + - ", store=" + store + ", quantity=" + quantity + - ", reorderLevel=" + reorderLevel + - ", lastRestocked=" + lastRestocked + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/Pet.java b/src/main/java/com/petshop/backend/entity/Pet.java index 61abe2c0..cbbb1f90 100644 --- a/src/main/java/com/petshop/backend/entity/Pet.java +++ b/src/main/java/com/petshop/backend/entity/Pet.java @@ -9,30 +9,29 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "pets") +@Table(name = "pet") public class Pet { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long petId; - @Column(name = "pet_name", nullable = false, length = 100) + @Column(nullable = false, length = 50) private String petName; - @Column(name = "pet_species", nullable = false, length = 50) + @Column(nullable = false, length = 50) private String petSpecies; - @Column(name = "pet_breed", length = 50) + @Column(nullable = false, length = 50) private String petBreed; - @Column(name = "pet_age") + @Column(nullable = false) private Integer petAge; - @Enumerated(EnumType.STRING) - @Column(name = "pet_status", nullable = false) - private PetStatus petStatus = PetStatus.AVAILABLE; + @Column(nullable = false, length = 20) + private String petStatus; - @Column(name = "pet_price", precision = 10, scale = 2) + @Column(nullable = false, precision = 10, scale = 2) private BigDecimal petPrice; @CreationTimestamp @@ -43,15 +42,11 @@ public class Pet { @Column(name = "updated_at") private LocalDateTime updatedAt; - public enum PetStatus { - AVAILABLE, ADOPTED, UNDER_CARE - } - public Pet() { } - public Pet(Long id, String petName, String petSpecies, String petBreed, Integer petAge, PetStatus petStatus, BigDecimal petPrice, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public Pet(Long petId, String petName, String petSpecies, String petBreed, Integer petAge, String petStatus, BigDecimal petPrice, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.petId = petId; this.petName = petName; this.petSpecies = petSpecies; this.petBreed = petBreed; @@ -62,12 +57,12 @@ public class Pet { this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getPetId() { + return petId; } - public void setId(Long id) { - this.id = id; + public void setPetId(Long petId) { + this.petId = petId; } public String getPetName() { @@ -102,11 +97,11 @@ public class Pet { this.petAge = petAge; } - public PetStatus getPetStatus() { + public String getPetStatus() { return petStatus; } - public void setPetStatus(PetStatus petStatus) { + public void setPetStatus(String petStatus) { this.petStatus = petStatus; } @@ -139,23 +134,23 @@ public class Pet { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pet pet = (Pet) o; - return Objects.equals(id, pet.id); + return Objects.equals(petId, pet.petId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(petId); } @Override public String toString() { return "Pet{" + - "id=" + id + + "petId=" + petId + ", petName='" + petName + '\'' + ", petSpecies='" + petSpecies + '\'' + ", petBreed='" + petBreed + '\'' + ", petAge=" + petAge + - ", petStatus=" + petStatus + + ", petStatus='" + petStatus + '\'' + ", petPrice=" + petPrice + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + diff --git a/src/main/java/com/petshop/backend/entity/Product.java b/src/main/java/com/petshop/backend/entity/Product.java index 2a3e0dd9..9eb9c2d6 100644 --- a/src/main/java/com/petshop/backend/entity/Product.java +++ b/src/main/java/com/petshop/backend/entity/Product.java @@ -9,28 +9,25 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "products") +@Table(name = "product") public class Product { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long prodId; - @Column(name = "product_name", nullable = false, length = 100) - private String productName; + @Column(nullable = false, length = 100) + private String prodName; @ManyToOne - @JoinColumn(name = "category_id", nullable = false) + @JoinColumn(name = "categoryId", nullable = false) private Category category; - @Column(name = "product_description", columnDefinition = "TEXT") - private String productDescription; + @Column(columnDefinition = "TEXT") + private String prodDesc; - @Column(name = "product_price", nullable = false, precision = 10, scale = 2) - private BigDecimal productPrice; - - @Column(nullable = false) - private Boolean active = true; + @Column(nullable = false, precision = 10, scale = 2) + private BigDecimal prodPrice; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -43,31 +40,30 @@ public class Product { public Product() { } - public Product(Long id, String productName, Category category, String productDescription, BigDecimal productPrice, Boolean active, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; - this.productName = productName; + public Product(Long prodId, String prodName, Category category, String prodDesc, BigDecimal prodPrice, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.prodId = prodId; + this.prodName = prodName; this.category = category; - this.productDescription = productDescription; - this.productPrice = productPrice; - this.active = active; + this.prodDesc = prodDesc; + this.prodPrice = prodPrice; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getProdId() { + return prodId; } - public void setId(Long id) { - this.id = id; + public void setProdId(Long prodId) { + this.prodId = prodId; } - public String getProductName() { - return productName; + public String getProdName() { + return prodName; } - public void setProductName(String productName) { - this.productName = productName; + public void setProdName(String prodName) { + this.prodName = prodName; } public Category getCategory() { @@ -78,28 +74,20 @@ public class Product { this.category = category; } - public String getProductDescription() { - return productDescription; + public String getProdDesc() { + return prodDesc; } - public void setProductDescription(String productDescription) { - this.productDescription = productDescription; + public void setProdDesc(String prodDesc) { + this.prodDesc = prodDesc; } - public BigDecimal getProductPrice() { - return productPrice; + public BigDecimal getProdPrice() { + return prodPrice; } - public void setProductPrice(BigDecimal productPrice) { - this.productPrice = productPrice; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; + public void setProdPrice(BigDecimal prodPrice) { + this.prodPrice = prodPrice; } public LocalDateTime getCreatedAt() { @@ -123,23 +111,22 @@ public class Product { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Product product = (Product) o; - return Objects.equals(id, product.id); + return Objects.equals(prodId, product.prodId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(prodId); } @Override public String toString() { return "Product{" + - "id=" + id + - ", productName='" + productName + '\'' + + "prodId=" + prodId + + ", prodName='" + prodName + '\'' + ", category=" + category + - ", productDescription='" + productDescription + '\'' + - ", productPrice=" + productPrice + - ", active=" + active + + ", prodDesc='" + prodDesc + '\'' + + ", prodPrice=" + prodPrice + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/ProductSupplier.java b/src/main/java/com/petshop/backend/entity/ProductSupplier.java index b9758404..95aa6017 100644 --- a/src/main/java/com/petshop/backend/entity/ProductSupplier.java +++ b/src/main/java/com/petshop/backend/entity/ProductSupplier.java @@ -10,28 +10,22 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "product_suppliers") +@Table(name = "productSupplier") @IdClass(ProductSupplier.ProductSupplierId.class) public class ProductSupplier { @Id @ManyToOne - @JoinColumn(name = "product_id", nullable = false) + @JoinColumn(name = "prodId", nullable = false) private Product product; @Id @ManyToOne - @JoinColumn(name = "supplier_id", nullable = false) + @JoinColumn(name = "supId", nullable = false) private Supplier supplier; - @Column(name = "cost_price", nullable = false, precision = 10, scale = 2) - private BigDecimal costPrice; - - @Column(name = "lead_time_days") - private Integer leadTimeDays; - - @Column(name = "is_preferred") - private Boolean isPreferred = false; + @Column(nullable = false, precision = 10, scale = 2) + private BigDecimal cost; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -44,12 +38,10 @@ public class ProductSupplier { public ProductSupplier() { } - public ProductSupplier(Product product, Supplier supplier, BigDecimal costPrice, Integer leadTimeDays, Boolean isPreferred, LocalDateTime createdAt, LocalDateTime updatedAt) { + public ProductSupplier(Product product, Supplier supplier, BigDecimal cost, LocalDateTime createdAt, LocalDateTime updatedAt) { this.product = product; this.supplier = supplier; - this.costPrice = costPrice; - this.leadTimeDays = leadTimeDays; - this.isPreferred = isPreferred; + this.cost = cost; this.createdAt = createdAt; this.updatedAt = updatedAt; } @@ -70,28 +62,12 @@ public class ProductSupplier { this.supplier = supplier; } - public BigDecimal getCostPrice() { - return costPrice; + public BigDecimal getCost() { + return cost; } - public void setCostPrice(BigDecimal costPrice) { - this.costPrice = costPrice; - } - - public Integer getLeadTimeDays() { - return leadTimeDays; - } - - public void setLeadTimeDays(Integer leadTimeDays) { - this.leadTimeDays = leadTimeDays; - } - - public Boolean getIsPreferred() { - return isPreferred; - } - - public void setIsPreferred(Boolean isPreferred) { - this.isPreferred = isPreferred; + public void setCost(BigDecimal cost) { + this.cost = cost; } public LocalDateTime getCreatedAt() { @@ -128,9 +104,7 @@ public class ProductSupplier { return "ProductSupplier{" + "product=" + product + ", supplier=" + supplier + - ", costPrice=" + costPrice + - ", leadTimeDays=" + leadTimeDays + - ", isPreferred=" + isPreferred + + ", cost=" + cost + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/PurchaseOrder.java b/src/main/java/com/petshop/backend/entity/PurchaseOrder.java index 3a63683f..76fc9a9d 100644 --- a/src/main/java/com/petshop/backend/entity/PurchaseOrder.java +++ b/src/main/java/com/petshop/backend/entity/PurchaseOrder.java @@ -12,35 +12,22 @@ import java.util.List; import java.util.Objects; @Entity -@Table(name = "purchase_orders") +@Table(name = "purchaseOrder") public class PurchaseOrder { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long purchaseOrderId; @ManyToOne - @JoinColumn(name = "supplier_id", nullable = false) + @JoinColumn(name = "supId", nullable = false) private Supplier supplier; - @Column(name = "order_date", nullable = false) + @Column(nullable = false) private LocalDate orderDate; - @Column(name = "expected_delivery") - private LocalDate expectedDelivery; - - @Enumerated(EnumType.STRING) - @Column(nullable = false) - private OrderStatus status = OrderStatus.Pending; - - @Column(name = "total_amount", nullable = false, precision = 10, scale = 2) - private BigDecimal totalAmount; - - @Column(columnDefinition = "TEXT") - private String notes; - - @OneToMany(mappedBy = "purchaseOrder", cascade = CascadeType.ALL) - private List items = new ArrayList<>(); + @Column(nullable = false, length = 50) + private String status; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -50,32 +37,24 @@ public class PurchaseOrder { @Column(name = "updated_at") private LocalDateTime updatedAt; - public enum OrderStatus { - Pending, Delivered, Cancelled - } - public PurchaseOrder() { } - public PurchaseOrder(Long id, Supplier supplier, LocalDate orderDate, LocalDate expectedDelivery, OrderStatus status, BigDecimal totalAmount, String notes, List items, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public PurchaseOrder(Long purchaseOrderId, Supplier supplier, LocalDate orderDate, String status, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.purchaseOrderId = purchaseOrderId; this.supplier = supplier; this.orderDate = orderDate; - this.expectedDelivery = expectedDelivery; this.status = status; - this.totalAmount = totalAmount; - this.notes = notes; - this.items = items; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getPurchaseOrderId() { + return purchaseOrderId; } - public void setId(Long id) { - this.id = id; + public void setPurchaseOrderId(Long purchaseOrderId) { + this.purchaseOrderId = purchaseOrderId; } public Supplier getSupplier() { @@ -94,46 +73,14 @@ public class PurchaseOrder { this.orderDate = orderDate; } - public LocalDate getExpectedDelivery() { - return expectedDelivery; - } - - public void setExpectedDelivery(LocalDate expectedDelivery) { - this.expectedDelivery = expectedDelivery; - } - - public OrderStatus getStatus() { + public String getStatus() { return status; } - public void setStatus(OrderStatus status) { + public void setStatus(String status) { this.status = status; } - public BigDecimal getTotalAmount() { - return totalAmount; - } - - public void setTotalAmount(BigDecimal totalAmount) { - this.totalAmount = totalAmount; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - public LocalDateTime getCreatedAt() { return createdAt; } @@ -155,25 +102,21 @@ public class PurchaseOrder { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PurchaseOrder that = (PurchaseOrder) o; - return Objects.equals(id, that.id); + return Objects.equals(purchaseOrderId, that.purchaseOrderId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(purchaseOrderId); } @Override public String toString() { return "PurchaseOrder{" + - "id=" + id + + "purchaseOrderId=" + purchaseOrderId + ", supplier=" + supplier + ", orderDate=" + orderDate + - ", expectedDelivery=" + expectedDelivery + - ", status=" + status + - ", totalAmount=" + totalAmount + - ", notes='" + notes + '\'' + - ", items=" + items + + ", status='" + status + '\'' + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/Refund.java b/src/main/java/com/petshop/backend/entity/Refund.java deleted file mode 100644 index 8fe89c9a..00000000 --- a/src/main/java/com/petshop/backend/entity/Refund.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.petshop.backend.entity; - -import jakarta.persistence.*; -import org.hibernate.annotations.CreationTimestamp; - -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -@Entity -@Table(name = "refunds") -public class Refund { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne - @JoinColumn(name = "sale_id", nullable = false) - private Sale sale; - - @Column(name = "refund_date", nullable = false) - private LocalDateTime refundDate = LocalDateTime.now(); - - @Column(name = "refund_amount", nullable = false, precision = 10, scale = 2) - private BigDecimal refundAmount; - - @Column(name = "refund_reason", columnDefinition = "TEXT") - private String refundReason; - - @ManyToOne - @JoinColumn(name = "processed_by", nullable = false) - private User processedBy; - - @OneToMany(mappedBy = "refund", cascade = CascadeType.ALL) - private List items = new ArrayList<>(); - - @CreationTimestamp - @Column(name = "created_at", updatable = false) - private LocalDateTime createdAt; - - public Refund() { - } - - public Refund(Long id, Sale sale, LocalDateTime refundDate, BigDecimal refundAmount, String refundReason, User processedBy, List items, LocalDateTime createdAt) { - this.id = id; - this.sale = sale; - this.refundDate = refundDate; - this.refundAmount = refundAmount; - this.refundReason = refundReason; - this.processedBy = processedBy; - this.items = items; - this.createdAt = createdAt; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Sale getSale() { - return sale; - } - - public void setSale(Sale sale) { - this.sale = sale; - } - - public LocalDateTime getRefundDate() { - return refundDate; - } - - public void setRefundDate(LocalDateTime refundDate) { - this.refundDate = refundDate; - } - - public BigDecimal getRefundAmount() { - return refundAmount; - } - - public void setRefundAmount(BigDecimal refundAmount) { - this.refundAmount = refundAmount; - } - - public String getRefundReason() { - return refundReason; - } - - public void setRefundReason(String refundReason) { - this.refundReason = refundReason; - } - - public User getProcessedBy() { - return processedBy; - } - - public void setProcessedBy(User processedBy) { - this.processedBy = processedBy; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public LocalDateTime getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Refund refund = (Refund) o; - return Objects.equals(id, refund.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "Refund{" + - "id=" + id + - ", sale=" + sale + - ", refundDate=" + refundDate + - ", refundAmount=" + refundAmount + - ", refundReason='" + refundReason + '\'' + - ", processedBy=" + processedBy + - ", items=" + items + - ", createdAt=" + createdAt + - '}'; - } -} diff --git a/src/main/java/com/petshop/backend/entity/RefundItem.java b/src/main/java/com/petshop/backend/entity/RefundItem.java deleted file mode 100644 index 1724679a..00000000 --- a/src/main/java/com/petshop/backend/entity/RefundItem.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.petshop.backend.entity; - -import jakarta.persistence.*; - -import java.math.BigDecimal; -import java.util.Objects; - -@Entity -@Table(name = "refund_items") -public class RefundItem { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne - @JoinColumn(name = "refund_id", nullable = false) - private Refund refund; - - @ManyToOne - @JoinColumn(name = "sale_item_id", nullable = false) - private SaleItem saleItem; - - @Column(nullable = false) - private Integer quantity; - - @Column(name = "refund_amount", nullable = false, precision = 10, scale = 2) - private BigDecimal refundAmount; - - public RefundItem() { - } - - public RefundItem(Long id, Refund refund, SaleItem saleItem, Integer quantity, BigDecimal refundAmount) { - this.id = id; - this.refund = refund; - this.saleItem = saleItem; - this.quantity = quantity; - this.refundAmount = refundAmount; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Refund getRefund() { - return refund; - } - - public void setRefund(Refund refund) { - this.refund = refund; - } - - public SaleItem getSaleItem() { - return saleItem; - } - - public void setSaleItem(SaleItem saleItem) { - this.saleItem = saleItem; - } - - public Integer getQuantity() { - return quantity; - } - - public void setQuantity(Integer quantity) { - this.quantity = quantity; - } - - public BigDecimal getRefundAmount() { - return refundAmount; - } - - public void setRefundAmount(BigDecimal refundAmount) { - this.refundAmount = refundAmount; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RefundItem that = (RefundItem) o; - return Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "RefundItem{" + - "id=" + id + - ", refund=" + refund + - ", saleItem=" + saleItem + - ", quantity=" + quantity + - ", refundAmount=" + refundAmount + - '}'; - } -} diff --git a/src/main/java/com/petshop/backend/entity/Sale.java b/src/main/java/com/petshop/backend/entity/Sale.java index fc1e8765..1874d439 100644 --- a/src/main/java/com/petshop/backend/entity/Sale.java +++ b/src/main/java/com/petshop/backend/entity/Sale.java @@ -10,42 +10,36 @@ import java.util.List; import java.util.Objects; @Entity -@Table(name = "sales") +@Table(name = "sale") public class Sale { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long saleId; - @Column(name = "sale_date", nullable = false) + @Column(nullable = false) private LocalDateTime saleDate = LocalDateTime.now(); @ManyToOne - @JoinColumn(name = "employee_id", nullable = false) - private User employee; + @JoinColumn(name = "employeeId", nullable = false) + private Employee employee; @ManyToOne - @JoinColumn(name = "customer_id") - private Customer customer; - - @ManyToOne - @JoinColumn(name = "store_id") - private Store store; + @JoinColumn(name = "storeId", nullable = false) + private StoreLocation store; @Column(nullable = false, precision = 10, scale = 2) - private BigDecimal subtotal; + private BigDecimal totalAmount; - @Column(nullable = false, precision = 10, scale = 2) - private BigDecimal tax = BigDecimal.ZERO; - - @Column(nullable = false, precision = 10, scale = 2) - private BigDecimal total; - - @Column(name = "payment_method", length = 50) + @Column(nullable = false, length = 50) private String paymentMethod; - @Column(columnDefinition = "TEXT") - private String notes; + @Column(nullable = false) + private Boolean isRefund = false; + + @ManyToOne + @JoinColumn(name = "originalSaleId") + private Sale originalSale; @OneToMany(mappedBy = "sale", cascade = CascadeType.ALL) private List items = new ArrayList<>(); @@ -57,27 +51,25 @@ public class Sale { public Sale() { } - public Sale(Long id, LocalDateTime saleDate, User employee, Customer customer, Store store, BigDecimal subtotal, BigDecimal tax, BigDecimal total, String paymentMethod, String notes, List items, LocalDateTime createdAt) { - this.id = id; + public Sale(Long saleId, LocalDateTime saleDate, Employee employee, StoreLocation store, BigDecimal totalAmount, String paymentMethod, Boolean isRefund, Sale originalSale, List items, LocalDateTime createdAt) { + this.saleId = saleId; this.saleDate = saleDate; this.employee = employee; - this.customer = customer; this.store = store; - this.subtotal = subtotal; - this.tax = tax; - this.total = total; + this.totalAmount = totalAmount; this.paymentMethod = paymentMethod; - this.notes = notes; + this.isRefund = isRefund; + this.originalSale = originalSale; this.items = items; this.createdAt = createdAt; } - public Long getId() { - return id; + public Long getSaleId() { + return saleId; } - public void setId(Long id) { - this.id = id; + public void setSaleId(Long saleId) { + this.saleId = saleId; } public LocalDateTime getSaleDate() { @@ -88,52 +80,28 @@ public class Sale { this.saleDate = saleDate; } - public User getEmployee() { + public Employee getEmployee() { return employee; } - public void setEmployee(User employee) { + public void setEmployee(Employee employee) { this.employee = employee; } - public Customer getCustomer() { - return customer; - } - - public void setCustomer(Customer customer) { - this.customer = customer; - } - - public Store getStore() { + public StoreLocation getStore() { return store; } - public void setStore(Store store) { + public void setStore(StoreLocation store) { this.store = store; } - public BigDecimal getSubtotal() { - return subtotal; + public BigDecimal getTotalAmount() { + return totalAmount; } - public void setSubtotal(BigDecimal subtotal) { - this.subtotal = subtotal; - } - - public BigDecimal getTax() { - return tax; - } - - public void setTax(BigDecimal tax) { - this.tax = tax; - } - - public BigDecimal getTotal() { - return total; - } - - public void setTotal(BigDecimal total) { - this.total = total; + public void setTotalAmount(BigDecimal totalAmount) { + this.totalAmount = totalAmount; } public String getPaymentMethod() { @@ -144,12 +112,20 @@ public class Sale { this.paymentMethod = paymentMethod; } - public String getNotes() { - return notes; + public Boolean getIsRefund() { + return isRefund; } - public void setNotes(String notes) { - this.notes = notes; + public void setIsRefund(Boolean isRefund) { + this.isRefund = isRefund; + } + + public Sale getOriginalSale() { + return originalSale; + } + + public void setOriginalSale(Sale originalSale) { + this.originalSale = originalSale; } public List getItems() { @@ -173,27 +149,25 @@ public class Sale { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Sale sale = (Sale) o; - return Objects.equals(id, sale.id); + return Objects.equals(saleId, sale.saleId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(saleId); } @Override public String toString() { return "Sale{" + - "id=" + id + + "saleId=" + saleId + ", saleDate=" + saleDate + ", employee=" + employee + - ", customer=" + customer + ", store=" + store + - ", subtotal=" + subtotal + - ", tax=" + tax + - ", total=" + total + + ", totalAmount=" + totalAmount + ", paymentMethod='" + paymentMethod + '\'' + - ", notes='" + notes + '\'' + + ", isRefund=" + isRefund + + ", originalSale=" + originalSale + ", items=" + items + ", createdAt=" + createdAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/SaleItem.java b/src/main/java/com/petshop/backend/entity/SaleItem.java index 5b883f4c..3738b29a 100644 --- a/src/main/java/com/petshop/backend/entity/SaleItem.java +++ b/src/main/java/com/petshop/backend/entity/SaleItem.java @@ -6,48 +6,44 @@ import java.math.BigDecimal; import java.util.Objects; @Entity -@Table(name = "sale_items") +@Table(name = "saleItem") public class SaleItem { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long saleItemId; @ManyToOne - @JoinColumn(name = "sale_id", nullable = false) + @JoinColumn(name = "saleId", nullable = false) private Sale sale; @ManyToOne - @JoinColumn(name = "product_id", nullable = false) + @JoinColumn(name = "prodId", nullable = false) private Product product; @Column(nullable = false) private Integer quantity; - @Column(name = "unit_price", nullable = false, precision = 10, scale = 2) - private BigDecimal unitPrice; - @Column(nullable = false, precision = 10, scale = 2) - private BigDecimal subtotal; + private BigDecimal unitPrice; public SaleItem() { } - public SaleItem(Long id, Sale sale, Product product, Integer quantity, BigDecimal unitPrice, BigDecimal subtotal) { - this.id = id; + public SaleItem(Long saleItemId, Sale sale, Product product, Integer quantity, BigDecimal unitPrice) { + this.saleItemId = saleItemId; this.sale = sale; this.product = product; this.quantity = quantity; this.unitPrice = unitPrice; - this.subtotal = subtotal; } - public Long getId() { - return id; + public Long getSaleItemId() { + return saleItemId; } - public void setId(Long id) { - this.id = id; + public void setSaleItemId(Long saleItemId) { + this.saleItemId = saleItemId; } public Sale getSale() { @@ -82,36 +78,27 @@ public class SaleItem { this.unitPrice = unitPrice; } - public BigDecimal getSubtotal() { - return subtotal; - } - - public void setSubtotal(BigDecimal subtotal) { - this.subtotal = subtotal; - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SaleItem saleItem = (SaleItem) o; - return Objects.equals(id, saleItem.id); + return Objects.equals(saleItemId, saleItem.saleItemId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(saleItemId); } @Override public String toString() { return "SaleItem{" + - "id=" + id + + "saleItemId=" + saleItemId + ", sale=" + sale + ", product=" + product + ", quantity=" + quantity + ", unitPrice=" + unitPrice + - ", subtotal=" + subtotal + '}'; } } diff --git a/src/main/java/com/petshop/backend/entity/Service.java b/src/main/java/com/petshop/backend/entity/Service.java index e3148cd9..a73387c8 100644 --- a/src/main/java/com/petshop/backend/entity/Service.java +++ b/src/main/java/com/petshop/backend/entity/Service.java @@ -9,27 +9,24 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "services") +@Table(name = "service") public class Service { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long serviceId; - @Column(name = "service_name", nullable = false, length = 100) + @Column(nullable = false, length = 100) private String serviceName; - @Column(name = "service_description", columnDefinition = "TEXT") - private String serviceDescription; + @Column(columnDefinition = "TEXT") + private String serviceDesc; - @Column(name = "service_price", nullable = false, precision = 10, scale = 2) + @Column(nullable = false, precision = 10, scale = 2) private BigDecimal servicePrice; - @Column(name = "service_duration_minutes") - private Integer serviceDurationMinutes; - @Column(nullable = false) - private Boolean active = true; + private Integer serviceDuration; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -42,23 +39,22 @@ public class Service { public Service() { } - public Service(Long id, String serviceName, String serviceDescription, BigDecimal servicePrice, Integer serviceDurationMinutes, Boolean active, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; + public Service(Long serviceId, String serviceName, String serviceDesc, BigDecimal servicePrice, Integer serviceDuration, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.serviceId = serviceId; this.serviceName = serviceName; - this.serviceDescription = serviceDescription; + this.serviceDesc = serviceDesc; this.servicePrice = servicePrice; - this.serviceDurationMinutes = serviceDurationMinutes; - this.active = active; + this.serviceDuration = serviceDuration; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getServiceId() { + return serviceId; } - public void setId(Long id) { - this.id = id; + public void setServiceId(Long serviceId) { + this.serviceId = serviceId; } public String getServiceName() { @@ -69,12 +65,12 @@ public class Service { this.serviceName = serviceName; } - public String getServiceDescription() { - return serviceDescription; + public String getServiceDesc() { + return serviceDesc; } - public void setServiceDescription(String serviceDescription) { - this.serviceDescription = serviceDescription; + public void setServiceDesc(String serviceDesc) { + this.serviceDesc = serviceDesc; } public BigDecimal getServicePrice() { @@ -85,20 +81,12 @@ public class Service { this.servicePrice = servicePrice; } - public Integer getServiceDurationMinutes() { - return serviceDurationMinutes; + public Integer getServiceDuration() { + return serviceDuration; } - public void setServiceDurationMinutes(Integer serviceDurationMinutes) { - this.serviceDurationMinutes = serviceDurationMinutes; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; + public void setServiceDuration(Integer serviceDuration) { + this.serviceDuration = serviceDuration; } public LocalDateTime getCreatedAt() { @@ -122,23 +110,22 @@ public class Service { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Service service = (Service) o; - return Objects.equals(id, service.id); + return Objects.equals(serviceId, service.serviceId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(serviceId); } @Override public String toString() { return "Service{" + - "id=" + id + + "serviceId=" + serviceId + ", serviceName='" + serviceName + '\'' + - ", serviceDescription='" + serviceDescription + '\'' + + ", serviceDesc='" + serviceDesc + '\'' + ", servicePrice=" + servicePrice + - ", serviceDurationMinutes=" + serviceDurationMinutes + - ", active=" + active + + ", serviceDuration=" + serviceDuration + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/StoreLocation.java b/src/main/java/com/petshop/backend/entity/StoreLocation.java new file mode 100644 index 00000000..6b1a2ced --- /dev/null +++ b/src/main/java/com/petshop/backend/entity/StoreLocation.java @@ -0,0 +1,132 @@ +package com.petshop.backend.entity; + +import jakarta.persistence.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.LocalDateTime; +import java.util.Objects; + +@Entity +@Table(name = "storeLocation") +public class StoreLocation { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long storeId; + + @Column(nullable = false, length = 100) + private String storeName; + + @Column(nullable = false, length = 255) + private String address; + + @Column(nullable = false, length = 20) + private String phone; + + @Column(nullable = false, length = 100) + private String email; + + @CreationTimestamp + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + public StoreLocation() { + } + + public StoreLocation(Long storeId, String storeName, String address, String phone, String email, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.storeId = storeId; + this.storeName = storeName; + this.address = address; + this.phone = phone; + this.email = email; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public Long getStoreId() { + return storeId; + } + + public void setStoreId(Long storeId) { + this.storeId = storeId; + } + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StoreLocation that = (StoreLocation) o; + return Objects.equals(storeId, that.storeId); + } + + @Override + public int hashCode() { + return Objects.hash(storeId); + } + + @Override + public String toString() { + return "StoreLocation{" + + "storeId=" + storeId + + ", storeName='" + storeName + '\'' + + ", address='" + address + '\'' + + ", phone='" + phone + '\'' + + ", email='" + email + '\'' + + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + + '}'; + } +} diff --git a/src/main/java/com/petshop/backend/entity/Supplier.java b/src/main/java/com/petshop/backend/entity/Supplier.java index c0279738..5dc35f17 100644 --- a/src/main/java/com/petshop/backend/entity/Supplier.java +++ b/src/main/java/com/petshop/backend/entity/Supplier.java @@ -8,30 +8,27 @@ import java.time.LocalDateTime; import java.util.Objects; @Entity -@Table(name = "suppliers") +@Table(name = "supplier") public class Supplier { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private Long supId; - @Column(name = "supplier_name", nullable = false, length = 100) - private String supplierName; + @Column(nullable = false, length = 100) + private String supCompany; - @Column(name = "supplier_contact", length = 100) - private String supplierContact; + @Column(nullable = false, length = 50) + private String supContactFirstName; - @Column(name = "supplier_email", length = 100) - private String supplierEmail; + @Column(nullable = false, length = 50) + private String supContactLastName; - @Column(name = "supplier_phone", length = 20) - private String supplierPhone; + @Column(nullable = false, length = 100) + private String supEmail; - @Column(name = "supplier_address", columnDefinition = "TEXT") - private String supplierAddress; - - @Column(nullable = false) - private Boolean active = true; + @Column(nullable = false, length = 20) + private String supPhone; @CreationTimestamp @Column(name = "created_at", updatable = false) @@ -44,72 +41,63 @@ public class Supplier { public Supplier() { } - public Supplier(Long id, String supplierName, String supplierContact, String supplierEmail, String supplierPhone, String supplierAddress, Boolean active, LocalDateTime createdAt, LocalDateTime updatedAt) { - this.id = id; - this.supplierName = supplierName; - this.supplierContact = supplierContact; - this.supplierEmail = supplierEmail; - this.supplierPhone = supplierPhone; - this.supplierAddress = supplierAddress; - this.active = active; + public Supplier(Long supId, String supCompany, String supContactFirstName, String supContactLastName, String supEmail, String supPhone, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.supId = supId; + this.supCompany = supCompany; + this.supContactFirstName = supContactFirstName; + this.supContactLastName = supContactLastName; + this.supEmail = supEmail; + this.supPhone = supPhone; this.createdAt = createdAt; this.updatedAt = updatedAt; } - public Long getId() { - return id; + public Long getSupId() { + return supId; } - public void setId(Long id) { - this.id = id; + public void setSupId(Long supId) { + this.supId = supId; } - public String getSupplierName() { - return supplierName; + public String getSupCompany() { + return supCompany; } - public void setSupplierName(String supplierName) { - this.supplierName = supplierName; + public void setSupCompany(String supCompany) { + this.supCompany = supCompany; } - public String getSupplierContact() { - return supplierContact; + public String getSupContactFirstName() { + return supContactFirstName; } - public void setSupplierContact(String supplierContact) { - this.supplierContact = supplierContact; + public void setSupContactFirstName(String supContactFirstName) { + this.supContactFirstName = supContactFirstName; } - public String getSupplierEmail() { - return supplierEmail; + public String getSupContactLastName() { + return supContactLastName; } - public void setSupplierEmail(String supplierEmail) { - this.supplierEmail = supplierEmail; + public void setSupContactLastName(String supContactLastName) { + this.supContactLastName = supContactLastName; } - public String getSupplierPhone() { - return supplierPhone; + public String getSupEmail() { + return supEmail; } - public void setSupplierPhone(String supplierPhone) { - this.supplierPhone = supplierPhone; + public void setSupEmail(String supEmail) { + this.supEmail = supEmail; } - public String getSupplierAddress() { - return supplierAddress; + public String getSupPhone() { + return supPhone; } - public void setSupplierAddress(String supplierAddress) { - this.supplierAddress = supplierAddress; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; + public void setSupPhone(String supPhone) { + this.supPhone = supPhone; } public LocalDateTime getCreatedAt() { @@ -133,24 +121,23 @@ public class Supplier { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Supplier supplier = (Supplier) o; - return Objects.equals(id, supplier.id); + return Objects.equals(supId, supplier.supId); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(supId); } @Override public String toString() { return "Supplier{" + - "id=" + id + - ", supplierName='" + supplierName + '\'' + - ", supplierContact='" + supplierContact + '\'' + - ", supplierEmail='" + supplierEmail + '\'' + - ", supplierPhone='" + supplierPhone + '\'' + - ", supplierAddress='" + supplierAddress + '\'' + - ", active=" + active + + "supId=" + supId + + ", supCompany='" + supCompany + '\'' + + ", supContactFirstName='" + supContactFirstName + '\'' + + ", supContactLastName='" + supContactLastName + '\'' + + ", supEmail='" + supEmail + '\'' + + ", supPhone='" + supPhone + '\'' + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; diff --git a/src/main/java/com/petshop/backend/entity/User.java b/src/main/java/com/petshop/backend/entity/User.java index 729e782a..7d6901a8 100644 --- a/src/main/java/com/petshop/backend/entity/User.java +++ b/src/main/java/com/petshop/backend/entity/User.java @@ -43,7 +43,7 @@ public class User { private LocalDateTime updatedAt; public enum Role { - STAFF, ADMIN, CUSTOMER + STAFF, ADMIN } public User() { diff --git a/src/main/java/com/petshop/backend/repository/RefundRepository.java b/src/main/java/com/petshop/backend/repository/RefundRepository.java deleted file mode 100644 index 8378b672..00000000 --- a/src/main/java/com/petshop/backend/repository/RefundRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.petshop.backend.repository; - -import com.petshop.backend.entity.Refund; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface RefundRepository extends JpaRepository { -} diff --git a/src/main/java/com/petshop/backend/security/SecurityConfig.java b/src/main/java/com/petshop/backend/security/SecurityConfig.java index e1ce42c4..dadf9d93 100644 --- a/src/main/java/com/petshop/backend/security/SecurityConfig.java +++ b/src/main/java/com/petshop/backend/security/SecurityConfig.java @@ -36,7 +36,7 @@ public class SecurityConfig { http .csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(auth -> auth - .requestMatchers("/api/v1/auth/login", "/api/v1/auth/register").permitAll() + .requestMatchers("/api/v1/auth/login").permitAll() .requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html").permitAll() .requestMatchers(HttpMethod.GET, "/api/v1/dropdowns/suppliers").hasRole("ADMIN") .requestMatchers("/api/v1/inventory/**").hasRole("ADMIN") diff --git a/src/main/java/com/petshop/backend/service/RefundService.java b/src/main/java/com/petshop/backend/service/RefundService.java deleted file mode 100644 index ae378996..00000000 --- a/src/main/java/com/petshop/backend/service/RefundService.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.petshop.backend.service; - -import com.petshop.backend.dto.refund.RefundRequest; -import com.petshop.backend.dto.refund.RefundResponse; -import com.petshop.backend.entity.*; -import com.petshop.backend.exception.BusinessException; -import com.petshop.backend.exception.ResourceNotFoundException; -import com.petshop.backend.repository.*; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -@Service -public class RefundService { - - private final RefundRepository refundRepository; - private final SaleRepository saleRepository; - private final SaleItemRepository saleItemRepository; - private final InventoryRepository inventoryRepository; - private final UserRepository userRepository; - - public RefundService(RefundRepository refundRepository, SaleRepository saleRepository, SaleItemRepository saleItemRepository, InventoryRepository inventoryRepository, UserRepository userRepository) { - this.refundRepository = refundRepository; - this.saleRepository = saleRepository; - this.saleItemRepository = saleItemRepository; - this.inventoryRepository = inventoryRepository; - this.userRepository = userRepository; - } - - @Transactional - public RefundResponse createRefund(Long saleId, RefundRequest request) { - String username = SecurityContextHolder.getContext().getAuthentication().getName(); - User processedBy = userRepository.findByUsername(username) - .orElseThrow(() -> new ResourceNotFoundException("User not found: " + username)); - - Sale sale = saleRepository.findById(saleId) - .orElseThrow(() -> new ResourceNotFoundException("Sale not found with id: " + saleId)); - - Refund refund = new Refund(); - refund.setSale(sale); - refund.setRefundDate(LocalDateTime.now()); - refund.setRefundReason(request.getRefundReason()); - refund.setProcessedBy(processedBy); - - BigDecimal totalRefundAmount = BigDecimal.ZERO; - List refundItems = new ArrayList<>(); - - for (var itemRequest : request.getItems()) { - SaleItem saleItem = saleItemRepository.findById(itemRequest.getSaleItemId()) - .orElseThrow(() -> new ResourceNotFoundException("Sale item not found with id: " + itemRequest.getSaleItemId())); - - if (!saleItem.getSale().getId().equals(saleId)) { - throw new BusinessException("Sale item " + itemRequest.getSaleItemId() + " does not belong to sale " + saleId); - } - - if (itemRequest.getQuantity() > saleItem.getQuantity()) { - throw new BusinessException("Refund quantity (" + itemRequest.getQuantity() + - ") exceeds original sale quantity (" + saleItem.getQuantity() + ") for product: " + saleItem.getProduct().getProductName()); - } - - Inventory inventory = inventoryRepository.findByProductIdAndStoreId( - saleItem.getProduct().getId(), - sale.getStore().getId()) - .orElseThrow(() -> new ResourceNotFoundException("Inventory not found for product " + - saleItem.getProduct().getId() + " at store " + sale.getStore().getId())); - - inventory.setQuantity(inventory.getQuantity() + itemRequest.getQuantity()); - inventory.setLastRestocked(LocalDateTime.now()); - inventoryRepository.save(inventory); - - BigDecimal itemRefundAmount = saleItem.getUnitPrice().multiply(BigDecimal.valueOf(itemRequest.getQuantity())); - - RefundItem refundItem = new RefundItem(); - refundItem.setRefund(refund); - refundItem.setSaleItem(saleItem); - refundItem.setQuantity(itemRequest.getQuantity()); - refundItem.setRefundAmount(itemRefundAmount); - - refundItems.add(refundItem); - totalRefundAmount = totalRefundAmount.add(itemRefundAmount); - } - - refund.setRefundAmount(totalRefundAmount); - refund.setItems(refundItems); - - Refund savedRefund = refundRepository.save(refund); - return mapToResponse(savedRefund); - } - - private RefundResponse mapToResponse(Refund refund) { - RefundResponse response = new RefundResponse(); - response.setId(refund.getId()); - response.setSaleId(refund.getSale().getId()); - response.setRefundDate(refund.getRefundDate()); - response.setRefundAmount(refund.getRefundAmount()); - response.setRefundReason(refund.getRefundReason()); - response.setProcessedBy(refund.getProcessedBy().getId()); - response.setProcessedByName(refund.getProcessedBy().getFullName()); - response.setCreatedAt(refund.getCreatedAt()); - - List itemResponses = new ArrayList<>(); - for (RefundItem item : refund.getItems()) { - RefundResponse.RefundItemResponse itemResponse = new RefundResponse.RefundItemResponse(); - itemResponse.setId(item.getId()); - itemResponse.setSaleItemId(item.getSaleItem().getId()); - itemResponse.setProductId(item.getSaleItem().getProduct().getId()); - itemResponse.setProductName(item.getSaleItem().getProduct().getProductName()); - itemResponse.setQuantity(item.getQuantity()); - itemResponse.setRefundAmount(item.getRefundAmount()); - itemResponses.add(itemResponse); - } - response.setItems(itemResponses); - - return response; - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 315667e7..6452f1a7 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,7 @@ spring: jpa: hibernate: - ddl-auto: update + ddl-auto: validate show-sql: ${JPA_SHOW_SQL:false} properties: hibernate: