Fix backend warnings
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ public class AppointmentService {
|
||||
this.employeeStoreRepository = employeeStoreRepository;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<AppointmentResponse> getAllAppointments(String query, Pageable pageable, Long customerId) {
|
||||
Page<Appointment> 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<String> checkAvailability(Long storeId, Long serviceId, LocalDate date) {
|
||||
storeRepository.findById(storeId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId));
|
||||
|
||||
@@ -40,6 +40,7 @@ public class SaleService {
|
||||
this.customerRepository = customerRepository;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Page<SaleResponse> getAllSales(String query, Pageable pageable) {
|
||||
Page<Sale> 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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user