404 page added

This commit is contained in:
Sidharth Prabhu
2026-04-21 18:26:55 +05:30
parent 239c055fc4
commit 655fb251b9
11 changed files with 226 additions and 41 deletions

View File

@@ -28,6 +28,7 @@ public class SecurityConfig {
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/auth/**").permitAll()
.requestMatchers("/api/notifications/**").permitAll()
.requestMatchers("/api/**").permitAll()
.anyRequest().permitAll()
);
@@ -46,7 +47,7 @@ public class SecurityConfig {
configuration.setAllowedOriginPatterns(List.of("*"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(List.of("*"));
configuration.setAllowCredentials(true);
configuration.setAllowCredentials(false);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;

View File

@@ -15,14 +15,31 @@ public class SystemNotificationController {
@Autowired
private SystemNotificationService notificationService;
@GetMapping("/test")
public String testReachability() {
return "Notification API is Reachable and whitelisted!";
}
@GetMapping
public List<SystemNotification> getUnread() {
return notificationService.getUnreadNotifications();
try {
return notificationService.getUnreadNotifications();
} catch (Exception e) {
System.err.println("[CRITICAL] Failed to fetch unread notifications:");
e.printStackTrace();
throw e;
}
}
@GetMapping("/all")
public List<SystemNotification> getAll() {
return notificationService.getAllNotifications();
try {
return notificationService.getAllNotifications();
} catch (Exception e) {
System.err.println("[CRITICAL] Failed to fetch all notifications:");
e.printStackTrace();
throw e;
}
}
@PostMapping("/mark-read/{id}")

View File

@@ -20,8 +20,8 @@ public class SystemNotification {
@Column(nullable = false)
private String type; // FEEDBACK, PURCHASE, PRODUCT, COUPON
@Column(nullable = false)
private boolean isRead = false;
@Column(name = "is_read", nullable = false)
private Boolean isReadStatus = false;
@Column(nullable = true)
private String link; // URL to navigate to
@@ -57,8 +57,8 @@ public class SystemNotification {
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public boolean isRead() { return isRead; }
public void setRead(boolean read) { isRead = read; }
public Boolean isReadStatus() { return isReadStatus; }
public void setReadStatus(Boolean readStatus) { isReadStatus = readStatus; }
public String getLink() { return link; }
public void setLink(String link) { this.link = link; }

View File

@@ -2,11 +2,14 @@ package com.rit.canteen.sales.repository;
import com.rit.canteen.sales.model.SystemNotification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface SystemNotificationRepository extends JpaRepository<SystemNotification, Long> {
List<SystemNotification> findByIsReadFalseOrderByCreatedAtDesc();
@Query(value = "SELECT * FROM system_notifications WHERE is_read = false ORDER BY created_at DESC", nativeQuery = true)
List<SystemNotification> findByReadStatusFalse();
List<SystemNotification> findAllByOrderByCreatedAtDesc();
}

View File

@@ -28,7 +28,7 @@ public class SystemNotificationService {
}
public List<SystemNotification> getUnreadNotifications() {
return notificationRepository.findByIsReadFalseOrderByCreatedAtDesc();
return notificationRepository.findByReadStatusFalse();
}
public List<SystemNotification> getAllNotifications() {
@@ -38,16 +38,16 @@ public class SystemNotificationService {
@Transactional
public void markAsRead(Long id) {
notificationRepository.findById(id).ifPresent(n -> {
n.setRead(true);
n.setReadStatus(Boolean.TRUE);
notificationRepository.save(n);
});
}
@Transactional
public void markAllAsRead() {
List<SystemNotification> unread = notificationRepository.findByIsReadFalseOrderByCreatedAtDesc();
List<SystemNotification> unread = notificationRepository.findByReadStatusFalse();
for (SystemNotification n : unread) {
n.setRead(true);
n.setReadStatus(Boolean.TRUE);
}
notificationRepository.saveAll(unread);
}