fix auth and logic bugs

This commit is contained in:
2026-04-15 15:54:46 -06:00
parent 1ab4df0b81
commit c24d49fa5b
4 changed files with 8 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package com.petshop.backend.controller;
import com.petshop.backend.entity.User;
import com.petshop.backend.exception.ResourceNotFoundException;
import com.petshop.backend.repository.UserRepository;
import com.petshop.backend.service.EmailService;
import com.petshop.backend.util.AuthenticationHelper;
@@ -33,7 +34,7 @@ public class ContactController {
@PostMapping
public ResponseEntity<Void> sendContactEmail(@Valid @RequestBody ContactRequest req) {
Long userId = AuthenticationHelper.getAuthenticatedUserId();
User user = userRepository.findById(userId).orElseThrow();
User user = userRepository.findById(userId).orElseThrow(() -> new ResourceNotFoundException("User not found with id: " + userId));
emailService.sendContactMessage(user, req.subject(), req.body());
return ResponseEntity.ok().build();
}

View File

@@ -35,11 +35,13 @@ public class StoreController {
}
@PostMapping
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<StoreResponse> createStore(@Valid @RequestBody StoreRequest request) {
return ResponseEntity.status(HttpStatus.CREATED).body(storeService.createStore(request));
}
@PutMapping("/{id}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<StoreResponse> updateStore(
@PathVariable Long id,
@Valid @RequestBody StoreRequest request) {
@@ -47,12 +49,14 @@ public class StoreController {
}
@DeleteMapping("/{id}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<Void> deleteStore(@PathVariable Long id) {
storeService.deleteStore(id);
return ResponseEntity.noContent().build();
}
@DeleteMapping
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<Void> bulkDeleteStores(@Valid @RequestBody BulkDeleteRequest request) {
storeService.bulkDeleteStores(request);
return ResponseEntity.noContent().build();

View File

@@ -100,7 +100,7 @@ public class PetRequest {
Objects.equals(petSpecies, that.petSpecies) &&
Objects.equals(petBreed, that.petBreed) &&
Objects.equals(petAge, that.petAge) &&
petStatus == that.petStatus &&
Objects.equals(petStatus, that.petStatus) &&
Objects.equals(petPrice, that.petPrice);
}

View File

@@ -264,7 +264,7 @@ public class AppointmentService {
List<Appointment> pastBookedAppointments = appointmentRepository.findPastBookedAppointments(currentDate, currentTime);
for (Appointment appointment : pastBookedAppointments) {
appointment.setAppointmentStatus("COMPLETED");
appointment.setAppointmentStatus("Completed");
appointmentRepository.save(appointment);
}