Merge branch 'main' of https://github.com/Amudieshwar-AG/Freshers-Hub
This commit is contained in:
9
backend/.gitignore
vendored
Normal file
9
backend/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/target/
|
||||
/.settings/
|
||||
/.classpath
|
||||
/.project
|
||||
/.metadata/
|
||||
/bin/
|
||||
*.class
|
||||
.factorypath
|
||||
.springBeans
|
||||
3
backend/.vscode/settings.json
vendored
Normal file
3
backend/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"java.compile.nullAnalysis.mode": "automatic"
|
||||
}
|
||||
90
backend/pom.xml
Normal file
90
backend/pom.xml
Normal file
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.rit</groupId>
|
||||
<artifactId>portal</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Freshers Hub Backend</name>
|
||||
<description>Centralized Spring Boot backend for RIT Freshers Hub</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- Web MVC starter for building REST APIs -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JPA starter for PostgreSQL database connection -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- PostgreSQL database driver -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Project Lombok to avoid boilerplate code (Getters, Setters) -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Validation starter for DTO validators -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Starter Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
13
backend/src/main/java/com/rit/portal/PortalApplication.java
Normal file
13
backend/src/main/java/com/rit/portal/PortalApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.rit.portal;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class PortalApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PortalApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
113
backend/src/main/java/com/rit/portal/config/DataInitializer.java
Normal file
113
backend/src/main/java/com/rit/portal/config/DataInitializer.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package com.rit.portal.config;
|
||||
|
||||
import com.rit.portal.entity.NotePyq;
|
||||
import com.rit.portal.repository.NotePyqRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Component
|
||||
public class DataInitializer implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private NotePyqRepository noteRepository;
|
||||
|
||||
@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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
18
backend/src/main/java/com/rit/portal/config/WebConfig.java
Normal file
18
backend/src/main/java/com/rit/portal/config/WebConfig.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.rit.portal.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/api/**")
|
||||
.allowedOrigins("http://localhost:5173", "http://localhost:3000")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.rit.portal.controller;
|
||||
|
||||
import com.rit.portal.entity.NotePyq;
|
||||
import com.rit.portal.repository.NotePyqRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/notes")
|
||||
@CrossOrigin(origins = "*") // CrossOrigin configured globally, but added here for safety
|
||||
public class NotePyqController {
|
||||
|
||||
@Autowired
|
||||
private NotePyqRepository noteRepository;
|
||||
|
||||
// Get all notes
|
||||
@GetMapping
|
||||
public List<NotePyq> getAllNotes() {
|
||||
return noteRepository.findAll();
|
||||
}
|
||||
|
||||
// Get notes by semester
|
||||
@GetMapping("/semester/{semester}")
|
||||
public List<NotePyq> getNotesBySemester(@PathVariable Integer semester) {
|
||||
return noteRepository.findBySemester(semester);
|
||||
}
|
||||
|
||||
// Get notes by department
|
||||
@GetMapping("/department")
|
||||
public List<NotePyq> getNotesByDepartment(@RequestParam String dept) {
|
||||
return noteRepository.findByDepartment(dept);
|
||||
}
|
||||
|
||||
// Add a new note metadata
|
||||
@PostMapping
|
||||
public NotePyq createNote(@RequestBody NotePyq note) {
|
||||
return noteRepository.save(note);
|
||||
}
|
||||
|
||||
// Increment downloads count
|
||||
@PostMapping("/{id}/download")
|
||||
public ResponseEntity<Void> incrementDownloads(@PathVariable Long id) {
|
||||
return noteRepository.findById(id).map(note -> {
|
||||
note.setDownloadsCount(note.getDownloadsCount() + 1);
|
||||
note.setFileType(note.getFileType()); // Keep dirty check
|
||||
noteRepository.save(note);
|
||||
return ResponseEntity.ok().<Void>build();
|
||||
}).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
46
backend/src/main/java/com/rit/portal/entity/NotePyq.java
Normal file
46
backend/src/main/java/com/rit/portal/entity/NotePyq.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.rit.portal.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "notes_pyqs")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class NotePyq {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String title;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String subject;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String department;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer semester;
|
||||
|
||||
@Column(name = "file_type", nullable = false)
|
||||
private String fileType; // 'notes', 'pyq', 'syllabus', 'assignment'
|
||||
|
||||
@Column(name = "download_url", nullable = false)
|
||||
private String downloadUrl;
|
||||
|
||||
@Column(name = "file_size", nullable = false)
|
||||
private String fileSize;
|
||||
|
||||
@Column(name = "downloads_count")
|
||||
private Integer downloadsCount = 0;
|
||||
|
||||
@Column(name = "uploaded_at")
|
||||
private LocalDateTime uploadedAt = LocalDateTime.now();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.rit.portal.repository;
|
||||
|
||||
import com.rit.portal.entity.NotePyq;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface NotePyqRepository extends JpaRepository<NotePyq, Long> {
|
||||
List<NotePyq> findBySemester(Integer semester);
|
||||
List<NotePyq> findByDepartment(String department);
|
||||
List<NotePyq> findByFileType(String fileType);
|
||||
}
|
||||
13
backend/src/main/resources/application.properties
Normal file
13
backend/src/main/resources/application.properties
Normal file
@@ -0,0 +1,13 @@
|
||||
# ─── DATABASE CONNECTION CONFIGURATION ───
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/rit_freshers_hub?sslmode=disable
|
||||
spring.datasource.username=postgres
|
||||
spring.datasource.password=Amudiesh22@.
|
||||
|
||||
# ─── JPA / HIBERNATE SETTINGS ───
|
||||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.properties.hibernate.format_sql=true
|
||||
|
||||
# ─── SERVER PORT ───
|
||||
server.port=8080
|
||||
Reference in New Issue
Block a user