Fix backend warnings

This commit is contained in:
2026-03-11 14:11:06 -06:00
parent d2b26dc113
commit a3fa7f32ed
7 changed files with 23 additions and 15 deletions

View File

@@ -2,8 +2,10 @@ package com.petshop.backend;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
@SpringBootApplication @SpringBootApplication
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
public class BackendApplication { public class BackendApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args); SpringApplication.run(BackendApplication.class, args);

View File

@@ -4,7 +4,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager; 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.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
@@ -48,14 +48,13 @@ public class SecurityConfig {
.anyRequest().authenticated() .anyRequest().authenticated()
) )
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider()) .authenticationProvider(daoAuthenticationProvider())
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
return http.build(); return http.build();
} }
@Bean private DaoAuthenticationProvider daoAuthenticationProvider() {
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(userDetailsService); DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder()); authProvider.setPasswordEncoder(passwordEncoder());
return authProvider; return authProvider;
@@ -63,7 +62,7 @@ public class SecurityConfig {
@Bean @Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception { public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager(); return new ProviderManager(daoAuthenticationProvider());
} }
@Bean @Bean

View File

@@ -8,6 +8,7 @@ import com.petshop.backend.repository.InventoryRepository;
import com.petshop.backend.repository.ProductRepository; import com.petshop.backend.repository.ProductRepository;
import com.petshop.backend.repository.SaleRepository; import com.petshop.backend.repository.SaleRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
@@ -30,6 +31,7 @@ public class AnalyticsService {
this.productRepository = productRepository; this.productRepository = productRepository;
} }
@Transactional(readOnly = true)
public DashboardResponse getDashboardData(int days, int top) { public DashboardResponse getDashboardData(int days, int top) {
LocalDateTime startDate = LocalDateTime.now().minusDays(days); LocalDateTime startDate = LocalDateTime.now().minusDays(days);

View File

@@ -58,6 +58,7 @@ public class AppointmentService {
this.employeeStoreRepository = employeeStoreRepository; this.employeeStoreRepository = employeeStoreRepository;
} }
@Transactional(readOnly = true)
public Page<AppointmentResponse> getAllAppointments(String query, Pageable pageable, Long customerId) { public Page<AppointmentResponse> getAllAppointments(String query, Pageable pageable, Long customerId) {
Page<Appointment> appointments; Page<Appointment> appointments;
@@ -78,6 +79,7 @@ public class AppointmentService {
return appointments.map(this::mapToResponse); return appointments.map(this::mapToResponse);
} }
@Transactional(readOnly = true)
public AppointmentResponse getAppointmentById(Long id, Long customerId) { public AppointmentResponse getAppointmentById(Long id, Long customerId) {
Appointment appointment = appointmentRepository.findById(id) Appointment appointment = appointmentRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Appointment not found with id: " + id)); .orElseThrow(() -> new ResourceNotFoundException("Appointment not found with id: " + id));
@@ -166,6 +168,7 @@ public class AppointmentService {
appointmentRepository.deleteAllById(request.getIds()); appointmentRepository.deleteAllById(request.getIds());
} }
@Transactional(readOnly = true)
public List<String> checkAvailability(Long storeId, Long serviceId, LocalDate date) { public List<String> checkAvailability(Long storeId, Long serviceId, LocalDate date) {
storeRepository.findById(storeId) storeRepository.findById(storeId)
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId)); .orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId));

View File

@@ -40,6 +40,7 @@ public class SaleService {
this.customerRepository = customerRepository; this.customerRepository = customerRepository;
} }
@Transactional(readOnly = true)
public Page<SaleResponse> getAllSales(String query, Pageable pageable) { public Page<SaleResponse> getAllSales(String query, Pageable pageable) {
Page<Sale> sales; Page<Sale> sales;
if (query != null && !query.trim().isEmpty()) { if (query != null && !query.trim().isEmpty()) {
@@ -50,6 +51,7 @@ public class SaleService {
return sales.map(this::mapToResponse); return sales.map(this::mapToResponse);
} }
@Transactional(readOnly = true)
public SaleResponse getSaleById(Long id) { public SaleResponse getSaleById(Long id) {
Sale sale = saleRepository.findById(id) Sale sale = saleRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Sale not found with id: " + id)); .orElseThrow(() -> new ResourceNotFoundException("Sale not found with id: " + id));

View File

@@ -27,7 +27,7 @@ spring:
properties: properties:
hibernate: hibernate:
format_sql: true format_sql: true
dialect: org.hibernate.dialect.MySQLDialect open-in-view: false
flyway: flyway:
enabled: true enabled: true
@@ -53,3 +53,4 @@ logging:
level: level:
com.petshop: ${LOG_LEVEL:INFO} com.petshop: ${LOG_LEVEL:INFO}
org.springframework.security: ${LOG_LEVEL_SECURITY:WARN} org.springframework.security: ${LOG_LEVEL_SECURITY:WARN}
org.springdoc.core.events.SpringDocAppInitializer: ERROR

View File

@@ -64,18 +64,17 @@ class RunConfigValidationTest {
} }
@Test @Test
void databaseSchemaFileExists() { void flywayBaselineMigrationExists() {
File schemaFile = new File("src/main/resources/schema.sql"); File migrationFile = new File("src/main/resources/db/migration/V1__baseline_schema.sql");
assertTrue(schemaFile.exists(), "schema.sql should exist in src/main/resources/"); assertTrue(migrationFile.exists(), "Flyway baseline migration should exist in src/main/resources/db/migration/");
} }
@Test @Test
void schemaContainsActiveColumn() throws Exception { void flywayBaselineContainsActiveColumn() throws Exception {
File schemaFile = new File("src/main/resources/schema.sql"); File migrationFile = new File("src/main/resources/db/migration/V1__baseline_schema.sql");
String schemaContent = new String(java.nio.file.Files.readAllBytes(schemaFile.toPath())); String migrationContent = new String(java.nio.file.Files.readAllBytes(migrationFile.toPath()));
assertTrue(schemaContent.contains("active BOOLEAN") || schemaContent.contains("active boolean"), assertTrue(migrationContent.contains("active BOOLEAN") || migrationContent.contains("active boolean"),
"schema.sql should contain 'active' column definition in users table. " + "Baseline migration should contain the users.active column definition.");
"If you see 'Unknown column active' error, run 'Reset Database Only' configuration.");
} }
} }