From a3fa7f32edf6935f35dd52a775a65caef81d454e Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Wed, 11 Mar 2026 14:11:06 -0600 Subject: [PATCH] Fix backend warnings --- .../com/petshop/backend/BackendApplication.java | 2 ++ .../backend/security/SecurityConfig.java | 9 ++++----- .../backend/service/AnalyticsService.java | 2 ++ .../backend/service/AppointmentService.java | 3 +++ .../petshop/backend/service/SaleService.java | 2 ++ src/main/resources/application.yml | 3 ++- .../backend/config/RunConfigValidationTest.java | 17 ++++++++--------- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/petshop/backend/BackendApplication.java b/src/main/java/com/petshop/backend/BackendApplication.java index 05cede40..b2df1cc4 100644 --- a/src/main/java/com/petshop/backend/BackendApplication.java +++ b/src/main/java/com/petshop/backend/BackendApplication.java @@ -2,8 +2,10 @@ package com.petshop.backend; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.web.config.EnableSpringDataWebSupport; @SpringBootApplication +@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO) public class BackendApplication { public static void main(String[] args) { SpringApplication.run(BackendApplication.class, args); diff --git a/src/main/java/com/petshop/backend/security/SecurityConfig.java b/src/main/java/com/petshop/backend/security/SecurityConfig.java index 696a2f88..0a893c18 100644 --- a/src/main/java/com/petshop/backend/security/SecurityConfig.java +++ b/src/main/java/com/petshop/backend/security/SecurityConfig.java @@ -4,7 +4,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.ProviderManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; @@ -48,14 +48,13 @@ public class SecurityConfig { .anyRequest().authenticated() ) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .authenticationProvider(authenticationProvider()) + .authenticationProvider(daoAuthenticationProvider()) .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); return http.build(); } - @Bean - public AuthenticationProvider authenticationProvider() { + private DaoAuthenticationProvider daoAuthenticationProvider() { DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(userDetailsService); authProvider.setPasswordEncoder(passwordEncoder()); return authProvider; @@ -63,7 +62,7 @@ public class SecurityConfig { @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception { - return config.getAuthenticationManager(); + return new ProviderManager(daoAuthenticationProvider()); } @Bean diff --git a/src/main/java/com/petshop/backend/service/AnalyticsService.java b/src/main/java/com/petshop/backend/service/AnalyticsService.java index 18c9c9b8..32e6a5a7 100644 --- a/src/main/java/com/petshop/backend/service/AnalyticsService.java +++ b/src/main/java/com/petshop/backend/service/AnalyticsService.java @@ -8,6 +8,7 @@ import com.petshop.backend.repository.InventoryRepository; import com.petshop.backend.repository.ProductRepository; import com.petshop.backend.repository.SaleRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDate; @@ -30,6 +31,7 @@ public class AnalyticsService { this.productRepository = productRepository; } + @Transactional(readOnly = true) public DashboardResponse getDashboardData(int days, int top) { LocalDateTime startDate = LocalDateTime.now().minusDays(days); diff --git a/src/main/java/com/petshop/backend/service/AppointmentService.java b/src/main/java/com/petshop/backend/service/AppointmentService.java index d2fa5eaf..9abcf831 100644 --- a/src/main/java/com/petshop/backend/service/AppointmentService.java +++ b/src/main/java/com/petshop/backend/service/AppointmentService.java @@ -58,6 +58,7 @@ public class AppointmentService { this.employeeStoreRepository = employeeStoreRepository; } + @Transactional(readOnly = true) public Page getAllAppointments(String query, Pageable pageable, Long customerId) { Page appointments; @@ -78,6 +79,7 @@ public class AppointmentService { return appointments.map(this::mapToResponse); } + @Transactional(readOnly = true) public AppointmentResponse getAppointmentById(Long id, Long customerId) { Appointment appointment = appointmentRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Appointment not found with id: " + id)); @@ -166,6 +168,7 @@ public class AppointmentService { appointmentRepository.deleteAllById(request.getIds()); } + @Transactional(readOnly = true) public List checkAvailability(Long storeId, Long serviceId, LocalDate date) { storeRepository.findById(storeId) .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId)); diff --git a/src/main/java/com/petshop/backend/service/SaleService.java b/src/main/java/com/petshop/backend/service/SaleService.java index 55024b0c..b426dc38 100644 --- a/src/main/java/com/petshop/backend/service/SaleService.java +++ b/src/main/java/com/petshop/backend/service/SaleService.java @@ -40,6 +40,7 @@ public class SaleService { this.customerRepository = customerRepository; } + @Transactional(readOnly = true) public Page getAllSales(String query, Pageable pageable) { Page sales; if (query != null && !query.trim().isEmpty()) { @@ -50,6 +51,7 @@ public class SaleService { return sales.map(this::mapToResponse); } + @Transactional(readOnly = true) public SaleResponse getSaleById(Long id) { Sale sale = saleRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Sale not found with id: " + id)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6338af51..81f7ed51 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,7 +27,7 @@ spring: properties: hibernate: format_sql: true - dialect: org.hibernate.dialect.MySQLDialect + open-in-view: false flyway: enabled: true @@ -53,3 +53,4 @@ logging: level: com.petshop: ${LOG_LEVEL:INFO} org.springframework.security: ${LOG_LEVEL_SECURITY:WARN} + org.springdoc.core.events.SpringDocAppInitializer: ERROR diff --git a/src/test/java/com/petshop/backend/config/RunConfigValidationTest.java b/src/test/java/com/petshop/backend/config/RunConfigValidationTest.java index 88851bae..6c1c4a85 100644 --- a/src/test/java/com/petshop/backend/config/RunConfigValidationTest.java +++ b/src/test/java/com/petshop/backend/config/RunConfigValidationTest.java @@ -64,18 +64,17 @@ class RunConfigValidationTest { } @Test - void databaseSchemaFileExists() { - File schemaFile = new File("src/main/resources/schema.sql"); - assertTrue(schemaFile.exists(), "schema.sql should exist in src/main/resources/"); + void flywayBaselineMigrationExists() { + File migrationFile = new File("src/main/resources/db/migration/V1__baseline_schema.sql"); + assertTrue(migrationFile.exists(), "Flyway baseline migration should exist in src/main/resources/db/migration/"); } @Test - void schemaContainsActiveColumn() throws Exception { - File schemaFile = new File("src/main/resources/schema.sql"); - String schemaContent = new String(java.nio.file.Files.readAllBytes(schemaFile.toPath())); + void flywayBaselineContainsActiveColumn() throws Exception { + File migrationFile = new File("src/main/resources/db/migration/V1__baseline_schema.sql"); + String migrationContent = new String(java.nio.file.Files.readAllBytes(migrationFile.toPath())); - assertTrue(schemaContent.contains("active BOOLEAN") || schemaContent.contains("active boolean"), - "schema.sql should contain 'active' column definition in users table. " + - "If you see 'Unknown column active' error, run 'Reset Database Only' configuration."); + assertTrue(migrationContent.contains("active BOOLEAN") || migrationContent.contains("active boolean"), + "Baseline migration should contain the users.active column definition."); } }