fix auth and logic bugs
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user