fix(backend): resolve merge conflict and update application properties

This commit is contained in:
Anbuselvan-dev
2026-07-23 14:31:50 +05:30
parent 9e9700f713
commit 43c570f4f3
90 changed files with 26209 additions and 96 deletions

View File

@@ -28,7 +28,7 @@
<url />
</scm>
<properties>
<java.version>21</java.version>
<java.version>17</java.version>
</properties>
<dependencies>

View File

@@ -17,6 +17,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.rit.portal.controller.NotePyqController;
@Component
public class DataInitializer implements CommandLineRunner {
@@ -26,100 +28,19 @@ public class DataInitializer implements CommandLineRunner {
@Autowired
private BusRouteRepository busRouteRepository;
@Autowired
private NotePyqController notePyqController;
@Override
public void run(String... args) throws Exception {
if (noteRepository.count() == 0) {
noteRepository.saveAll(Arrays.asList(
NotePyq.builder()
.title("Engineering Mathematics Unit 1-5")
.subject("Mathematics")
.department("Computer Science & Engineering")
.semester(1)
.fileType("notes")
.downloadUrl("#")
.fileSize("4.2 MB")
.downloadsCount(348)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("Physics PYQ 2020-2024")
.subject("Physics")
.department("Computer Science & Engineering")
.semester(1)
.fileType("pyq")
.downloadUrl("#")
.fileSize("8.1 MB")
.downloadsCount(512)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("C Programming Complete Notes")
.subject("Programming")
.department("Computer Science & Engineering")
.semester(1)
.fileType("notes")
.downloadUrl("#")
.fileSize("6.3 MB")
.downloadsCount(734)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("Data Structures PYQ 2019-2024")
.subject("Data Structures")
.department("Computer Science & Engineering")
.semester(3)
.fileType("pyq")
.downloadUrl("#")
.fileSize("10.2 MB")
.downloadsCount(621)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("Circuit Theory Full Notes")
.subject("Circuit Theory")
.department("Electronics & Communication")
.semester(2)
.fileType("notes")
.downloadUrl("#")
.fileSize("5.7 MB")
.downloadsCount(289)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("Anna University Syllabus 2021")
.subject("Syllabus")
.department("All Departments")
.semester(1)
.fileType("syllabus")
.downloadUrl("#")
.fileSize("2.1 MB")
.downloadsCount(890)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("Thermodynamics Notes")
.subject("Thermodynamics")
.department("Mechanical Engineering")
.semester(3)
.fileType("notes")
.downloadUrl("#")
.fileSize("3.9 MB")
.downloadsCount(201)
.uploadedAt(LocalDateTime.now())
.build(),
NotePyq.builder()
.title("Digital Electronics PYQ")
.subject("Digital Electronics")
.department("Electronics & Communication")
.semester(4)
.fileType("pyq")
.downloadUrl("#")
.fileSize("7.3 MB")
.downloadsCount(445)
.uploadedAt(LocalDateTime.now())
.build()
));
System.out.println("🌱 Database successfully seeded with Notes & PYQs test data!");
// Clear all previous mock data from the database
noteRepository.deleteAll();
// Run initial scan to populate database with whatever is currently in /uploads
try {
notePyqController.syncUploads();
System.out.println("🌱 Initialized Note/PYQ database from local uploads folder!");
} catch (Exception e) {
System.err.println("⚠️ Failed to run initial uploads sync: " + e.getMessage());
}
// Seed Bus Routes

View File

@@ -9,10 +9,16 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}
@Override
public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) {
registry.addResourceHandler("/uploads/**")
.addResourceLocations("file:uploads/");
}
}

View File

@@ -7,6 +7,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.time.LocalDateTime;
@RestController
@RequestMapping("/api/notes")
public class NotePyqController {
@@ -14,21 +19,117 @@ public class NotePyqController {
@Autowired
private NotePyqRepository noteRepository;
// Sync uploads directory with DB
public synchronized void syncUploads() {
File uploadsDir = new File("uploads");
if (!uploadsDir.exists()) {
uploadsDir.mkdirs();
}
List<NotePyq> currentNotes = noteRepository.findAll();
List<String> activeUrls = Collections.synchronizedList(new ArrayList<>());
File[] semDirs = uploadsDir.listFiles();
if (semDirs != null) {
for (File semDir : semDirs) {
if (semDir.isDirectory() && semDir.getName().startsWith("sem")) {
String semStr = semDir.getName().substring(3);
try {
Integer semester = Integer.parseInt(semStr);
File[] subDirs = semDir.listFiles();
if (subDirs != null) {
for (File subDir : subDirs) {
if (subDir.isDirectory()) {
String subject = subDir.getName();
File[] typeDirs = subDir.listFiles();
if (typeDirs != null) {
for (File typeDir : typeDirs) {
if (typeDir.isDirectory()) {
String fileType = typeDir.getName();
File[] files = typeDir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile() && !file.getName().equals(".gitkeep")) {
String fileName = file.getName();
String downloadUrl = "http://localhost:8080/uploads/" +
semDir.getName() + "/" +
subDir.getName() + "/" +
typeDir.getName() + "/" +
fileName;
activeUrls.add(downloadUrl);
boolean exists = currentNotes.stream().anyMatch(n -> n.getDownloadUrl().equals(downloadUrl));
if (!exists) {
String baseName = fileName.contains(".") ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName;
String title = baseName.replace("_", " ").replace("-", " ");
String department = "All Departments";
long bytes = file.length();
String fileSize = formatFileSize(bytes);
NotePyq newNote = NotePyq.builder()
.title(title)
.subject(subject)
.department(department)
.semester(semester)
.fileType(fileType)
.downloadUrl(downloadUrl)
.fileSize(fileSize)
.downloadsCount(0)
.uploadedAt(LocalDateTime.now())
.build();
noteRepository.save(newNote);
}
}
}
}
}
}
}
}
}
}
} catch (NumberFormatException e) {
// Ignore
}
}
}
}
// Delete notes from DB that no longer exist on disk
for (NotePyq note : currentNotes) {
if (!activeUrls.contains(note.getDownloadUrl())) {
noteRepository.delete(note);
}
}
}
private String formatFileSize(long bytes) {
if (bytes < 1024) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(1024));
char pre = "KMGTPE".charAt(exp - 1);
return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre);
}
// Get all notes
@GetMapping
public List<NotePyq> getAllNotes() {
syncUploads();
return noteRepository.findAll();
}
// Get notes by semester
@GetMapping("/semester/{semester}")
public List<NotePyq> getNotesBySemester(@PathVariable Integer semester) {
syncUploads();
return noteRepository.findBySemester(semester);
}
// Get notes by department
@GetMapping("/department")
public List<NotePyq> getNotesByDepartment(@RequestParam String dept) {
syncUploads();
return noteRepository.findByDepartment(dept);
}

View File

@@ -1,7 +1,11 @@
# ─── DATABASE CONNECTION CONFIGURATION ───
spring.datasource.url=jdbc:postgresql://localhost:5433/rit_freshers_hub?sslmode=disable
spring.datasource.url=jdbc:postgresql://localhost:5432/rit_freshers_hub?sslmode=disable
spring.datasource.username=postgres
spring.datasource.password=Anbukathir@#$2006
<<<<<<< Updated upstream
spring.datasource.password=your_local_postgres_password_here
=======
spring.datasource.password=${DB_PASSWORD:Amudiesh22@.}
>>>>>>> Stashed changes
# ─── JPA / HIBERNATE SETTINGS ───
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

File diff suppressed because it is too large Load Diff