Update Store and Pet services and DTOs
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.petshop.backend.dto.pet;
|
||||
|
||||
import com.petshop.backend.entity.Pet;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
@@ -20,7 +19,7 @@ public class PetRequest {
|
||||
private Integer petAge;
|
||||
|
||||
@NotNull(message = "Status is required")
|
||||
private Pet.PetStatus petStatus;
|
||||
private String petStatus;
|
||||
|
||||
private BigDecimal petPrice;
|
||||
|
||||
@@ -56,11 +55,11 @@ public class PetRequest {
|
||||
this.petAge = petAge;
|
||||
}
|
||||
|
||||
public Pet.PetStatus getPetStatus() {
|
||||
public String getPetStatus() {
|
||||
return petStatus;
|
||||
}
|
||||
|
||||
public void setPetStatus(Pet.PetStatus petStatus) {
|
||||
public void setPetStatus(String petStatus) {
|
||||
this.petStatus = petStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PetResponse {
|
||||
private Long id;
|
||||
private Long petId;
|
||||
private String petName;
|
||||
private String petSpecies;
|
||||
private String petBreed;
|
||||
@@ -18,8 +18,8 @@ public class PetResponse {
|
||||
public PetResponse() {
|
||||
}
|
||||
|
||||
public PetResponse(Long id, String petName, String petSpecies, String petBreed, Integer petAge, String petStatus, BigDecimal petPrice, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
||||
this.id = id;
|
||||
public PetResponse(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;
|
||||
@@ -30,12 +30,12 @@ public class PetResponse {
|
||||
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() {
|
||||
@@ -107,18 +107,18 @@ public class PetResponse {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PetResponse that = (PetResponse) o;
|
||||
return Objects.equals(id, that.id) && Objects.equals(petName, that.petName) && Objects.equals(petSpecies, that.petSpecies) && Objects.equals(petBreed, that.petBreed) && Objects.equals(petAge, that.petAge) && Objects.equals(petStatus, that.petStatus) && Objects.equals(petPrice, that.petPrice) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt);
|
||||
return Objects.equals(petId, that.petId) && Objects.equals(petName, that.petName) && Objects.equals(petSpecies, that.petSpecies) && Objects.equals(petBreed, that.petBreed) && Objects.equals(petAge, that.petAge) && Objects.equals(petStatus, that.petStatus) && Objects.equals(petPrice, that.petPrice) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, petName, petSpecies, petBreed, petAge, petStatus, petPrice, createdAt, updatedAt);
|
||||
return Objects.hash(petId, petName, petSpecies, petBreed, petAge, petStatus, petPrice, createdAt, updatedAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PetResponse{" +
|
||||
"id=" + id +
|
||||
"petId=" + petId +
|
||||
", petName='" + petName + '\'' +
|
||||
", petSpecies='" + petSpecies + '\'' +
|
||||
", petBreed='" + petBreed + '\'' +
|
||||
|
||||
@@ -4,27 +4,31 @@ import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
public class StoreResponse {
|
||||
private Long id;
|
||||
private Long storeId;
|
||||
private String storeName;
|
||||
private String storeLocation;
|
||||
private String address;
|
||||
private String phone;
|
||||
private String email;
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
public StoreResponse() {
|
||||
}
|
||||
|
||||
public StoreResponse(Long id, String storeName, String storeLocation, LocalDateTime createdAt) {
|
||||
this.id = id;
|
||||
public StoreResponse(Long storeId, String storeName, String address, String phone, String email, LocalDateTime createdAt) {
|
||||
this.storeId = storeId;
|
||||
this.storeName = storeName;
|
||||
this.storeLocation = storeLocation;
|
||||
this.address = address;
|
||||
this.phone = phone;
|
||||
this.email = email;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
public Long getStoreId() {
|
||||
return storeId;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
public void setStoreId(Long storeId) {
|
||||
this.storeId = storeId;
|
||||
}
|
||||
|
||||
public String getStoreName() {
|
||||
@@ -35,12 +39,28 @@ public class StoreResponse {
|
||||
this.storeName = storeName;
|
||||
}
|
||||
|
||||
public String getStoreLocation() {
|
||||
return storeLocation;
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setStoreLocation(String storeLocation) {
|
||||
this.storeLocation = storeLocation;
|
||||
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() {
|
||||
@@ -56,20 +76,22 @@ public class StoreResponse {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
StoreResponse that = (StoreResponse) o;
|
||||
return Objects.equals(id, that.id) && Objects.equals(storeName, that.storeName) && Objects.equals(storeLocation, that.storeLocation) && Objects.equals(createdAt, that.createdAt);
|
||||
return Objects.equals(storeId, that.storeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, storeName, storeLocation, createdAt);
|
||||
return Objects.hash(storeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StoreResponse{" +
|
||||
"id=" + id +
|
||||
"storeId=" + storeId +
|
||||
", storeName='" + storeName + '\'' +
|
||||
", storeLocation='" + storeLocation + '\'' +
|
||||
", address='" + address + '\'' +
|
||||
", phone='" + phone + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", createdAt=" + createdAt +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ public class PetService {
|
||||
|
||||
private PetResponse mapToResponse(Pet pet) {
|
||||
return new PetResponse(
|
||||
pet.getId(),
|
||||
pet.getPetId(),
|
||||
pet.getPetName(),
|
||||
pet.getPetSpecies(),
|
||||
pet.getPetBreed(),
|
||||
pet.getPetAge(),
|
||||
pet.getPetStatus() != null ? pet.getPetStatus().toString() : null,
|
||||
pet.getPetStatus(),
|
||||
pet.getPetPrice(),
|
||||
pet.getCreatedAt(),
|
||||
pet.getUpdatedAt()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.petshop.backend.service;
|
||||
|
||||
import com.petshop.backend.dto.store.StoreResponse;
|
||||
import com.petshop.backend.entity.Store;
|
||||
import com.petshop.backend.entity.StoreLocation;
|
||||
import com.petshop.backend.repository.StoreRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -17,7 +17,7 @@ public class StoreService {
|
||||
}
|
||||
|
||||
public Page<StoreResponse> getAllStores(String query, Pageable pageable) {
|
||||
Page<Store> stores;
|
||||
Page<StoreLocation> stores;
|
||||
if (query != null && !query.trim().isEmpty()) {
|
||||
stores = storeRepository.searchStores(query, pageable);
|
||||
} else {
|
||||
@@ -26,11 +26,13 @@ public class StoreService {
|
||||
return stores.map(this::mapToResponse);
|
||||
}
|
||||
|
||||
private StoreResponse mapToResponse(Store store) {
|
||||
private StoreResponse mapToResponse(StoreLocation store) {
|
||||
return new StoreResponse(
|
||||
store.getId(),
|
||||
store.getStoreId(),
|
||||
store.getStoreName(),
|
||||
store.getStoreLocation(),
|
||||
store.getAddress(),
|
||||
store.getPhone(),
|
||||
store.getEmail(),
|
||||
store.getCreatedAt()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user