From a018c98ce71a597bab08a41a1e0fda2ab3620993 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Thu, 5 Mar 2026 16:40:53 -0700 Subject: [PATCH] Add repositories for new entities and cleanup --- .../com/petshop/backend/entity/Store.java | 91 ------------------- .../repository/ActivityLogRepository.java | 9 ++ .../repository/EmployeeRepository.java | 9 ++ .../backend/repository/StoreRepository.java | 10 +- test_endpoints.sh | 58 ------------ 5 files changed, 23 insertions(+), 154 deletions(-) delete mode 100644 src/main/java/com/petshop/backend/entity/Store.java create mode 100644 src/main/java/com/petshop/backend/repository/ActivityLogRepository.java create mode 100644 src/main/java/com/petshop/backend/repository/EmployeeRepository.java delete mode 100755 test_endpoints.sh diff --git a/src/main/java/com/petshop/backend/entity/Store.java b/src/main/java/com/petshop/backend/entity/Store.java deleted file mode 100644 index 35861c87..00000000 --- a/src/main/java/com/petshop/backend/entity/Store.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.petshop.backend.entity; - -import jakarta.persistence.*; -import org.hibernate.annotations.CreationTimestamp; - -import java.time.LocalDateTime; -import java.util.Objects; - -@Entity -@Table(name = "stores") -public class Store { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "store_name", nullable = false, length = 100) - private String storeName; - - @Column(name = "store_location", length = 200) - private String storeLocation; - - @CreationTimestamp - @Column(name = "created_at", updatable = false) - private LocalDateTime createdAt; - - public Store() { - } - - public Store(Long id, String storeName, String storeLocation, LocalDateTime createdAt) { - this.id = id; - this.storeName = storeName; - this.storeLocation = storeLocation; - this.createdAt = createdAt; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getStoreName() { - return storeName; - } - - public void setStoreName(String storeName) { - this.storeName = storeName; - } - - public String getStoreLocation() { - return storeLocation; - } - - public void setStoreLocation(String storeLocation) { - this.storeLocation = storeLocation; - } - - 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; - Store store = (Store) o; - return Objects.equals(id, store.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "Store{" + - "id=" + id + - ", storeName='" + storeName + '\'' + - ", storeLocation='" + storeLocation + '\'' + - ", createdAt=" + createdAt + - '}'; - } -} diff --git a/src/main/java/com/petshop/backend/repository/ActivityLogRepository.java b/src/main/java/com/petshop/backend/repository/ActivityLogRepository.java new file mode 100644 index 00000000..5c5db4c5 --- /dev/null +++ b/src/main/java/com/petshop/backend/repository/ActivityLogRepository.java @@ -0,0 +1,9 @@ +package com.petshop.backend.repository; + +import com.petshop.backend.entity.ActivityLog; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ActivityLogRepository extends JpaRepository { +} diff --git a/src/main/java/com/petshop/backend/repository/EmployeeRepository.java b/src/main/java/com/petshop/backend/repository/EmployeeRepository.java new file mode 100644 index 00000000..4c5aa9d8 --- /dev/null +++ b/src/main/java/com/petshop/backend/repository/EmployeeRepository.java @@ -0,0 +1,9 @@ +package com.petshop.backend.repository; + +import com.petshop.backend.entity.Employee; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface EmployeeRepository extends JpaRepository { +} diff --git a/src/main/java/com/petshop/backend/repository/StoreRepository.java b/src/main/java/com/petshop/backend/repository/StoreRepository.java index 0c855389..5ee3758b 100644 --- a/src/main/java/com/petshop/backend/repository/StoreRepository.java +++ b/src/main/java/com/petshop/backend/repository/StoreRepository.java @@ -1,6 +1,6 @@ package com.petshop.backend.repository; -import com.petshop.backend.entity.Store; +import com.petshop.backend.entity.StoreLocation; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,10 +9,10 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository -public interface StoreRepository extends JpaRepository { +public interface StoreRepository extends JpaRepository { - @Query("SELECT s FROM Store s WHERE " + + @Query("SELECT s FROM StoreLocation s WHERE " + "LOWER(s.storeName) LIKE LOWER(CONCAT('%', :q, '%')) OR " + - "LOWER(s.storeLocation) LIKE LOWER(CONCAT('%', :q, '%'))") - Page searchStores(@Param("q") String query, Pageable pageable); + "LOWER(s.address) LIKE LOWER(CONCAT('%', :q, '%'))") + Page searchStores(@Param("q") String query, Pageable pageable); } diff --git a/test_endpoints.sh b/test_endpoints.sh deleted file mode 100755 index d310bbe6..00000000 --- a/test_endpoints.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -ADMIN_TOKEN="eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImlhdCI6MTc3MjczMzAxOSwiZXhwIjoxNzcyODE5NDE5fQ.__RqJbY2_HMjMlF6MoU8LagTu8pxjmizYYg4BQ0ahxRn9PV5iSQO3WRnCnujyE04AOY5yjTDEakOZOTEpiDFSw" -STAFF_TOKEN="eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdGFmZiIsImlhdCI6MTc3MjczMzAyMCwiZXhwIjoxNzcyODE5NDIwfQ.m7jC_QMWmJsj-kc4Qb-9cQwUEnJEAYJ7mbpKJOMISSup1rONwloN3Heio6Iw5ysIkjNt6uZbwIX2SZygbxQSVg" -BASE_URL="http://localhost:8080/api/v1" - -PASS=0 -FAIL=0 -TOTAL=0 - -test_endpoint() { - local method=$1 - local path=$2 - local token=$3 - local expected_status=$4 - local data=$5 - local desc=$6 - - TOTAL=$((TOTAL + 1)) - - if [ -z "$data" ]; then - response=$(curl -s -w "\n%{http_code}" -X $method "$BASE_URL$path" -H "Authorization: Bearer $token" -H "Content-Type: application/json") - else - response=$(curl -s -w "\n%{http_code}" -X $method "$BASE_URL$path" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d "$data") - fi - - status=$(echo "$response" | tail -n1) - body=$(echo "$response" | head -n-1) - - if [ "$status" = "$expected_status" ]; then - echo "✓ PASS: $desc ($method $path) - $status" - PASS=$((PASS + 1)) - echo "$body" | jq '.' 2>/dev/null || echo "$body" - else - echo "✗ FAIL: $desc ($method $path) - Expected $expected_status, got $status" - FAIL=$((FAIL + 1)) - echo "$body" - fi - echo "---" -} - -echo "=========================================" -echo "PHASE 1: DROPDOWN ENDPOINTS (7 endpoints)" -echo "=========================================" - -test_endpoint "GET" "/dropdowns/pets" "$STAFF_TOKEN" "200" "" "Get pets dropdown" -test_endpoint "GET" "/dropdowns/customers" "$STAFF_TOKEN" "200" "" "Get customers dropdown" -test_endpoint "GET" "/dropdowns/services" "$STAFF_TOKEN" "200" "" "Get services dropdown" -test_endpoint "GET" "/dropdowns/products" "$STAFF_TOKEN" "200" "" "Get products dropdown" -test_endpoint "GET" "/dropdowns/categories" "$STAFF_TOKEN" "200" "" "Get categories dropdown" -test_endpoint "GET" "/dropdowns/stores" "$STAFF_TOKEN" "200" "" "Get stores dropdown" -test_endpoint "GET" "/dropdowns/suppliers" "$ADMIN_TOKEN" "200" "" "Get suppliers dropdown (admin)" - -echo "" -echo "=========================================" -echo "SUMMARY: Phase 1" -echo "=========================================" -echo "Total: $TOTAL | Pass: $PASS | Fail: $FAIL"