add service species collection
This commit is contained in:
@@ -4,7 +4,9 @@ import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ServiceRequest {
|
||||
@NotBlank(message = "Service name is required")
|
||||
@@ -19,6 +21,8 @@ public class ServiceRequest {
|
||||
@Positive(message = "Duration must be positive")
|
||||
private Integer serviceDuration;
|
||||
|
||||
private Set<String> species = new HashSet<>();
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
@@ -51,6 +55,14 @@ public class ServiceRequest {
|
||||
this.serviceDuration = serviceDuration;
|
||||
}
|
||||
|
||||
public Set<String> getSpecies() {
|
||||
return species;
|
||||
}
|
||||
|
||||
public void setSpecies(Set<String> species) {
|
||||
this.species = species;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@@ -59,12 +71,13 @@ public class ServiceRequest {
|
||||
return Objects.equals(serviceName, that.serviceName) &&
|
||||
Objects.equals(serviceDesc, that.serviceDesc) &&
|
||||
Objects.equals(servicePrice, that.servicePrice) &&
|
||||
Objects.equals(serviceDuration, that.serviceDuration);
|
||||
Objects.equals(serviceDuration, that.serviceDuration) &&
|
||||
Objects.equals(species, that.species);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(serviceName, serviceDesc, servicePrice, serviceDuration);
|
||||
return Objects.hash(serviceName, serviceDesc, servicePrice, serviceDuration, species);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,6 +87,7 @@ public class ServiceRequest {
|
||||
", serviceDesc='" + serviceDesc + '\'' +
|
||||
", servicePrice=" + servicePrice +
|
||||
", serviceDuration=" + serviceDuration +
|
||||
", species=" + species +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.petshop.backend.dto.service;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ServiceResponse {
|
||||
private Long serviceId;
|
||||
@@ -10,18 +11,20 @@ public class ServiceResponse {
|
||||
private String serviceDesc;
|
||||
private BigDecimal servicePrice;
|
||||
private Integer serviceDuration;
|
||||
private Set<String> species;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public ServiceResponse() {
|
||||
}
|
||||
|
||||
public ServiceResponse(Long serviceId, String serviceName, String serviceDesc, BigDecimal servicePrice, Integer serviceDuration, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
||||
public ServiceResponse(Long serviceId, String serviceName, String serviceDesc, BigDecimal servicePrice, Integer serviceDuration, Set<String> species, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
||||
this.serviceId = serviceId;
|
||||
this.serviceName = serviceName;
|
||||
this.serviceDesc = serviceDesc;
|
||||
this.servicePrice = servicePrice;
|
||||
this.serviceDuration = serviceDuration;
|
||||
this.species = species;
|
||||
this.createdAt = createdAt;
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
@@ -66,6 +69,14 @@ public class ServiceResponse {
|
||||
this.serviceDuration = serviceDuration;
|
||||
}
|
||||
|
||||
public Set<String> getSpecies() {
|
||||
return species;
|
||||
}
|
||||
|
||||
public void setSpecies(Set<String> species) {
|
||||
this.species = species;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
@@ -87,12 +98,12 @@ public class ServiceResponse {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ServiceResponse that = (ServiceResponse) o;
|
||||
return Objects.equals(serviceId, that.serviceId) && Objects.equals(serviceName, that.serviceName) && Objects.equals(serviceDesc, that.serviceDesc) && Objects.equals(servicePrice, that.servicePrice) && Objects.equals(serviceDuration, that.serviceDuration) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt);
|
||||
return Objects.equals(serviceId, that.serviceId) && Objects.equals(serviceName, that.serviceName) && Objects.equals(serviceDesc, that.serviceDesc) && Objects.equals(servicePrice, that.servicePrice) && Objects.equals(serviceDuration, that.serviceDuration) && Objects.equals(species, that.species) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(serviceId, serviceName, serviceDesc, servicePrice, serviceDuration, createdAt, updatedAt);
|
||||
return Objects.hash(serviceId, serviceName, serviceDesc, servicePrice, serviceDuration, species, createdAt, updatedAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,6 +114,7 @@ public class ServiceResponse {
|
||||
", serviceDesc='" + serviceDesc + '\'' +
|
||||
", servicePrice=" + servicePrice +
|
||||
", serviceDuration=" + serviceDuration +
|
||||
", species=" + species +
|
||||
", createdAt=" + createdAt +
|
||||
", updatedAt=" + updatedAt +
|
||||
'}';
|
||||
|
||||
@@ -6,7 +6,9 @@ import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "service")
|
||||
@@ -28,6 +30,11 @@ public class Service {
|
||||
@Column(nullable = false)
|
||||
private Integer serviceDuration;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "service_species", joinColumns = @JoinColumn(name = "serviceId"))
|
||||
@Column(name = "species", length = 50)
|
||||
private Set<String> species = new HashSet<>();
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
@@ -89,6 +96,14 @@ public class Service {
|
||||
this.serviceDuration = serviceDuration;
|
||||
}
|
||||
|
||||
public Set<String> getSpecies() {
|
||||
return species;
|
||||
}
|
||||
|
||||
public void setSpecies(Set<String> species) {
|
||||
this.species = species;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ public class ServiceService {
|
||||
service.setServiceDesc(request.getServiceDesc());
|
||||
service.setServicePrice(request.getServicePrice());
|
||||
service.setServiceDuration(request.getServiceDuration());
|
||||
if (request.getSpecies() != null) {
|
||||
service.setSpecies(request.getSpecies());
|
||||
}
|
||||
|
||||
service = serviceRepository.save(service);
|
||||
return mapToResponse(service);
|
||||
@@ -56,6 +59,9 @@ public class ServiceService {
|
||||
service.setServiceDesc(request.getServiceDesc());
|
||||
service.setServicePrice(request.getServicePrice());
|
||||
service.setServiceDuration(request.getServiceDuration());
|
||||
if (request.getSpecies() != null) {
|
||||
service.setSpecies(request.getSpecies());
|
||||
}
|
||||
|
||||
service = serviceRepository.save(service);
|
||||
return mapToResponse(service);
|
||||
@@ -81,6 +87,7 @@ public class ServiceService {
|
||||
service.getServiceDesc(),
|
||||
service.getServicePrice(),
|
||||
service.getServiceDuration(),
|
||||
service.getSpecies(),
|
||||
service.getCreatedAt(),
|
||||
service.getUpdatedAt()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user