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