Compare commits
11 Commits
7b153f4cf6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bd2f5b95ce | |||
| cfe68a276f | |||
| 911933074b | |||
| 9712439261 | |||
| 7d701d3747 | |||
| d8be4e7ca1 | |||
| 279c6f9c1a | |||
| f41a1043c9 | |||
| e206968993 | |||
| bd5119fc3c | |||
| 9c6c3abc32 |
26
docker-compose.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
version: '3.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
cmc-new-backend:
|
||||||
|
build:
|
||||||
|
context: ./support-portal-backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "8070:8080"
|
||||||
|
environment:
|
||||||
|
- DATABASE_HOST=mysql-common-mysql-1
|
||||||
|
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql-common-mysql-1:3306/demo
|
||||||
|
- SPRING_DATASOURCE_USERNAME=youruser
|
||||||
|
- SPRING_DATASOURCE_PASSWORD=youruserpassword
|
||||||
|
networks:
|
||||||
|
- cmc-forntend
|
||||||
|
- mysql-common_mynetwork
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db-data: {}
|
||||||
|
|
||||||
|
networks:
|
||||||
|
cmc-forntend: {}
|
||||||
|
mysql-common_mynetwork:
|
||||||
|
external: true
|
||||||
15
support-portal-backend/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
FROM --platform=$BUILDPLATFORM maven:3.8.5-eclipse-temurin-17 AS builder
|
||||||
|
WORKDIR /workdir/server
|
||||||
|
COPY pom.xml /workdir/server/pom.xml
|
||||||
|
RUN mvn dependency:go-offline
|
||||||
|
|
||||||
|
COPY src /workdir/server/src
|
||||||
|
RUN mvn package -Dmaven.test.skip=true
|
||||||
|
RUN ls -la target/
|
||||||
|
|
||||||
|
FROM eclipse-temurin:17-jre-focal
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
VOLUME /tmp
|
||||||
|
COPY --from=builder /workdir/server/target/*.jar /app/app.jar
|
||||||
|
ENTRYPOINT ["java","-jar","/app/app.jar"]
|
||||||
@ -15,8 +15,11 @@
|
|||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
|
||||||
<mapstruct.version>1.4.2.Final</mapstruct.version>
|
|
||||||
|
<mapstruct.version>1.5.5.Final</mapstruct.version>
|
||||||
|
|
||||||
<docker.image.prefix>artarkatesoft</docker.image.prefix>
|
<docker.image.prefix>artarkatesoft</docker.image.prefix>
|
||||||
<docker.image.name>angular-${project.artifactId}</docker.image.name>
|
<docker.image.name>angular-${project.artifactId}</docker.image.name>
|
||||||
@ -29,6 +32,12 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||||
|
</dependency> -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
@ -100,11 +109,11 @@
|
|||||||
<version>1.12.75</version>
|
<version>1.12.75</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!-- <dependency>
|
||||||
<groupId>com.github.ulisesbocchio</groupId>
|
<groupId>com.github.ulisesbocchio</groupId>
|
||||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||||
<version>3.0.3</version>
|
<version>3.0.3</version>
|
||||||
</dependency>
|
</dependency> -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -158,6 +167,12 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
@ -195,11 +210,7 @@
|
|||||||
</path>
|
</path>
|
||||||
|
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
<compilerArgs>
|
|
||||||
<compilerArg>
|
|
||||||
-Amapstruct.defaultComponentModel=spring
|
|
||||||
</compilerArg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
@ -246,6 +257,9 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.config;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.User;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.UserRepository;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.shyshkin.study.fullstack.supportportal.backend.constant.Authority.*;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class DataInitializer {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CommandLineRunner init(UserRepository userRepository, PasswordEncoder passwordEncoder) {
|
||||||
|
return args -> {
|
||||||
|
System.out.println("Running DataInitializer...");
|
||||||
|
|
||||||
|
// Initialize users
|
||||||
|
createUserIfNotExists(userRepository, passwordEncoder, "admin", "adminpassword", "admin@example.com", "Admin", "User", "ROLE_ADMIN");
|
||||||
|
createUserIfNotExists(userRepository, passwordEncoder, "hr", "hrpassword", "hr@example.com", "HR", "User", "ROLE_HR");
|
||||||
|
createUserIfNotExists(userRepository, passwordEncoder, "manager", "managerpassword", "manager@example.com", "Manager", "User", "ROLE_MANAGER");
|
||||||
|
createUserIfNotExists(userRepository, passwordEncoder, "user", "userpassword", "user@example.com", "Regular", "User", "ROLE_USER");
|
||||||
|
createUserIfNotExists(userRepository, passwordEncoder, "superadmin", "superadminpassword", "superadmin@example.com", "Super", "Admin", "ROLE_SUPER_ADMIN");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUserIfNotExists(UserRepository userRepository, PasswordEncoder passwordEncoder,
|
||||||
|
String username, String password, String email,
|
||||||
|
String firstName, String lastName, String role) {
|
||||||
|
if (userRepository.findByUsername(username).isEmpty()) {
|
||||||
|
String encodedPassword = passwordEncoder.encode(password);
|
||||||
|
|
||||||
|
User user = User.builder()
|
||||||
|
.email(email)
|
||||||
|
.firstName(firstName)
|
||||||
|
.lastName(lastName)
|
||||||
|
.username(username)
|
||||||
|
.password(encodedPassword)
|
||||||
|
.userId(UUID.randomUUID())
|
||||||
|
.isActive(true)
|
||||||
|
.isNotLocked(true)
|
||||||
|
.role(role)
|
||||||
|
.authorities(getAuthoritiesByRole(role))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
userRepository.save(user);
|
||||||
|
System.out.println(role + " user created successfully.");
|
||||||
|
} else {
|
||||||
|
System.out.println(role + " user already exists.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getAuthoritiesByRole(String role) {
|
||||||
|
switch (role) {
|
||||||
|
case "ROLE_ADMIN":
|
||||||
|
return ADMIN_AUTHORITIES;
|
||||||
|
case "ROLE_HR":
|
||||||
|
return HR_AUTHORITIES;
|
||||||
|
case "ROLE_MANAGER":
|
||||||
|
return MANAGER_AUTHORITIES;
|
||||||
|
case "ROLE_USER":
|
||||||
|
return USER_AUTHORITIES;
|
||||||
|
case "ROLE_SUPER_ADMIN":
|
||||||
|
return SUPER_ADMIN_AUTHORITIES;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid role: " + role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
// package com.example.tamilnadureservoir.config;
|
||||||
|
|
||||||
|
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.config;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate() {
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -14,4 +14,10 @@ public class FileConstant {
|
|||||||
public static final String NOT_AN_IMAGE_FILE = " is not an image file. Please upload an image file";
|
public static final String NOT_AN_IMAGE_FILE = " is not an image file. Please upload an image file";
|
||||||
public static final String TEMP_PROFILE_IMAGE_BASE_URL = "https://robohash.org/";
|
public static final String TEMP_PROFILE_IMAGE_BASE_URL = "https://robohash.org/";
|
||||||
|
|
||||||
|
// public static final String PROFESSOR_IMAGE_PATH = "/professor/image/";
|
||||||
|
// public static final String PROFESSOR_FOLDER = System.getProperty("user.home") + "/supportportal/professor/";
|
||||||
|
// public static final String DEFAULT_PROFESSOR_IMAGE_URI_PATTERN = "/professor/%s/profile-image";
|
||||||
|
// public static final String PROFESSOR_IMAGE_FILENAME = "avatar.jpg";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,97 @@
|
|||||||
|
// CourseApplicationController.java - REST Controller for Course Applications
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Course;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.CourseApplication;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.CourseApplicationDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.CourseRepository;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.CourseApplicationRepository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/course-applications")
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class CourseApplicationController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseApplicationRepository courseApplicationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseRepository courseRepository;
|
||||||
|
|
||||||
|
// Get all applications (for admin)
|
||||||
|
@GetMapping
|
||||||
|
public List<CourseApplication> getAllApplications() {
|
||||||
|
return courseApplicationRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get applications by course ID
|
||||||
|
@GetMapping("/course/{courseId}")
|
||||||
|
public ResponseEntity<List<CourseApplication>> getApplicationsByCourseId(@PathVariable Long courseId) {
|
||||||
|
try {
|
||||||
|
List<CourseApplication> applications = courseApplicationRepository.findAllByCourseId(courseId);
|
||||||
|
return ResponseEntity.ok(applications);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single application by ID
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<CourseApplication> getApplicationById(@PathVariable Long id) {
|
||||||
|
return courseApplicationRepository.findById(id)
|
||||||
|
.map(application -> ResponseEntity.ok(application))
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<?> createApplication(@RequestBody CourseApplicationDto applicationDto) {
|
||||||
|
Course course = courseRepository.findById(applicationDto.getCourseId())
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Course not found"));
|
||||||
|
|
||||||
|
CourseApplication application = new CourseApplication();
|
||||||
|
application.setCourse(course);
|
||||||
|
application.setFullName(applicationDto.getFullName());
|
||||||
|
application.setEmail(applicationDto.getEmail());
|
||||||
|
application.setPhone(applicationDto.getPhone());
|
||||||
|
application.setQualification(applicationDto.getQualification());
|
||||||
|
application.setExperience(applicationDto.getExperience());
|
||||||
|
application.setCoverLetter(applicationDto.getCoverLetter());
|
||||||
|
application.setResumeUrl(applicationDto.getResumeUrl());
|
||||||
|
|
||||||
|
courseApplicationRepository.save(application);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}/status")
|
||||||
|
public ResponseEntity<?> updateApplicationStatus(@PathVariable Long id, @RequestParam String status) {
|
||||||
|
CourseApplication application = courseApplicationRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Application not found"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
application.setStatus(CourseApplication.ApplicationStatus.valueOf(status.toUpperCase()));
|
||||||
|
courseApplicationRepository.save(application);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return ResponseEntity.badRequest().body("Invalid status: " + status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteApplication(@PathVariable Long id) {
|
||||||
|
return courseApplicationRepository.findById(id)
|
||||||
|
.map(application -> {
|
||||||
|
courseApplicationRepository.delete(application);
|
||||||
|
return ResponseEntity.noContent().<Void>build();
|
||||||
|
})
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
// CourseController.java - REST Controller for Courses
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Course;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.CourseDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.CourseRepository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/courses")
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class CourseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseRepository courseRepository;
|
||||||
|
|
||||||
|
// Get all active courses (for public display)
|
||||||
|
@GetMapping("/active")
|
||||||
|
public ResponseEntity<List<Course>> getActiveCourses() {
|
||||||
|
try {
|
||||||
|
List<Course> courses = courseRepository.findAllByIsActiveTrue();
|
||||||
|
return ResponseEntity.ok(courses);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all courses (for admin)
|
||||||
|
@GetMapping
|
||||||
|
public List<Course> getAllCourses() {
|
||||||
|
return courseRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single course by ID
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<Course> getCourseById(@PathVariable Long id) {
|
||||||
|
return courseRepository.findById(id)
|
||||||
|
.map(course -> ResponseEntity.ok(course))
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<?> createCourse(@RequestBody CourseDto courseDto) {
|
||||||
|
Course course = new Course();
|
||||||
|
course.setTitle(courseDto.getTitle());
|
||||||
|
course.setDescription(courseDto.getDescription());
|
||||||
|
course.setDuration(courseDto.getDuration());
|
||||||
|
course.setSeats(courseDto.getSeats());
|
||||||
|
course.setCategory(courseDto.getCategory());
|
||||||
|
course.setLevel(courseDto.getLevel());
|
||||||
|
course.setInstructor(courseDto.getInstructor());
|
||||||
|
course.setPrice(courseDto.getPrice());
|
||||||
|
course.setStartDate(courseDto.getStartDate());
|
||||||
|
course.setImageUrl(courseDto.getImageUrl());
|
||||||
|
course.setEligibility(courseDto.getEligibility());
|
||||||
|
course.setObjectives(courseDto.getObjectives());
|
||||||
|
course.setActive(courseDto.isActive());
|
||||||
|
|
||||||
|
courseRepository.save(course);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<?> updateCourse(@PathVariable Long id, @RequestBody CourseDto courseDto) {
|
||||||
|
Course course = courseRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Course not found"));
|
||||||
|
|
||||||
|
course.setTitle(courseDto.getTitle());
|
||||||
|
course.setDescription(courseDto.getDescription());
|
||||||
|
course.setDuration(courseDto.getDuration());
|
||||||
|
course.setSeats(courseDto.getSeats());
|
||||||
|
course.setCategory(courseDto.getCategory());
|
||||||
|
course.setLevel(courseDto.getLevel());
|
||||||
|
course.setInstructor(courseDto.getInstructor());
|
||||||
|
course.setPrice(courseDto.getPrice());
|
||||||
|
course.setStartDate(courseDto.getStartDate());
|
||||||
|
course.setImageUrl(courseDto.getImageUrl());
|
||||||
|
course.setEligibility(courseDto.getEligibility());
|
||||||
|
course.setObjectives(courseDto.getObjectives());
|
||||||
|
course.setActive(courseDto.isActive());
|
||||||
|
|
||||||
|
courseRepository.save(course);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteCourse(@PathVariable Long id) {
|
||||||
|
return courseRepository.findById(id)
|
||||||
|
.map(course -> {
|
||||||
|
courseRepository.delete(course);
|
||||||
|
return ResponseEntity.noContent().<Void>build();
|
||||||
|
})
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Event;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.EventRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/events")
|
||||||
|
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.OPTIONS})
|
||||||
|
public class EventController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EventRepository eventRepository;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<Event>> getAllEvents() {
|
||||||
|
List<Event> events = eventRepository.findAll();
|
||||||
|
return new ResponseEntity<>(events, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<Event> getEventById(@PathVariable Long id) {
|
||||||
|
Optional<Event> event = eventRepository.findById(id);
|
||||||
|
return event.map(ResponseEntity::ok)
|
||||||
|
.orElseGet(() -> ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<Event> createEvent(@RequestBody Event event) {
|
||||||
|
try {
|
||||||
|
Event savedEvent = eventRepository.save(event);
|
||||||
|
return new ResponseEntity<>(savedEvent, HttpStatus.CREATED);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<Event> updateEvent(@PathVariable Long id, @RequestBody Event event) {
|
||||||
|
if (!eventRepository.existsById(id)) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
event.setId(id);
|
||||||
|
Event updatedEvent = eventRepository.save(event);
|
||||||
|
return new ResponseEntity<>(updatedEvent, HttpStatus.OK);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteEvent(@PathVariable Long id) {
|
||||||
|
if (!eventRepository.existsById(id)) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
eventRepository.deleteById(id);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional endpoint to get upcoming events
|
||||||
|
@GetMapping("/upcoming")
|
||||||
|
public ResponseEntity<List<Event>> getUpcomingEvents() {
|
||||||
|
List<Event> events = eventRepository.findByIsActiveTrueOrderByDateAsc();
|
||||||
|
return new ResponseEntity<>(events, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional endpoint to get past events
|
||||||
|
@GetMapping("/past")
|
||||||
|
public ResponseEntity<List<Event>> getPastEvents() {
|
||||||
|
List<Event> events = eventRepository.findByIsActiveTrueOrderByDateDesc();
|
||||||
|
return new ResponseEntity<>(events, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,120 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/files")
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class FileController { // Changed from FileUploadController to FileController
|
||||||
|
|
||||||
|
@Value("${file.upload.directory:uploads}")
|
||||||
|
private String uploadDirectory;
|
||||||
|
|
||||||
|
@Value("${app.base-url:http://localhost:8080}")
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||||
|
System.out.println("=== FILE UPLOAD DEBUG ===");
|
||||||
|
System.out.println("File name: " + file.getOriginalFilename());
|
||||||
|
System.out.println("Content type: " + file.getContentType());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
return ResponseEntity.badRequest().body("File is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updated validation to accept both images and documents
|
||||||
|
String contentType = file.getContentType();
|
||||||
|
if (!isValidFileType(contentType)) {
|
||||||
|
return ResponseEntity.badRequest().body("Invalid file type. Only images and documents (PDF, DOC, DOCX) are allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create upload directory if it doesn't exist
|
||||||
|
Path uploadPath = Paths.get(uploadDirectory);
|
||||||
|
if (!Files.exists(uploadPath)) {
|
||||||
|
Files.createDirectories(uploadPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate unique filename
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||||
|
String uniqueFilename = UUID.randomUUID().toString() + fileExtension;
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
Path filePath = uploadPath.resolve(uniqueFilename);
|
||||||
|
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
// Return file URL - use generic /files/ path for documents
|
||||||
|
String fileUrl = "/uploads/" + uniqueFilename;
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
response.put("url", fileUrl);
|
||||||
|
response.put("filename", uniqueFilename);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Failed to upload file: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updated validation method
|
||||||
|
private boolean isValidFileType(String contentType) {
|
||||||
|
return contentType != null && (
|
||||||
|
// Image types
|
||||||
|
contentType.equals("image/jpeg") ||
|
||||||
|
contentType.equals("image/jpg") ||
|
||||||
|
contentType.equals("image/png") ||
|
||||||
|
contentType.equals("image/gif") ||
|
||||||
|
contentType.equals("image/webp") ||
|
||||||
|
// Document types for resumes
|
||||||
|
contentType.equals("application/pdf") ||
|
||||||
|
contentType.equals("application/msword") ||
|
||||||
|
contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/images/{filename}")
|
||||||
|
public ResponseEntity<byte[]> getImage(@PathVariable String filename) {
|
||||||
|
try {
|
||||||
|
Path filePath = Paths.get(uploadDirectory).resolve(filename);
|
||||||
|
if (!Files.exists(filePath)) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] imageBytes = Files.readAllBytes(filePath);
|
||||||
|
String contentType = Files.probeContentType(filePath);
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header("Content-Type", contentType != null ? contentType : "application/octet-stream")
|
||||||
|
.body(imageBytes);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValidImageType(String contentType) {
|
||||||
|
return contentType != null && (
|
||||||
|
contentType.equals("image/jpeg") ||
|
||||||
|
contentType.equals("image/jpg") ||
|
||||||
|
contentType.equals("image/png") ||
|
||||||
|
contentType.equals("image/gif") ||
|
||||||
|
contentType.equals("image/webp")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,127 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.service.ProfileImageService;
|
||||||
|
import org.springframework.http.CacheControl;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class ImageController {
|
||||||
|
|
||||||
|
private final ProfileImageService profileImageService;
|
||||||
|
|
||||||
|
@GetMapping("/{professorId}/profile-image/{filename}")
|
||||||
|
public ResponseEntity<byte[]> getProfileImage(
|
||||||
|
@PathVariable UUID professorId,
|
||||||
|
@PathVariable String filename) {
|
||||||
|
try {
|
||||||
|
log.debug("Fetching profile image for professor: {} with filename: {}", professorId, filename);
|
||||||
|
|
||||||
|
byte[] imageBytes = profileImageService.retrieveProfileImage(professorId, filename);
|
||||||
|
|
||||||
|
if (imageBytes == null || imageBytes.length == 0) {
|
||||||
|
log.warn("No image data found for professor: {} with filename: {}", professorId, filename);
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
||||||
|
// Determine content type based on filename
|
||||||
|
String contentType = getContentTypeFromFilename(filename);
|
||||||
|
headers.setContentType(MediaType.parseMediaType(contentType));
|
||||||
|
|
||||||
|
// Set cache control
|
||||||
|
headers.setCacheControl(CacheControl.maxAge(Duration.ofHours(1)).cachePublic());
|
||||||
|
|
||||||
|
log.debug("Successfully retrieved image for professor: {}, size: {} bytes", professorId, imageBytes.length);
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.headers(headers)
|
||||||
|
.body(imageBytes);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error retrieving profile image for professor: {} with filename: {}", professorId, filename, e);
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{professorId}/profile-image")
|
||||||
|
public ResponseEntity<byte[]> getDefaultProfileImage(@PathVariable UUID professorId) {
|
||||||
|
try {
|
||||||
|
log.debug("Fetching default profile image for professor: {}", professorId);
|
||||||
|
|
||||||
|
// Try to get the default image (avatar.jpg or similar)
|
||||||
|
byte[] imageBytes = profileImageService.retrieveProfileImage(professorId, "avatar.jpg");
|
||||||
|
|
||||||
|
if (imageBytes == null || imageBytes.length == 0) {
|
||||||
|
log.warn("No default image found for professor: {}", professorId);
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.IMAGE_JPEG);
|
||||||
|
headers.setCacheControl(CacheControl.maxAge(Duration.ofHours(1)).cachePublic());
|
||||||
|
|
||||||
|
log.debug("Successfully retrieved default image for professor: {}, size: {} bytes", professorId, imageBytes.length);
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.headers(headers)
|
||||||
|
.body(imageBytes);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error retrieving default profile image for professor: {}", professorId, e);
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint to check if a profile image exists
|
||||||
|
*/
|
||||||
|
@GetMapping("/{professorId}/profile-image/exists")
|
||||||
|
public ResponseEntity<Boolean> checkProfileImageExists(@PathVariable UUID professorId) {
|
||||||
|
try {
|
||||||
|
byte[] imageBytes = profileImageService.retrieveProfileImage(professorId, "avatar.jpg");
|
||||||
|
boolean exists = imageBytes != null && imageBytes.length > 0;
|
||||||
|
|
||||||
|
return ResponseEntity.ok(exists);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error checking if profile image exists for professor: {}", professorId, e);
|
||||||
|
return ResponseEntity.ok(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine content type based on file extension
|
||||||
|
*/
|
||||||
|
private String getContentTypeFromFilename(String filename) {
|
||||||
|
if (filename == null) {
|
||||||
|
return MediaType.IMAGE_JPEG_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
String lowerCaseFilename = filename.toLowerCase();
|
||||||
|
|
||||||
|
if (lowerCaseFilename.endsWith(".png")) {
|
||||||
|
return MediaType.IMAGE_PNG_VALUE;
|
||||||
|
} else if (lowerCaseFilename.endsWith(".gif")) {
|
||||||
|
return MediaType.IMAGE_GIF_VALUE;
|
||||||
|
} else if (lowerCaseFilename.endsWith(".webp")) {
|
||||||
|
return "image/webp";
|
||||||
|
} else if (lowerCaseFilename.endsWith(".bmp")) {
|
||||||
|
return "image/bmp";
|
||||||
|
} else {
|
||||||
|
// Default to JPEG
|
||||||
|
return MediaType.IMAGE_JPEG_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Job;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.JobApplication;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.JobApplicationDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.JobRepository;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.JobApplicationRepository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/job-applications")
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class JobApplicationController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JobApplicationRepository jobApplicationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JobRepository jobRepository;
|
||||||
|
|
||||||
|
// Get all applications (for admin)
|
||||||
|
@GetMapping
|
||||||
|
public List<JobApplication> getAllApplications() {
|
||||||
|
return jobApplicationRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get applications by job ID
|
||||||
|
@GetMapping("/job/{jobId}")
|
||||||
|
public ResponseEntity<List<JobApplication>> getApplicationsByJobId(@PathVariable Long jobId) {
|
||||||
|
try {
|
||||||
|
List<JobApplication> applications = jobApplicationRepository.findAllByJobId(jobId);
|
||||||
|
return ResponseEntity.ok(applications);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single application by ID
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<JobApplication> getApplicationById(@PathVariable Long id) {
|
||||||
|
return jobApplicationRepository.findById(id)
|
||||||
|
.map(application -> ResponseEntity.ok(application))
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<?> createApplication(@RequestBody JobApplicationDto applicationDto) {
|
||||||
|
Job job = jobRepository.findById(applicationDto.getJobId())
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Job not found"));
|
||||||
|
|
||||||
|
JobApplication application = new JobApplication();
|
||||||
|
application.setJob(job);
|
||||||
|
application.setFullName(applicationDto.getFullName());
|
||||||
|
application.setEmail(applicationDto.getEmail());
|
||||||
|
application.setPhone(applicationDto.getPhone());
|
||||||
|
application.setExperience(applicationDto.getExperience());
|
||||||
|
application.setCoverLetter(applicationDto.getCoverLetter());
|
||||||
|
application.setResumeUrl(applicationDto.getResumeUrl());
|
||||||
|
|
||||||
|
jobApplicationRepository.save(application);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}/status")
|
||||||
|
public ResponseEntity<?> updateApplicationStatus(@PathVariable Long id, @RequestParam String status) {
|
||||||
|
JobApplication application = jobApplicationRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Application not found"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
application.setStatus(JobApplication.ApplicationStatus.valueOf(status.toUpperCase()));
|
||||||
|
jobApplicationRepository.save(application);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return ResponseEntity.badRequest().body("Invalid status: " + status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteApplication(@PathVariable Long id) {
|
||||||
|
return jobApplicationRepository.findById(id)
|
||||||
|
.map(application -> {
|
||||||
|
jobApplicationRepository.delete(application);
|
||||||
|
return ResponseEntity.noContent().<Void>build();
|
||||||
|
})
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
// JobController.java - REST Controller for Jobs
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Job;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.JobDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.JobRepository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/jobs")
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class JobController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JobRepository jobRepository;
|
||||||
|
|
||||||
|
// Get all active jobs (for public display)
|
||||||
|
@GetMapping("/active")
|
||||||
|
public ResponseEntity<List<Job>> getActiveJobs() {
|
||||||
|
try {
|
||||||
|
List<Job> jobs = jobRepository.findAllByIsActiveTrue();
|
||||||
|
return ResponseEntity.ok(jobs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all jobs (for admin)
|
||||||
|
@GetMapping
|
||||||
|
public List<Job> getAllJobs() {
|
||||||
|
return jobRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single job by ID
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<Job> getJobById(@PathVariable Long id) {
|
||||||
|
return jobRepository.findById(id)
|
||||||
|
.map(job -> ResponseEntity.ok(job))
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<?> createJob(@RequestBody JobDto jobDto) {
|
||||||
|
System.out.println("=== BACKEND DEBUG ===");
|
||||||
|
System.out.println("Received JobDto: " + jobDto);
|
||||||
|
System.out.println("isActive value: " + jobDto.isActive());
|
||||||
|
// Remove the .getClass() line since boolean is a primitive
|
||||||
|
|
||||||
|
Job job = new Job();
|
||||||
|
job.setTitle(jobDto.getTitle());
|
||||||
|
job.setDepartment(jobDto.getDepartment());
|
||||||
|
job.setLocation(jobDto.getLocation());
|
||||||
|
job.setType(jobDto.getType());
|
||||||
|
job.setExperience(jobDto.getExperience());
|
||||||
|
job.setSalary(jobDto.getSalary());
|
||||||
|
job.setDescription(jobDto.getDescription());
|
||||||
|
job.setRequirements(jobDto.getRequirements());
|
||||||
|
job.setResponsibilities(jobDto.getResponsibilities());
|
||||||
|
job.setActive(jobDto.isActive());
|
||||||
|
|
||||||
|
System.out.println("Job before save - isActive: " + job.isActive());
|
||||||
|
|
||||||
|
Job savedJob = jobRepository.save(job);
|
||||||
|
System.out.println("Job after save - isActive: " + savedJob.isActive());
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<?> updateJob(@PathVariable Long id, @RequestBody JobDto jobDto) {
|
||||||
|
Job job = jobRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Job not found"));
|
||||||
|
|
||||||
|
job.setTitle(jobDto.getTitle());
|
||||||
|
job.setDepartment(jobDto.getDepartment());
|
||||||
|
job.setLocation(jobDto.getLocation());
|
||||||
|
job.setType(jobDto.getType());
|
||||||
|
job.setExperience(jobDto.getExperience());
|
||||||
|
job.setSalary(jobDto.getSalary());
|
||||||
|
job.setDescription(jobDto.getDescription());
|
||||||
|
job.setRequirements(jobDto.getRequirements());
|
||||||
|
job.setResponsibilities(jobDto.getResponsibilities());
|
||||||
|
job.setActive(jobDto.isActive());
|
||||||
|
|
||||||
|
jobRepository.save(job);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteJob(@PathVariable Long id) {
|
||||||
|
return jobRepository.findById(id)
|
||||||
|
.map(job -> {
|
||||||
|
jobRepository.delete(job);
|
||||||
|
return ResponseEntity.noContent().<Void>build();
|
||||||
|
})
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,227 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Post;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.PostDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.PostRepository;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.ProfessorRepository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/posts")
|
||||||
|
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.OPTIONS})
|
||||||
|
public class PostController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PostRepository postRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProfessorRepository professorRepository;
|
||||||
|
|
||||||
|
// Get all posts where isPosted is true
|
||||||
|
@GetMapping("/posted")
|
||||||
|
public ResponseEntity<List<Post>> getAllPostedPosts() {
|
||||||
|
try {
|
||||||
|
log.info("Fetching all posted posts");
|
||||||
|
List<Post> posts = postRepository.findAllByIsPostedTrue();
|
||||||
|
log.info("Retrieved {} posted posts", posts.size());
|
||||||
|
return ResponseEntity.ok(posts);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error fetching posted posts: ", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all unique tags with count
|
||||||
|
@GetMapping("/tags/count")
|
||||||
|
public ResponseEntity<Map<String, Long>> getTagsWithCount() {
|
||||||
|
try {
|
||||||
|
log.info("Fetching tag counts");
|
||||||
|
List<Object[]> tagCounts = postRepository.findTagsWithCount();
|
||||||
|
Map<String, Long> tagCountMap = new HashMap<>();
|
||||||
|
for (Object[] tagCount : tagCounts) {
|
||||||
|
tagCountMap.put((String) tagCount[0], (Long) tagCount[1]);
|
||||||
|
}
|
||||||
|
log.info("Retrieved {} unique tags", tagCountMap.size());
|
||||||
|
return ResponseEntity.ok(tagCountMap);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error fetching tag counts: ", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all posts associated with a specific tag where isPosted is true
|
||||||
|
@GetMapping("/tag/{tag}")
|
||||||
|
public ResponseEntity<List<Post>> getPostsByTag(@PathVariable String tag) {
|
||||||
|
try {
|
||||||
|
log.info("Fetching posts by tag: {}", tag);
|
||||||
|
List<Post> posts = postRepository.findAllByTagAndIsPostedTrue(tag);
|
||||||
|
log.info("Retrieved {} posts for tag: {}", posts.size(), tag);
|
||||||
|
return ResponseEntity.ok(posts);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error fetching posts by tag {}: ", tag, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all posts
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<Post>> getAllPosts() {
|
||||||
|
try {
|
||||||
|
log.info("Fetching all posts");
|
||||||
|
List<Post> posts = postRepository.findAll();
|
||||||
|
log.info("Retrieved {} posts", posts.size());
|
||||||
|
return ResponseEntity.ok(posts);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error fetching all posts: ", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single post by ID
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<Post> getPostById(@PathVariable Long id) {
|
||||||
|
try {
|
||||||
|
log.info("Fetching post with id: {}", id);
|
||||||
|
return postRepository.findById(id)
|
||||||
|
.map(post -> {
|
||||||
|
log.info("Found post with id: {}", id);
|
||||||
|
return ResponseEntity.ok(post);
|
||||||
|
})
|
||||||
|
.orElseGet(() -> {
|
||||||
|
log.warn("Post not found with id: {}", id);
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error fetching post with id {}: ", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<?> createPost(@RequestBody PostDto postDto) {
|
||||||
|
try {
|
||||||
|
// Debug logging to see what data is being received
|
||||||
|
log.info("Creating new post with data:");
|
||||||
|
log.info("Title: {}", postDto.getTitle());
|
||||||
|
log.info("Content: {}", postDto.getContent());
|
||||||
|
log.info("Posted: {}", postDto.isPosted());
|
||||||
|
log.info("ImageUrl: {}", postDto.getImageUrl());
|
||||||
|
log.info("Professors: {}", postDto.getProfessors());
|
||||||
|
log.info("Tags: {}", postDto.getTags());
|
||||||
|
|
||||||
|
Post post = new Post();
|
||||||
|
post.setTitle(postDto.getTitle());
|
||||||
|
post.setContent(postDto.getContent());
|
||||||
|
post.setPosted(postDto.isPosted());
|
||||||
|
post.setImageUrl(postDto.getImageUrl());
|
||||||
|
|
||||||
|
// Fetch professors from IDs, filter out null IDs
|
||||||
|
List<Long> validProfessorIds = postDto.getProfessors().stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Professor> professors = professorRepository.findAllById(validProfessorIds);
|
||||||
|
post.setProfessors(professors);
|
||||||
|
|
||||||
|
// Set tags
|
||||||
|
post.setTags(postDto.getTags());
|
||||||
|
|
||||||
|
// Save the post
|
||||||
|
Post savedPost = postRepository.save(post);
|
||||||
|
log.info("Successfully created post with id: {}", savedPost.getId());
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(savedPost);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error creating post: ", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Failed to create post: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<?> updatePost(@PathVariable Long id, @RequestBody PostDto postDto) {
|
||||||
|
try {
|
||||||
|
log.info("Updating post with id: {}", id);
|
||||||
|
log.info("New Title: {}", postDto.getTitle());
|
||||||
|
log.info("New Content length: {}", postDto.getContent() != null ? postDto.getContent().length() : 0);
|
||||||
|
log.info("New Posted status: {}", postDto.isPosted());
|
||||||
|
log.info("New ImageUrl: {}", postDto.getImageUrl());
|
||||||
|
|
||||||
|
Post post = postRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Post not found with id: " + id));
|
||||||
|
|
||||||
|
post.setTitle(postDto.getTitle());
|
||||||
|
post.setContent(postDto.getContent());
|
||||||
|
post.setPosted(postDto.isPosted());
|
||||||
|
post.setImageUrl(postDto.getImageUrl());
|
||||||
|
|
||||||
|
// Fetch professors from IDs, filter out null IDs
|
||||||
|
List<Long> validProfessorIds = postDto.getProfessors().stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Professor> professors = professorRepository.findAllById(validProfessorIds);
|
||||||
|
post.setProfessors(professors);
|
||||||
|
|
||||||
|
// Set tags
|
||||||
|
post.setTags(postDto.getTags());
|
||||||
|
|
||||||
|
// Save the updated post
|
||||||
|
Post updatedPost = postRepository.save(post);
|
||||||
|
log.info("Successfully updated post with id: {}", id);
|
||||||
|
return ResponseEntity.ok(updatedPost);
|
||||||
|
|
||||||
|
} catch (ResourceNotFoundException e) {
|
||||||
|
log.warn("Post not found for update: {}", e.getMessage());
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error updating post with id {}: ", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Failed to update post: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deletePost(@PathVariable Long id) {
|
||||||
|
try {
|
||||||
|
log.info("Deleting post with id: {}", id);
|
||||||
|
return postRepository.findById(id)
|
||||||
|
.map(post -> {
|
||||||
|
postRepository.delete(post);
|
||||||
|
log.info("Successfully deleted post with id: {}", id);
|
||||||
|
return ResponseEntity.noContent().<Void>build();
|
||||||
|
})
|
||||||
|
.orElseGet(() -> {
|
||||||
|
log.warn("Post not found for deletion with id: {}", id);
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error deleting post with id {}: ", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle preflight OPTIONS requests
|
||||||
|
@RequestMapping(method = RequestMethod.OPTIONS)
|
||||||
|
public ResponseEntity<?> handleOptions() {
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header("Access-Control-Allow-Origin", "*")
|
||||||
|
.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||||
|
.header("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.HttpResponse;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.ProfessorDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.service.ProfessorService;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("professor")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ProfessorResource {
|
||||||
|
|
||||||
|
private final ProfessorService professorService;
|
||||||
|
|
||||||
|
@GetMapping("home")
|
||||||
|
public String showProfessor() {
|
||||||
|
return "Application works";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("register")
|
||||||
|
public Professor register(@RequestBody Professor professor) {
|
||||||
|
return professorService.register(professor.getFirstName(), professor.getLastName(), professor.getEmail(), professor.getDepartment(), professor.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("add")
|
||||||
|
public ResponseEntity<Professor> addNewProfessor(@Valid ProfessorDto professorDto) {
|
||||||
|
log.debug("Professor DTO: {}", professorDto);
|
||||||
|
Professor professor = professorService.addNewProfessor(professorDto);
|
||||||
|
return ResponseEntity.ok(professor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PutMapping("{professorId}")
|
||||||
|
public Professor updateProfessor(@PathVariable UUID professorId, @Valid ProfessorDto professorDto) {
|
||||||
|
log.debug("Professor DTO: {}", professorDto);
|
||||||
|
return professorService.updateProfessor(professorId, professorDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{professorId}")
|
||||||
|
public Professor findProfessorById(@PathVariable UUID professorId) {
|
||||||
|
return professorService.findByProfessorId(professorId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("email/{email}")
|
||||||
|
public Professor findProfessorByEmail(@PathVariable String email) {
|
||||||
|
return professorService.findByEmail(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Page<Professor> getAllProfessors(Pageable pageable) {
|
||||||
|
return professorService.findAll(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("{professorId}")
|
||||||
|
public HttpResponse deleteProfessor(@PathVariable UUID professorId) {
|
||||||
|
professorService.deleteProfessor(professorId);
|
||||||
|
return HttpResponse.builder()
|
||||||
|
.httpStatusCode(OK.value())
|
||||||
|
.httpStatus(OK)
|
||||||
|
.reason(OK.getReasonPhrase())
|
||||||
|
.message("Professor deleted successfully")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("{professorId}/profile-image")
|
||||||
|
public Professor updateProfileImage(@PathVariable UUID professorId, @RequestParam MultipartFile profileImage) {
|
||||||
|
return professorService.updateProfileImage(professorId, profileImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "{professorId}/profile-image/{filename}", produces = MediaType.IMAGE_JPEG_VALUE)
|
||||||
|
public byte[] getProfileImageByProfessorId(@PathVariable UUID professorId, @PathVariable String filename) {
|
||||||
|
return professorService.getImageByProfessorId(professorId, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "{professorId}/profile-image", produces = MediaType.IMAGE_JPEG_VALUE)
|
||||||
|
public byte[] getDefaultProfileImage(@PathVariable UUID professorId) {
|
||||||
|
return professorService.getDefaultProfileImage(professorId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.service.ProfessorService;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("public/professor")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@CrossOrigin(origins = "*") // Configure this properly for production
|
||||||
|
public class PublicProfessorController {
|
||||||
|
|
||||||
|
private final ProfessorService professorService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<Page<Professor>> getAllProfessors(Pageable pageable) {
|
||||||
|
Page<Professor> professors = professorService.findAll(pageable);
|
||||||
|
return ResponseEntity.ok(professors);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{professorId}")
|
||||||
|
public ResponseEntity<Professor> getProfessorById(@PathVariable UUID professorId) {
|
||||||
|
Professor professor = professorService.findByProfessorId(professorId);
|
||||||
|
return ResponseEntity.ok(professor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("active")
|
||||||
|
public ResponseEntity<Page<Professor>> getActiveProfessors(Pageable pageable) {
|
||||||
|
Page<Professor> activeProfessors = professorService.findActiveProfessors(pageable);
|
||||||
|
return ResponseEntity.ok(activeProfessors);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the missing endpoint that your Next.js frontend is calling
|
||||||
|
@GetMapping("active/category/{category}")
|
||||||
|
public ResponseEntity<Page<Professor>> getActiveProfessorsByCategory(
|
||||||
|
@PathVariable String category,
|
||||||
|
Pageable pageable) {
|
||||||
|
try {
|
||||||
|
ProfessorCategory professorCategory = ProfessorCategory.valueOf(category.toUpperCase());
|
||||||
|
Page<Professor> professors = professorService.findActiveProfessorsByCategory(professorCategory, pageable);
|
||||||
|
return ResponseEntity.ok(professors);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.warn("Invalid category provided: {}", category);
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional endpoint for all professors by category (active and inactive)
|
||||||
|
@GetMapping("category/{category}")
|
||||||
|
public ResponseEntity<Page<Professor>> getProfessorsByCategory(
|
||||||
|
@PathVariable String category,
|
||||||
|
Pageable pageable) {
|
||||||
|
try {
|
||||||
|
ProfessorCategory professorCategory = ProfessorCategory.valueOf(category.toUpperCase());
|
||||||
|
Page<Professor> professors = professorService.findByCategory(professorCategory, pageable);
|
||||||
|
return ResponseEntity.ok(professors);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.warn("Invalid category provided: {}", category);
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,198 @@
|
|||||||
|
// package com.example.tamilnadureservoir.controller;
|
||||||
|
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.transform.dom.DOMResult;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ConferenceData;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.ConferenceDataRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/soap")
|
||||||
|
public class SoapController {
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
private final ConferenceDataRepository conferenceDataRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SoapController(RestTemplate restTemplate, ConferenceDataRepository conferenceDataRepository) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
this.conferenceDataRepository = conferenceDataRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/insertConferenceData")
|
||||||
|
public ResponseEntity<String> insertConferenceData(@RequestBody ConferenceData conferenceData) {
|
||||||
|
try {
|
||||||
|
// Save the conferenceData object to the database
|
||||||
|
ConferenceData savedConferenceData = conferenceDataRepository.save(conferenceData);
|
||||||
|
return new ResponseEntity<>("ConferenceData inserted with ID: " + savedConferenceData.getId(),
|
||||||
|
HttpStatus.CREATED);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new ResponseEntity<>("Failed to insert ConferenceData: " + e.getMessage(),
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getAllConferenceData")
|
||||||
|
public ResponseEntity<List<ConferenceData>> getAllConferenceData() {
|
||||||
|
List<ConferenceData> conferenceDataList = conferenceDataRepository.findAll();
|
||||||
|
return new ResponseEntity<>(conferenceDataList, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/updateConferenceData/{id}")
|
||||||
|
public ResponseEntity<ConferenceData> updateConferenceData(@PathVariable Long id,
|
||||||
|
@RequestBody ConferenceData updatedData) {
|
||||||
|
// Implement the logic to update conference data by ID
|
||||||
|
Optional<ConferenceData> existingData = conferenceDataRepository.findById(id);
|
||||||
|
|
||||||
|
if (existingData.isPresent()) {
|
||||||
|
ConferenceData dataToUpdate = existingData.get();
|
||||||
|
// Update the fields of dataToUpdate with values from updatedData
|
||||||
|
// e.g., dataToUpdate.setName(updatedData.getName());
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Save the updated data
|
||||||
|
conferenceDataRepository.save(dataToUpdate);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(dataToUpdate, HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/partialUpdateConferenceData/{id}")
|
||||||
|
public ResponseEntity<ConferenceData> partialUpdateConferenceData(@PathVariable Long id,
|
||||||
|
@RequestBody Map<String, Object> updates) {
|
||||||
|
// Implement the logic to partially update conference data by ID
|
||||||
|
Optional<ConferenceData> existingData = conferenceDataRepository.findById(id);
|
||||||
|
|
||||||
|
if (existingData.isPresent()) {
|
||||||
|
ConferenceData dataToUpdate = existingData.get();
|
||||||
|
|
||||||
|
// Apply updates from the request body to dataToUpdate
|
||||||
|
for (Map.Entry<String, Object> entry : updates.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
// Update specific fields based on the key-value pairs
|
||||||
|
// e.g., if (key.equals("name")) dataToUpdate.setName((String) value);
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the partially updated data
|
||||||
|
conferenceDataRepository.save(dataToUpdate);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(dataToUpdate, HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/deleteConferenceData/{id}")
|
||||||
|
public ResponseEntity<Void> deleteConferenceData(@PathVariable Long id) {
|
||||||
|
// Implement the logic to delete conference data by ID
|
||||||
|
conferenceDataRepository.deleteById(id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getConferenceDataByPhone/{phone}")
|
||||||
|
public ResponseEntity<Object> getConferenceDataByPhone(@PathVariable("phone") String phone) {
|
||||||
|
Optional<ConferenceData> conferenceDataOptional = conferenceDataRepository.findByPhone(phone);
|
||||||
|
|
||||||
|
if (conferenceDataOptional.isPresent()) {
|
||||||
|
ConferenceData conferenceData = conferenceDataOptional.get();
|
||||||
|
return new ResponseEntity<>(conferenceData, HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>("ConferenceData not found for phone: " + phone, HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/callWebService", consumes = "application/soap+xml", produces = MediaType.APPLICATION_XML_VALUE)
|
||||||
|
public String callWebService(
|
||||||
|
@RequestBody String soapRequest,
|
||||||
|
@RequestHeader("Content-Type") String contentType,
|
||||||
|
@RequestHeader("SOAPAction") String soapAction) {
|
||||||
|
|
||||||
|
// Log or use the 'Content-Type' and 'SOAPAction' headers as needed
|
||||||
|
System.out.println("Content-Type: " + contentType);
|
||||||
|
System.out.println("SOAPAction: " + soapAction);
|
||||||
|
|
||||||
|
// Specify the SOAP action for your ASMX web service
|
||||||
|
String soapActionValue = soapAction;
|
||||||
|
String url = "https://clin.cmcvellore.ac.in/newconference/ConferencePay.asmx";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create a DocumentBuilder to parse the SOAP request string
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document requestDoc = builder.parse(new InputSource(new StringReader(soapRequest)));
|
||||||
|
|
||||||
|
// Create a DOMSource from the parsed SOAP request
|
||||||
|
DOMSource requestSource = new DOMSource(requestDoc);
|
||||||
|
|
||||||
|
// Create a DOMResult to capture the response
|
||||||
|
DOMResult responseResult = new DOMResult();
|
||||||
|
|
||||||
|
// Set the Content-Type header to specify the SOAP format
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.TEXT_XML);
|
||||||
|
|
||||||
|
// Set the SOAPAction header to specify the SOAP action
|
||||||
|
headers.set("SOAPAction", soapActionValue);
|
||||||
|
|
||||||
|
// Create a HttpEntity with the headers
|
||||||
|
HttpEntity<DOMSource> httpEntity = new HttpEntity<>(requestSource, headers);
|
||||||
|
|
||||||
|
// Send the SOAP request to the external ASMX web service
|
||||||
|
ResponseEntity<String> responseEntity = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
httpEntity,
|
||||||
|
String.class);
|
||||||
|
|
||||||
|
// Extract the response XML from the ResponseEntity
|
||||||
|
String responseXml = responseEntity.getBody();
|
||||||
|
|
||||||
|
// Handle the SOAP response as needed
|
||||||
|
return responseXml;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Handle exceptions
|
||||||
|
e.printStackTrace(); // You can log the exception details
|
||||||
|
return null; // Return an appropriate response or handle differently
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
// UpcomingEventController.java - REST Controller for Upcoming Events
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.UpcomingEvent;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UpcomingEventDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.UpcomingEventRepository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/upcoming-events")
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class UpcomingEventController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UpcomingEventRepository upcomingEventRepository;
|
||||||
|
|
||||||
|
// Get all active upcoming events (for public display)
|
||||||
|
@GetMapping("/active")
|
||||||
|
public ResponseEntity<List<UpcomingEvent>> getActiveUpcomingEvents() {
|
||||||
|
try {
|
||||||
|
List<UpcomingEvent> events = upcomingEventRepository.findAllByIsActiveTrue();
|
||||||
|
return ResponseEntity.ok(events);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all upcoming events (for admin)
|
||||||
|
@GetMapping
|
||||||
|
public List<UpcomingEvent> getAllUpcomingEvents() {
|
||||||
|
return upcomingEventRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a single upcoming event by ID
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<UpcomingEvent> getUpcomingEventById(@PathVariable Long id) {
|
||||||
|
return upcomingEventRepository.findById(id)
|
||||||
|
.map(event -> ResponseEntity.ok(event))
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<?> createUpcomingEvent(@RequestBody UpcomingEventDto eventDto) {
|
||||||
|
UpcomingEvent event = new UpcomingEvent();
|
||||||
|
event.setTitle(eventDto.getTitle());
|
||||||
|
event.setDescription(eventDto.getDescription());
|
||||||
|
event.setSchedule(eventDto.getSchedule());
|
||||||
|
event.setEventDate(eventDto.getEventDate());
|
||||||
|
event.setActive(eventDto.isActive());
|
||||||
|
|
||||||
|
upcomingEventRepository.save(event);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<?> updateUpcomingEvent(@PathVariable Long id, @RequestBody UpcomingEventDto eventDto) {
|
||||||
|
UpcomingEvent event = upcomingEventRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Upcoming event not found"));
|
||||||
|
|
||||||
|
event.setTitle(eventDto.getTitle());
|
||||||
|
event.setDescription(eventDto.getDescription());
|
||||||
|
event.setSchedule(eventDto.getSchedule());
|
||||||
|
event.setEventDate(eventDto.getEventDate());
|
||||||
|
event.setActive(eventDto.isActive());
|
||||||
|
|
||||||
|
upcomingEventRepository.save(event);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteUpcomingEvent(@PathVariable Long id) {
|
||||||
|
return upcomingEventRepository.findById(id)
|
||||||
|
.map(event -> {
|
||||||
|
upcomingEventRepository.delete(event);
|
||||||
|
return ResponseEntity.noContent().<Void>build();
|
||||||
|
})
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.constant.SecurityConstants;
|
import net.shyshkin.study.fullstack.supportportal.backend.constant.SecurityConstants;
|
||||||
@ -32,6 +33,13 @@ import static org.springframework.http.HttpStatus.OK;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UserResource {
|
public class UserResource {
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class UserDTO{
|
||||||
|
String username;
|
||||||
|
String password;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final AuthenticationManager authenticationManager;
|
private final AuthenticationManager authenticationManager;
|
||||||
private final JwtTokenProvider jwtTokenProvider;
|
private final JwtTokenProvider jwtTokenProvider;
|
||||||
@ -47,7 +55,8 @@ public class UserResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public ResponseEntity<User> login(@RequestBody User user) {
|
public ResponseEntity<User> login(@RequestBody UserDTO user) {
|
||||||
|
// public ResponseEntity<User> login(@RequestBody User user) {
|
||||||
|
|
||||||
authenticate(user.getUsername(), user.getPassword());
|
authenticate(user.getUsername(), user.getPassword());
|
||||||
User byUsername = userService.findByUsername(user.getUsername());
|
User byUsername = userService.findByUsername(user.getUsername());
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
public abstract class BaseEntity {
|
||||||
|
|
||||||
|
@Column(nullable = false, updatable = false)
|
||||||
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean isDeleted = false;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
protected void onCreate() {
|
||||||
|
createdDate = LocalDateTime.now();
|
||||||
|
updatedDate = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
protected void onUpdate() {
|
||||||
|
updatedDate = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getCreatedDate() {
|
||||||
|
return createdDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getUpdatedDate() {
|
||||||
|
return updatedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
isDeleted = deleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class ConferenceData {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// Request fields
|
||||||
|
private String conferencecode;
|
||||||
|
private String conferenceyear;
|
||||||
|
private String bankname;
|
||||||
|
private String remoteip;
|
||||||
|
private String regno;
|
||||||
|
private String candidatename;
|
||||||
|
private String nameinreceipt;
|
||||||
|
private String address1;
|
||||||
|
private String address2;
|
||||||
|
private String city;
|
||||||
|
private String state;
|
||||||
|
private String country;
|
||||||
|
private String pincode;
|
||||||
|
private String phone;
|
||||||
|
private String mobile;
|
||||||
|
private String email;
|
||||||
|
private String foodtype;
|
||||||
|
private String participanttype;
|
||||||
|
private String practicetype;
|
||||||
|
private String accompanymembers;
|
||||||
|
private String paymentamount;
|
||||||
|
private String ToWards;
|
||||||
|
private String Allow80G;
|
||||||
|
private String PanCardNo;
|
||||||
|
private String hasgst;
|
||||||
|
private String GSTReg;
|
||||||
|
private String gstnumber;
|
||||||
|
private String gstmobileno;
|
||||||
|
private String gstemailid;
|
||||||
|
private String inputcaption1;
|
||||||
|
private String inputvalue1;
|
||||||
|
private String inputcaption2;
|
||||||
|
private String inputvalue2;
|
||||||
|
private String inputcaption3;
|
||||||
|
private String inputvalue3;
|
||||||
|
private String inputcaption4;
|
||||||
|
private String inputvalue4;
|
||||||
|
private String inputcaption5;
|
||||||
|
private String inputvalue5;
|
||||||
|
|
||||||
|
// Response fields
|
||||||
|
private String responseTransid;
|
||||||
|
private String responseResultCode;
|
||||||
|
private String responseResult;
|
||||||
|
private String responseURL;
|
||||||
|
|
||||||
|
// Constructors, getters, and setters
|
||||||
|
|
||||||
|
// You can generate getters and setters for each field using your IDE or
|
||||||
|
// manually.
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class Course extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT", nullable = false)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String duration;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Integer seats;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String level;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String instructor;
|
||||||
|
|
||||||
|
private String price;
|
||||||
|
|
||||||
|
@Column(name = "start_date")
|
||||||
|
private LocalDate startDate;
|
||||||
|
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "course_eligibility", joinColumns = @JoinColumn(name = "course_id"))
|
||||||
|
@Column(name = "eligibility")
|
||||||
|
private List<String> eligibility;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "course_objectives", joinColumns = @JoinColumn(name = "course_id"))
|
||||||
|
@Column(name = "objective", columnDefinition = "TEXT")
|
||||||
|
private List<String> objectives;
|
||||||
|
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private boolean isActive = true;
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
// CourseApplication.java - Entity for course applications
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class CourseApplication extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "course_id", nullable = false)
|
||||||
|
private Course course;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String fullName;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String qualification;
|
||||||
|
|
||||||
|
private String experience;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String coverLetter;
|
||||||
|
|
||||||
|
private String resumeUrl;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private ApplicationStatus status = ApplicationStatus.PENDING;
|
||||||
|
|
||||||
|
public enum ApplicationStatus {
|
||||||
|
PENDING, REVIEWED, SHORTLISTED, ACCEPTED, REJECTED, ENROLLED
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,143 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@Table(name = "events")
|
||||||
|
public class Event {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, unique = true)
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String year;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private String subTitle;
|
||||||
|
|
||||||
|
// New fields to match Next.js component
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String detail;
|
||||||
|
|
||||||
|
private String mainImage;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "event_gallery_images", joinColumns = @JoinColumn(name = "event_id"))
|
||||||
|
@Column(name = "image_url")
|
||||||
|
private List<String> galleryImages;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "venues", joinColumns = @JoinColumn(name = "event_id"))
|
||||||
|
private List<Venue> venue;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "highlights", joinColumns = @JoinColumn(name = "event_id"))
|
||||||
|
private List<String> highlights;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "organisers", joinColumns = @JoinColumn(name = "event_id"))
|
||||||
|
private List<String> organisers;
|
||||||
|
|
||||||
|
// Fixed Fee mapping with proper column name
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "event_fees", joinColumns = @JoinColumn(name = "event_id"))
|
||||||
|
private List<Fee> fee;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted", nullable = false)
|
||||||
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@JoinTable(
|
||||||
|
name = "event_professors",
|
||||||
|
joinColumns = @JoinColumn(name = "event_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "professor_id")
|
||||||
|
)
|
||||||
|
private List<Professor> professors;
|
||||||
|
|
||||||
|
// Embedded classes
|
||||||
|
@Embeddable
|
||||||
|
public static class Venue {
|
||||||
|
private String title;
|
||||||
|
private String date;
|
||||||
|
private String address;
|
||||||
|
private String info;
|
||||||
|
|
||||||
|
// Constructors, getters, setters
|
||||||
|
public Venue() {}
|
||||||
|
|
||||||
|
public Venue(String title, String date, String address, String info) {
|
||||||
|
this.title = title;
|
||||||
|
this.date = date;
|
||||||
|
this.address = address;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters and setters
|
||||||
|
public String getTitle() { return title; }
|
||||||
|
public void setTitle(String title) { this.title = title; }
|
||||||
|
|
||||||
|
public String getDate() { return date; }
|
||||||
|
public void setDate(String date) { this.date = date; }
|
||||||
|
|
||||||
|
public String getAddress() { return address; }
|
||||||
|
public void setAddress(String address) { this.address = address; }
|
||||||
|
|
||||||
|
public String getInfo() { return info; }
|
||||||
|
public void setInfo(String info) { this.info = info; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Embeddable
|
||||||
|
public static class Fee {
|
||||||
|
@Column(name = "fee_description") // Explicit column mapping to avoid reserved word issues
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "fee_cost")
|
||||||
|
private Integer cost;
|
||||||
|
|
||||||
|
// Constructors, getters, setters
|
||||||
|
public Fee() {}
|
||||||
|
|
||||||
|
public Fee(String description, Integer cost) {
|
||||||
|
this.description = description;
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters and setters
|
||||||
|
public String getDescription() { return description; }
|
||||||
|
public void setDescription(String description) { this.description = description; }
|
||||||
|
|
||||||
|
public Integer getCost() { return cost; }
|
||||||
|
public void setCost(Integer cost) { this.cost = cost; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
// Job.java - Entity for job positions
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class Job extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String department;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String type; // Full-time, Contract, Observership, etc.
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String experience;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String salary;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT", nullable = false)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "job_requirements", joinColumns = @JoinColumn(name = "job_id"))
|
||||||
|
@Column(name = "requirement")
|
||||||
|
private List<String> requirements;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "job_responsibilities", joinColumns = @JoinColumn(name = "job_id"))
|
||||||
|
@Column(name = "responsibility")
|
||||||
|
private List<String> responsibilities;
|
||||||
|
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private boolean isActive = true;
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
// JobApplication.java - Entity for job applications
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class JobApplication extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "job_id", nullable = false)
|
||||||
|
private Job job;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String fullName;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String experience;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String coverLetter;
|
||||||
|
|
||||||
|
private String resumeUrl; // Path to uploaded resume file
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private ApplicationStatus status = ApplicationStatus.PENDING;
|
||||||
|
|
||||||
|
public enum ApplicationStatus {
|
||||||
|
PENDING, REVIEWED, SHORTLISTED, INTERVIEWED, REJECTED, HIRED
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false) // Changed from true since you're extending BaseEntity
|
||||||
|
public class Post extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "LONGTEXT", nullable = false)
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@ManyToMany
|
||||||
|
@JoinTable(
|
||||||
|
name = "post_professors",
|
||||||
|
joinColumns = @JoinColumn(name = "post_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "professor_id")
|
||||||
|
)
|
||||||
|
private List<Professor> professors;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean isPosted;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name = "post_tags", joinColumns = @JoinColumn(name = "post_id"))
|
||||||
|
@Column(name = "tag")
|
||||||
|
private List<String> tags;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String imageUrl; // Add this field
|
||||||
|
}
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
|
@Builder
|
||||||
|
public class Professor implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4372214856545239049L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Type(type = "org.hibernate.type.UUIDCharType")
|
||||||
|
@Column(length = 36, columnDefinition = "varchar(36)", updatable = false, nullable = false)
|
||||||
|
private UUID professorId;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String email;
|
||||||
|
private String department;
|
||||||
|
private String position;
|
||||||
|
private String officeLocation;
|
||||||
|
private LocalDateTime joinDate;
|
||||||
|
private String profileImageUrl;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private WorkingStatus status;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private ProfessorCategory category;
|
||||||
|
|
||||||
|
// Additional fields for Next.js integration
|
||||||
|
private String phone;
|
||||||
|
private String specialty;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String certification;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String training;
|
||||||
|
|
||||||
|
private String experience;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String designation;
|
||||||
|
|
||||||
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
|
@CollectionTable(name = "professor_work_days", joinColumns = @JoinColumn(name = "professor_id"))
|
||||||
|
@Column(name = "work_day")
|
||||||
|
private List<String> workDays;
|
||||||
|
|
||||||
|
// Use Set instead of List to avoid MultipleBagFetchException
|
||||||
|
// Sets can be eagerly loaded together without issues
|
||||||
|
@OneToMany(mappedBy = "professor", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
private Set<ProfessorSkill> skills;
|
||||||
|
|
||||||
|
// Use Set instead of List to avoid MultipleBagFetchException
|
||||||
|
@OneToMany(mappedBy = "professor", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
private Set<ProfessorAward> awards;
|
||||||
|
|
||||||
|
@ManyToMany(mappedBy = "professors")
|
||||||
|
@JsonIgnore // Keep this as @JsonIgnore to avoid circular references
|
||||||
|
private List<Post> posts;
|
||||||
|
|
||||||
|
// Convenience method to get full name
|
||||||
|
public String getName() {
|
||||||
|
return firstName + " " + lastName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ProfessorAward {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String year;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "professor_id")
|
||||||
|
@JsonIgnore
|
||||||
|
@ToString.Exclude
|
||||||
|
@EqualsAndHashCode.Exclude
|
||||||
|
private Professor professor;
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
public enum ProfessorCategory {
|
||||||
|
FACULTY,
|
||||||
|
SUPPORT_TEAM,
|
||||||
|
TRAINEE_FELLOW
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ProfessorSkill {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private Integer level;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "professor_id")
|
||||||
|
@JsonIgnore
|
||||||
|
@ToString.Exclude
|
||||||
|
@EqualsAndHashCode.Exclude
|
||||||
|
private Professor professor;
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
// UpcomingEvent.java - Entity for upcoming events
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class UpcomingEvent extends BaseEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT", nullable = false)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String schedule; // e.g., "Q3 2025", "Monthly Sessions", "Ongoing"
|
||||||
|
|
||||||
|
@Column(name = "event_date")
|
||||||
|
private LocalDate eventDate;
|
||||||
|
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private boolean isActive = true;
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain;
|
||||||
|
|
||||||
|
public enum WorkingStatus {
|
||||||
|
ACTIVE,
|
||||||
|
ON_LEAVE,
|
||||||
|
RETIRED
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class AwardDto {
|
||||||
|
private String title;
|
||||||
|
private String year;
|
||||||
|
private String description;
|
||||||
|
private String imageUrl;
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
// CourseApplicationDto.java - DTO for Course Application
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Email;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class CourseApplicationDto {
|
||||||
|
@NotNull
|
||||||
|
private Long courseId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String fullName;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Email
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String qualification;
|
||||||
|
|
||||||
|
private String experience;
|
||||||
|
private String coverLetter;
|
||||||
|
private String resumeUrl;
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
// CourseDto.java - DTO for Course
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class CourseDto {
|
||||||
|
@NotNull
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String duration;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Integer seats;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String level;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String instructor;
|
||||||
|
|
||||||
|
private String price;
|
||||||
|
private LocalDate startDate;
|
||||||
|
private String imageUrl;
|
||||||
|
private List<String> eligibility;
|
||||||
|
private List<String> objectives;
|
||||||
|
private boolean active;
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
// JobApplicationDto.java - DTO for Job Application
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Email;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class JobApplicationDto {
|
||||||
|
@NotNull
|
||||||
|
private Long jobId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String fullName;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Email
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String experience;
|
||||||
|
|
||||||
|
private String coverLetter;
|
||||||
|
private String resumeUrl;
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
// JobDto.java - DTO for Job
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class JobDto {
|
||||||
|
@NotNull
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String department;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String experience;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String salary;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private List<String> requirements;
|
||||||
|
private List<String> responsibilities;
|
||||||
|
|
||||||
|
// Explicit boolean field handling (remove @Data for this field)
|
||||||
|
private boolean active; // Change from isActive to active
|
||||||
|
|
||||||
|
// Explicit getters and setters for the boolean field
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For Jackson JSON deserialization
|
||||||
|
public void setIsActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class PostDto {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@NotEmpty(message = "At least one professor must be selected.")
|
||||||
|
private List<Long> professors;
|
||||||
|
|
||||||
|
private List<String> tags;
|
||||||
|
private boolean posted;
|
||||||
|
private String imageUrl; // Add this field
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||||
|
// Add these imports at the top
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.SkillDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.AwardDto;
|
||||||
|
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Email;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ProfessorDto {
|
||||||
|
|
||||||
|
@NotEmpty(message = "Should not be empty")
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String email;
|
||||||
|
private String department;
|
||||||
|
private String position;
|
||||||
|
private String officeLocation;
|
||||||
|
private WorkingStatus status;
|
||||||
|
private ProfessorCategory category;
|
||||||
|
private LocalDateTime joinDate;
|
||||||
|
private MultipartFile profileImage;
|
||||||
|
|
||||||
|
// Additional fields for Next.js integration
|
||||||
|
private String phone;
|
||||||
|
private String specialty;
|
||||||
|
private String certification;
|
||||||
|
private String training;
|
||||||
|
private String experience;
|
||||||
|
private String description;
|
||||||
|
private String designation;
|
||||||
|
private List<String> workDays;
|
||||||
|
private List<SkillDto> skills;
|
||||||
|
private List<AwardDto> awards;
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ProfessorResponseDto {
|
||||||
|
private Long id;
|
||||||
|
private UUID professorId;
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String email;
|
||||||
|
private String department;
|
||||||
|
private String position;
|
||||||
|
private String officeLocation;
|
||||||
|
private LocalDateTime joinDate;
|
||||||
|
private String profileImageUrl;
|
||||||
|
private WorkingStatus status;
|
||||||
|
private ProfessorCategory category;
|
||||||
|
|
||||||
|
// Additional fields for Next.js integration
|
||||||
|
private String phone;
|
||||||
|
private String specialty;
|
||||||
|
private String certification;
|
||||||
|
private String training;
|
||||||
|
private String experience;
|
||||||
|
private String description;
|
||||||
|
private String designation;
|
||||||
|
private List<String> workDays;
|
||||||
|
|
||||||
|
// Nested DTOs for skills and awards
|
||||||
|
private List<SkillDto> skills;
|
||||||
|
private List<AwardDto> awards;
|
||||||
|
|
||||||
|
// Convenience method to get full name
|
||||||
|
public String getName() {
|
||||||
|
return firstName + " " + lastName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SkillDto {
|
||||||
|
private String name;
|
||||||
|
private Integer level;
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
// UpcomingEventDto.java - DTO for Upcoming Event
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class UpcomingEventDto {
|
||||||
|
@NotNull
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String schedule;
|
||||||
|
|
||||||
|
private LocalDate eventDate;
|
||||||
|
private boolean active;
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.exception.domain;
|
||||||
|
|
||||||
|
public class ProfessorNotFoundException extends RuntimeException {
|
||||||
|
public ProfessorNotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.mapper;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.ProfessorDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.Named;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface ProfessorMapper {
|
||||||
|
|
||||||
|
// @Mapping(target = "professorId", ignore = true) // Auto-generated
|
||||||
|
@Mapping(target = "joinDate", expression = "java(java.time.LocalDateTime.now())") // Default value
|
||||||
|
@Mapping(target = "status", source = "status", qualifiedByName = "stringToWorkingStatus")
|
||||||
|
Professor toEntity(ProfessorDto professorDto);
|
||||||
|
|
||||||
|
@Mapping(target = "profileImage", ignore = true) // Ignore profileImage mapping
|
||||||
|
@Mapping(target = "status", source = "status", qualifiedByName = "workingStatusToString")
|
||||||
|
ProfessorDto toDto(Professor professor);
|
||||||
|
|
||||||
|
@Named("stringToWorkingStatus")
|
||||||
|
default WorkingStatus stringToWorkingStatus(String status) {
|
||||||
|
return status == null ? null : WorkingStatus.valueOf(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Named("workingStatusToString")
|
||||||
|
default String workingStatusToString(WorkingStatus status) {
|
||||||
|
return status == null ? null : status.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -7,14 +7,13 @@ import org.mapstruct.Mapping;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Mapper(imports = {LocalDateTime.class})
|
|
||||||
public interface UserMapper {
|
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring", imports = {LocalDateTime.class})
|
||||||
|
public interface UserMapper {
|
||||||
@Mapping(target = "isNotLocked", source = "notLocked")
|
@Mapping(target = "isNotLocked", source = "notLocked")
|
||||||
@Mapping(target = "isActive", source = "active")
|
@Mapping(target = "isActive", source = "active")
|
||||||
@Mapping(target = "joinDate", expression = "java(LocalDateTime.now())")
|
@Mapping(target = "joinDate", expression = "java(LocalDateTime.now())")
|
||||||
@Mapping(target = "role", source = "role", resultType = String.class)
|
@Mapping(target = "role", source = "role", resultType = String.class)
|
||||||
@Mapping(target = "authorities", source = "role.authorities")
|
@Mapping(target = "authorities", source = "role.authorities")
|
||||||
User toEntity(UserDto userDto);
|
User toEntity(UserDto userDto);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.mapper;
|
||||||
|
|
||||||
|
// import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement(name = "YourSoapRequest")
|
||||||
|
public class YourSoapRequest {
|
||||||
|
private String conferencecode;
|
||||||
|
private String conferenceyear;
|
||||||
|
private String bankname;
|
||||||
|
private String remoteip;
|
||||||
|
private String regno;
|
||||||
|
private String candidatename;
|
||||||
|
private String nameinreceipt;
|
||||||
|
private String address1;
|
||||||
|
private String address2;
|
||||||
|
private String city;
|
||||||
|
private String state;
|
||||||
|
private String country;
|
||||||
|
private String pincode;
|
||||||
|
private String phone;
|
||||||
|
private String mobile;
|
||||||
|
private String email;
|
||||||
|
private String foodtype;
|
||||||
|
private String participanttype;
|
||||||
|
private String practicetype;
|
||||||
|
private String accompanymembers;
|
||||||
|
private String paymentamount;
|
||||||
|
private String ToWards;
|
||||||
|
private String Allow80G;
|
||||||
|
private String PanCardNo;
|
||||||
|
private String hasgst;
|
||||||
|
private String GSTReg;
|
||||||
|
private String gstnumber;
|
||||||
|
private String gstmobileno;
|
||||||
|
private String gstemailid;
|
||||||
|
private String inputcaption1;
|
||||||
|
private String inputvalue1;
|
||||||
|
private String inputcaption2;
|
||||||
|
private String inputvalue2;
|
||||||
|
private String inputcaption3;
|
||||||
|
private String inputvalue3;
|
||||||
|
private String inputcaption4;
|
||||||
|
private String inputvalue4;
|
||||||
|
private String inputcaption5;
|
||||||
|
private String inputvalue5;
|
||||||
|
|
||||||
|
// Add getters and setters for each property
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ConferenceData;
|
||||||
|
|
||||||
|
// import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
|
||||||
|
|
||||||
|
// @RepositoryRestResource(path = "conferences")
|
||||||
|
public interface ConferenceDataRepository extends JpaRepository<ConferenceData, Long> {
|
||||||
|
Optional<ConferenceData> findByPhone(String phone); // Change 'phone' to your actual field name
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
// CourseApplicationRepository.java
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.CourseApplication;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CourseApplicationRepository extends JpaRepository<CourseApplication, Long> {
|
||||||
|
List<CourseApplication> findAllByCourseId(Long courseId);
|
||||||
|
List<CourseApplication> findAllByStatus(CourseApplication.ApplicationStatus status);
|
||||||
|
List<CourseApplication> findAllByEmail(String email);
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
// CourseRepository.java
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Course;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||||
|
List<Course> findAllByIsActiveTrue();
|
||||||
|
List<Course> findAllByCategory(String category);
|
||||||
|
List<Course> findAllByLevel(String level);
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Event;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface EventRepository extends JpaRepository<Event, Long> {
|
||||||
|
|
||||||
|
// Find active events ordered by date ascending (for upcoming events)
|
||||||
|
List<Event> findByIsActiveTrueOrderByDateAsc();
|
||||||
|
|
||||||
|
// Find active events ordered by date descending (for past events)
|
||||||
|
List<Event> findByIsActiveTrueOrderByDateDesc();
|
||||||
|
|
||||||
|
// Find events by year
|
||||||
|
List<Event> findByYearAndIsActiveTrue(String year);
|
||||||
|
|
||||||
|
// Find events by subject
|
||||||
|
List<Event> findBySubjectContainingIgnoreCaseAndIsActiveTrue(String subject);
|
||||||
|
|
||||||
|
// Find events by title containing keyword
|
||||||
|
List<Event> findByTitleContainingIgnoreCaseAndIsActiveTrue(String title);
|
||||||
|
|
||||||
|
// Custom query to search events by multiple fields
|
||||||
|
@Query("SELECT e FROM Event e WHERE e.isActive = true AND " +
|
||||||
|
"(LOWER(e.title) LIKE LOWER(CONCAT('%', ?1, '%')) OR " +
|
||||||
|
"LOWER(e.description) LIKE LOWER(CONCAT('%', ?1, '%')) OR " +
|
||||||
|
"LOWER(e.subject) LIKE LOWER(CONCAT('%', ?1, '%')))")
|
||||||
|
List<Event> searchActiveEvents(String searchTerm);
|
||||||
|
|
||||||
|
// Find events by date range (you might need to adjust based on your date format)
|
||||||
|
@Query("SELECT e FROM Event e WHERE e.isActive = true AND e.date BETWEEN ?1 AND ?2 ORDER BY e.date ASC")
|
||||||
|
List<Event> findEventsByDateRange(String startDate, String endDate);
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
// JobApplicationRepository.java
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.JobApplication;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface JobApplicationRepository extends JpaRepository<JobApplication, Long> {
|
||||||
|
List<JobApplication> findAllByJobId(Long jobId);
|
||||||
|
List<JobApplication> findAllByStatus(JobApplication.ApplicationStatus status);
|
||||||
|
List<JobApplication> findAllByEmail(String email);
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
// JobRepository.java
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Job;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface JobRepository extends JpaRepository<Job, Long> {
|
||||||
|
List<Job> findAllByIsActiveTrue();
|
||||||
|
List<Job> findAllByDepartment(String department);
|
||||||
|
List<Job> findAllByType(String type);
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Post;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface PostRepository extends JpaRepository<Post, Long> {
|
||||||
|
|
||||||
|
// Additional query methods can be defined here if needed
|
||||||
|
|
||||||
|
// 1. Find all posts where isPosted is true
|
||||||
|
List<Post> findAllByIsPostedTrue();
|
||||||
|
|
||||||
|
// 3. Find all posts associated with a specific tag where isPosted is true
|
||||||
|
@Query("SELECT p FROM Post p JOIN p.tags t WHERE t = :tag AND p.isPosted = true")
|
||||||
|
List<Post> findAllByTagAndIsPostedTrue(@Param("tag") String tag);
|
||||||
|
|
||||||
|
// Custom query to count unique tags
|
||||||
|
@Query("SELECT t, COUNT(t) FROM Post p JOIN p.tags t GROUP BY t")
|
||||||
|
List<Object[]> findTagsWithCount();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||||
|
|
||||||
|
public interface ProfessorRepository extends JpaRepository<Professor, Long> {
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Professor p WHERE p.email = :email")
|
||||||
|
Optional<Professor> findByEmail(@Param("email") String email);
|
||||||
|
|
||||||
|
@Query("SELECT CASE WHEN COUNT(p) > 0 THEN TRUE ELSE FALSE END FROM Professor p WHERE p.email = :email")
|
||||||
|
Boolean existsByEmail(@Param("email") String email);
|
||||||
|
|
||||||
|
Boolean existsByProfessorId(UUID professorId);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Professor p WHERE p.professorId = :professorId")
|
||||||
|
Optional<Professor> findByProfessorId(@Param("professorId") UUID professorId);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Professor p WHERE p.status = :status")
|
||||||
|
Page<Professor> findByStatus(@Param("status") WorkingStatus status, Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Professor p WHERE p.category = :category")
|
||||||
|
Page<Professor> findByCategory(@Param("category") ProfessorCategory category, Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Professor p WHERE p.status = :status AND p.category = :category")
|
||||||
|
Page<Professor> findByStatusAndCategory(@Param("status") WorkingStatus status,
|
||||||
|
@Param("category") ProfessorCategory category,
|
||||||
|
Pageable pageable);
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
// UpcomingEventRepository.java
|
||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.repository;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.UpcomingEvent;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface UpcomingEventRepository extends JpaRepository<UpcomingEvent, Long> {
|
||||||
|
List<UpcomingEvent> findAllByIsActiveTrue();
|
||||||
|
}
|
||||||
@ -18,7 +18,6 @@ public class EmailService {
|
|||||||
private final Environment environment;
|
private final Environment environment;
|
||||||
|
|
||||||
public void sendNewPasswordEmail(String firstName, String password, String email) {
|
public void sendNewPasswordEmail(String firstName, String password, String email) {
|
||||||
|
|
||||||
// Create a Simple MailMessage.
|
// Create a Simple MailMessage.
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
message.setTo(email);
|
message.setTo(email);
|
||||||
@ -35,7 +34,20 @@ public class EmailService {
|
|||||||
message.setSubject(EMAIL_SUBJECT);
|
message.setSubject(EMAIL_SUBJECT);
|
||||||
message.setText("Hello " + firstName + "!\n\nYour new account password is: " + password + "\n\nThe Support Team");
|
message.setText("Hello " + firstName + "!\n\nYour new account password is: " + password + "\n\nThe Support Team");
|
||||||
|
|
||||||
|
// Log the email details before sending
|
||||||
|
log.info("Preparing to send email:");
|
||||||
|
log.info("From: {}", message.getFrom());
|
||||||
|
log.info("To: {}", String.join(", ", message.getTo()));
|
||||||
|
log.info("Cc: {}", String.join(", ", message.getCc()));
|
||||||
|
log.info("Subject: {}", message.getSubject());
|
||||||
|
log.info("Text: {}", message.getText());
|
||||||
|
|
||||||
|
try {
|
||||||
// Send Message!
|
// Send Message!
|
||||||
this.emailSender.send(message);
|
this.emailSender.send(message);
|
||||||
|
log.info("Email successfully sent to {}", email);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to send email to {}. Error: {}", email, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.service;
|
||||||
|
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.ProfessorDto;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface ProfessorService {
|
||||||
|
|
||||||
|
Professor register(String firstName, String lastName, String email, String department, String position);
|
||||||
|
|
||||||
|
Page<Professor> findAll(Pageable pageable);
|
||||||
|
|
||||||
|
Professor findByEmail(String email);
|
||||||
|
|
||||||
|
Professor findByProfessorId(UUID professorId);
|
||||||
|
|
||||||
|
Professor addNewProfessor(ProfessorDto professorDto);
|
||||||
|
|
||||||
|
Professor updateProfessor(UUID professorId, ProfessorDto professorDto);
|
||||||
|
|
||||||
|
void deleteProfessor(UUID professorId);
|
||||||
|
|
||||||
|
Professor updateProfileImage(UUID professorId, MultipartFile profileImage);
|
||||||
|
|
||||||
|
byte[] getImageByProfessorId(UUID professorId, String filename);
|
||||||
|
|
||||||
|
byte[] getDefaultProfileImage(UUID professorId);
|
||||||
|
|
||||||
|
// Existing method for active professors
|
||||||
|
Page<Professor> findActiveProfessors(Pageable pageable);
|
||||||
|
|
||||||
|
// New methods for category-based filtering
|
||||||
|
Page<Professor> findByCategory(ProfessorCategory category, Pageable pageable);
|
||||||
|
|
||||||
|
Page<Professor> findActiveProfessorsByCategory(ProfessorCategory category, Pageable pageable);
|
||||||
|
|
||||||
|
// Method to find professor with details
|
||||||
|
Professor findProfessorWithDetailsById(UUID professorId);
|
||||||
|
}
|
||||||
@ -0,0 +1,353 @@
|
|||||||
|
package net.shyshkin.study.fullstack.supportportal.backend.service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.Professor;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorAward;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorCategory;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.ProfessorSkill;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.ProfessorDto;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.WorkingStatus;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailExistsException;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.NotAnImageFileException;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.ProfessorNotFoundException;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.mapper.ProfessorMapper;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.ProfessorRepository;
|
||||||
|
|
||||||
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.RequestEntity;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||||
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static net.shyshkin.study.fullstack.supportportal.backend.constant.FileConstant.*;
|
||||||
|
import static org.springframework.http.MediaType.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ProfessorServiceImpl implements ProfessorService {
|
||||||
|
|
||||||
|
public static final String EMAIL_NOT_FOUND_MSG = "Professor with email `%s` not found";
|
||||||
|
public static final String EMAIL_EXISTS_MSG = "Professor with email `%s` is already registered";
|
||||||
|
public static final String PROFESSOR_NOT_FOUND_MSG = "Professor not found";
|
||||||
|
|
||||||
|
private final ProfessorRepository professorRepository;
|
||||||
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
private final EmailService emailService;
|
||||||
|
private final ProfessorMapper professorMapper;
|
||||||
|
private final ProfileImageService profileImageService;
|
||||||
|
private final RestTemplateBuilder restTemplateBuilder;
|
||||||
|
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
void init() {
|
||||||
|
restTemplate = restTemplateBuilder
|
||||||
|
.rootUri(TEMP_PROFILE_IMAGE_BASE_URL)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Professor register(String firstName, String lastName, String email, String department, String position) {
|
||||||
|
ProfessorDto professorDto = ProfessorDto.builder()
|
||||||
|
.firstName(firstName)
|
||||||
|
.lastName(lastName)
|
||||||
|
.email(email)
|
||||||
|
.department(department)
|
||||||
|
.position(position)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return addNewProfessor(professorDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateDefaultProfileImageUrl(UUID professorId) {
|
||||||
|
return ServletUriComponentsBuilder.fromCurrentContextPath()
|
||||||
|
.path(String.format(DEFAULT_USER_IMAGE_URI_PATTERN, professorId))
|
||||||
|
.toUriString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateProfileImageUrl(UUID professorId) {
|
||||||
|
return ServletUriComponentsBuilder.fromCurrentContextPath()
|
||||||
|
.path(String.format(DEFAULT_USER_IMAGE_URI_PATTERN, professorId))
|
||||||
|
.pathSegment(USER_IMAGE_FILENAME)
|
||||||
|
.toUriString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Professor> findAll(Pageable pageable) {
|
||||||
|
return professorRepository.findAll(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Professor findByEmail(String email) {
|
||||||
|
return professorRepository
|
||||||
|
.findByEmail(email)
|
||||||
|
.orElseThrow(() -> new EmailExistsException(String.format(EMAIL_NOT_FOUND_MSG, email)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Professor findByProfessorId(UUID professorId) {
|
||||||
|
return professorRepository
|
||||||
|
.findByProfessorId(professorId)
|
||||||
|
.orElseThrow(() -> new ProfessorNotFoundException(PROFESSOR_NOT_FOUND_MSG));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Professor> findActiveProfessors(Pageable pageable) {
|
||||||
|
return professorRepository.findByStatus(WorkingStatus.ACTIVE, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Professor> findByCategory(ProfessorCategory category, Pageable pageable) {
|
||||||
|
return professorRepository.findByCategory(category, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Professor> findActiveProfessorsByCategory(ProfessorCategory category, Pageable pageable) {
|
||||||
|
return professorRepository.findByStatusAndCategory(WorkingStatus.ACTIVE, category, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Professor findProfessorWithDetailsById(UUID professorId) {
|
||||||
|
return professorRepository.findByProfessorId(professorId)
|
||||||
|
.orElseThrow(() -> new ProfessorNotFoundException(PROFESSOR_NOT_FOUND_MSG));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveProfileImage(Professor professor, MultipartFile profileImage) {
|
||||||
|
if (profileImage == null) return;
|
||||||
|
|
||||||
|
if (!List.of(IMAGE_JPEG_VALUE, IMAGE_GIF_VALUE, IMAGE_PNG_VALUE).contains(profileImage.getContentType())) {
|
||||||
|
throw new NotAnImageFileException(profileImage.getOriginalFilename() + " is not an image file. Please upload an image");
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = profileImageService.persistProfileImage(professor.getProfessorId(), profileImage, USER_IMAGE_FILENAME);
|
||||||
|
|
||||||
|
if (imageUrl == null)
|
||||||
|
imageUrl = generateProfileImageUrl(professor.getProfessorId());
|
||||||
|
|
||||||
|
professor.setProfileImageUrl(imageUrl);
|
||||||
|
professorRepository.save(professor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearProfessorStorage(Professor professor) {
|
||||||
|
profileImageService.clearUserStorage(professor.getProfessorId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID generateUuid() {
|
||||||
|
return UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Professor addNewProfessor(ProfessorDto professorDto) {
|
||||||
|
validateNewEmail(professorDto.getEmail());
|
||||||
|
|
||||||
|
Professor professor = professorMapper.toEntity(professorDto);
|
||||||
|
|
||||||
|
// Set a unique identifier for the professor
|
||||||
|
professor.setProfessorId(generateUuid());
|
||||||
|
professor.setJoinDate(LocalDateTime.now());
|
||||||
|
professor.setProfileImageUrl(generateDefaultProfileImageUrl(professor.getProfessorId()));
|
||||||
|
|
||||||
|
// Save the professor first to get the ID
|
||||||
|
Professor savedProfessor = professorRepository.save(professor);
|
||||||
|
|
||||||
|
// Handle skills if provided
|
||||||
|
if (professorDto.getSkills() != null && !professorDto.getSkills().isEmpty()) {
|
||||||
|
Set<ProfessorSkill> skills = professorDto.getSkills().stream()
|
||||||
|
.filter(skillDto -> skillDto.getName() != null && !skillDto.getName().trim().isEmpty())
|
||||||
|
.map(skillDto -> ProfessorSkill.builder()
|
||||||
|
.name(skillDto.getName().trim())
|
||||||
|
.level(skillDto.getLevel())
|
||||||
|
.professor(savedProfessor)
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
savedProfessor.setSkills(skills);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle awards if provided
|
||||||
|
if (professorDto.getAwards() != null && !professorDto.getAwards().isEmpty()) {
|
||||||
|
Set<ProfessorAward> awards = professorDto.getAwards().stream()
|
||||||
|
.filter(awardDto -> awardDto.getTitle() != null && !awardDto.getTitle().trim().isEmpty())
|
||||||
|
.map(awardDto -> ProfessorAward.builder()
|
||||||
|
.title(awardDto.getTitle().trim())
|
||||||
|
.year(awardDto.getYear())
|
||||||
|
.description(awardDto.getDescription())
|
||||||
|
.imageUrl(awardDto.getImageUrl())
|
||||||
|
.professor(savedProfessor)
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
savedProfessor.setAwards(awards);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save again to persist the relationships
|
||||||
|
Professor finalProfessor = professorRepository.save(savedProfessor);
|
||||||
|
|
||||||
|
// Handle profile image if provided
|
||||||
|
if (professorDto.getProfileImage() != null) {
|
||||||
|
saveProfileImage(finalProfessor, professorDto.getProfileImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalProfessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Professor updateProfessor(UUID professorId, ProfessorDto professorDto) {
|
||||||
|
Professor professor = professorRepository.findByProfessorId(professorId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Professor not found with id: " + professorId));
|
||||||
|
|
||||||
|
validateUpdateEmail(professorId, professorDto.getEmail());
|
||||||
|
|
||||||
|
// Update basic fields
|
||||||
|
professor.setFirstName(professorDto.getFirstName());
|
||||||
|
professor.setLastName(professorDto.getLastName());
|
||||||
|
professor.setEmail(professorDto.getEmail());
|
||||||
|
professor.setDepartment(professorDto.getDepartment());
|
||||||
|
professor.setPosition(professorDto.getPosition());
|
||||||
|
professor.setOfficeLocation(professorDto.getOfficeLocation());
|
||||||
|
professor.setStatus(professorDto.getStatus());
|
||||||
|
professor.setCategory(professorDto.getCategory());
|
||||||
|
|
||||||
|
// Update extended fields
|
||||||
|
professor.setPhone(professorDto.getPhone());
|
||||||
|
professor.setSpecialty(professorDto.getSpecialty());
|
||||||
|
professor.setCertification(professorDto.getCertification());
|
||||||
|
professor.setTraining(professorDto.getTraining());
|
||||||
|
professor.setExperience(professorDto.getExperience());
|
||||||
|
professor.setDescription(professorDto.getDescription());
|
||||||
|
professor.setDesignation(professorDto.getDesignation());
|
||||||
|
professor.setWorkDays(professorDto.getWorkDays());
|
||||||
|
|
||||||
|
if (professorDto.getJoinDate() != null) {
|
||||||
|
professor.setJoinDate(professorDto.getJoinDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a final reference for lambda expressions
|
||||||
|
final Professor professorRef = professor;
|
||||||
|
|
||||||
|
// Update skills - clear existing and add new ones
|
||||||
|
if (professor.getSkills() != null) {
|
||||||
|
professor.getSkills().clear();
|
||||||
|
}
|
||||||
|
if (professorDto.getSkills() != null && !professorDto.getSkills().isEmpty()) {
|
||||||
|
Set<ProfessorSkill> skills = professorDto.getSkills().stream()
|
||||||
|
.filter(skillDto -> skillDto.getName() != null && !skillDto.getName().trim().isEmpty())
|
||||||
|
.map(skillDto -> ProfessorSkill.builder()
|
||||||
|
.name(skillDto.getName().trim())
|
||||||
|
.level(skillDto.getLevel())
|
||||||
|
.professor(professorRef)
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (professor.getSkills() == null) {
|
||||||
|
professor.setSkills(new HashSet<>());
|
||||||
|
}
|
||||||
|
professor.getSkills().addAll(skills);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update awards - clear existing and add new ones
|
||||||
|
if (professor.getAwards() != null) {
|
||||||
|
professor.getAwards().clear();
|
||||||
|
}
|
||||||
|
if (professorDto.getAwards() != null && !professorDto.getAwards().isEmpty()) {
|
||||||
|
Set<ProfessorAward> awards = professorDto.getAwards().stream()
|
||||||
|
.filter(awardDto -> awardDto.getTitle() != null && !awardDto.getTitle().trim().isEmpty())
|
||||||
|
.map(awardDto -> ProfessorAward.builder()
|
||||||
|
.title(awardDto.getTitle().trim())
|
||||||
|
.year(awardDto.getYear())
|
||||||
|
.description(awardDto.getDescription())
|
||||||
|
.imageUrl(awardDto.getImageUrl())
|
||||||
|
.professor(professorRef)
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (professor.getAwards() == null) {
|
||||||
|
professor.setAwards(new HashSet<>());
|
||||||
|
}
|
||||||
|
professor.getAwards().addAll(awards);
|
||||||
|
}
|
||||||
|
|
||||||
|
Professor savedProfessor = professorRepository.save(professor);
|
||||||
|
|
||||||
|
// Handle profile image if provided
|
||||||
|
if (professorDto.getProfileImage() != null) {
|
||||||
|
saveProfileImage(savedProfessor, professorDto.getProfileImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return savedProfessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteProfessor(UUID professorId) {
|
||||||
|
Professor professorToBeDeleted = professorRepository
|
||||||
|
.findByProfessorId(professorId)
|
||||||
|
.orElseThrow(() -> new ProfessorNotFoundException(PROFESSOR_NOT_FOUND_MSG));
|
||||||
|
|
||||||
|
clearProfessorStorage(professorToBeDeleted);
|
||||||
|
professorRepository.delete(professorToBeDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Professor updateProfileImage(UUID professorId, MultipartFile profileImage) {
|
||||||
|
Professor professor = findByProfessorId(professorId);
|
||||||
|
saveProfileImage(professor, profileImage);
|
||||||
|
return professor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getImageByProfessorId(UUID professorId, String filename) {
|
||||||
|
if (!professorRepository.existsByProfessorId(professorId)) {
|
||||||
|
throw new ProfessorNotFoundException(PROFESSOR_NOT_FOUND_MSG);
|
||||||
|
}
|
||||||
|
return profileImageService.retrieveProfileImage(professorId, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getDefaultProfileImage(UUID professorId) {
|
||||||
|
if (!professorRepository.existsByProfessorId(professorId)) {
|
||||||
|
throw new ProfessorNotFoundException(PROFESSOR_NOT_FOUND_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestEntity<Void> requestEntity = RequestEntity
|
||||||
|
.get("/{professorId}", professorId)
|
||||||
|
.accept(IMAGE_JPEG)
|
||||||
|
.build();
|
||||||
|
var responseEntity = restTemplate.exchange(requestEntity, new ParameterizedTypeReference<byte[]>() {});
|
||||||
|
return responseEntity.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateNewEmail(String email) {
|
||||||
|
if (professorRepository.existsByEmail(email)) {
|
||||||
|
throw new EmailExistsException(String.format(EMAIL_EXISTS_MSG, email));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Professor validateUpdateEmail(UUID professorId, String email) {
|
||||||
|
Objects.requireNonNull(professorId);
|
||||||
|
|
||||||
|
Professor currentProfessor = findByProfessorId(professorId);
|
||||||
|
|
||||||
|
if (!Objects.equals(currentProfessor.getEmail(), email) && professorRepository.existsByEmail(email)) {
|
||||||
|
throw new EmailExistsException(String.format(EMAIL_EXISTS_MSG, email));
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentProfessor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -35,3 +35,5 @@ public interface UserService extends UserDetailsService {
|
|||||||
|
|
||||||
byte[] getDefaultProfileImage(UUID userId);
|
byte[] getDefaultProfileImage(UUID userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import net.shyshkin.study.fullstack.supportportal.backend.domain.UserPrincipal;
|
|||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.*;
|
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.*;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.mapper.UserMapper;
|
import net.shyshkin.study.fullstack.supportportal.backend.mapper.UserMapper;
|
||||||
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.ProfessorRepository;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.repository.UserRepository;
|
import net.shyshkin.study.fullstack.supportportal.backend.repository.UserRepository;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
@ -45,6 +46,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
public static final String EMAIL_EXISTS_MSG = "User with email `%s` is already registered";
|
public static final String EMAIL_EXISTS_MSG = "User with email `%s` is already registered";
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final ProfessorRepository professorRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final LoginAttemptService loginAttemptService;
|
private final LoginAttemptService loginAttemptService;
|
||||||
private final EmailService emailService;
|
private final EmailService emailService;
|
||||||
@ -264,10 +266,14 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] getDefaultProfileImage(UUID userId) {
|
public byte[] getDefaultProfileImage(UUID userId) {
|
||||||
|
|
||||||
if (!userRepository.existsByUserId(userId)) {
|
if (!userRepository.existsByUserId(userId) && !professorRepository.existsByProfessorId(userId)) {
|
||||||
throw new UserNotFoundException(USER_NOT_FOUND_MSG);
|
throw new UserNotFoundException(USER_NOT_FOUND_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (!professorRepository.existsByProfessorId(userId)) {
|
||||||
|
// throw new UserNotFoundException(USER_NOT_FOUND_MSG);
|
||||||
|
// }
|
||||||
|
|
||||||
// "https://robohash.org/11951691-d373-4126-bef2-84d157a6546b"
|
// "https://robohash.org/11951691-d373-4126-bef2-84d157a6546b"
|
||||||
RequestEntity<Void> requestEntity = RequestEntity
|
RequestEntity<Void> requestEntity = RequestEntity
|
||||||
.get("/{userId}", userId)
|
.get("/{userId}", userId)
|
||||||
|
|||||||
@ -1,34 +1,37 @@
|
|||||||
server:
|
server:
|
||||||
error:
|
error:
|
||||||
path: /error
|
path: /error
|
||||||
# whitelabel:
|
|
||||||
# enabled: false
|
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
mail:
|
mail:
|
||||||
host: smtp.gmail.com
|
host: mail.techzoos.in
|
||||||
port: 587
|
port: 587
|
||||||
username: ${PORTAL_MAIL_USERNAME:fake.user@gmail.com}
|
username: ${PORTAL_MAIL_USERNAME:govardhan@techzoos.in}
|
||||||
password: ${PORTAL_MAIL_PASSWORD:fake_password}
|
password: ${PORTAL_MAIL_PASSWORD:123456}
|
||||||
properties:
|
properties:
|
||||||
mail:
|
mail:
|
||||||
transport:
|
transport:
|
||||||
protocol: smtp
|
protocol: smtp
|
||||||
smtp:
|
smtp:
|
||||||
auth: true
|
auth: false
|
||||||
starttls:
|
starttls:
|
||||||
enable: true
|
enable: true
|
||||||
|
ssl:
|
||||||
|
enable: false
|
||||||
|
|
||||||
datasource:
|
datasource:
|
||||||
|
url: jdbc:mysql://localhost:3306/support_portal?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
|
||||||
|
username: support_portal_user
|
||||||
|
password: Supp0rt_Porta!_P@ssword
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://mysql:3306/support-portal
|
|
||||||
username: ENC(criE3etnc/EVZbizNgNdmj+8F0BYC3bSVBK1VT/xJ7WMoNvSfdEGsqWfCpaX5lEWvXLOO8pzgjdB5zIOBcTikw==)
|
|
||||||
password: ENC(OTG4nZfio2dHHxV0Ey/Nmb4XeEfaD1YMsRVQxOwF59Q1JSBZPUKLWXORJXPz2RysKRngcdk2SgioAMw166DoqA==)
|
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: update
|
ddl-auto: update
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||||
|
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
max-file-size: 10MB
|
max-file-size: 10MB
|
||||||
@ -39,125 +42,41 @@ spring:
|
|||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
add-mappings: false
|
add-mappings: false
|
||||||
|
|
||||||
|
# File upload configuration
|
||||||
|
file:
|
||||||
|
upload:
|
||||||
|
directory: uploads
|
||||||
|
|
||||||
app:
|
app:
|
||||||
public-urls: /user/login,/user/register,/user/*/profile-image/**
|
base-url: ${APP_BASE_URL:http://localhost:8080}
|
||||||
|
# Updated public URLs to include image endpoints
|
||||||
|
public-urls: /user/login,/user/register,/user/*/profile-image,/user/*/profile-image/**,/professors,/professors/**,/api/posts,/api/posts/*,/api/posts/posted,/api/posts/tag/*,/api/posts/tags/count,/api/files/**,/professor,/professor/*,/api/events,/api/events/*,/api/public/**,/api/jobs/active,/api/job-applications,/api/courses/active,/api/courses/*,/api/course-applications,/api/upcoming-events/active
|
||||||
cors:
|
cors:
|
||||||
allowed-origins: http://localhost:4200,https://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://portal.shyshkin.net
|
allowed-origins: http://localhost:4200,https://localhost:4200,http://localhost:3000,https://localhost:3000,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://portal.shyshkin.net,*
|
||||||
jwt:
|
jwt:
|
||||||
secret: ENC(EfWSJqncgjSJ0g/tMzLoO9PlrjmpQf8Eb+q51SUXlh3AzwMHJyTF1gV0VpuNEQkNb9Lsw62xOBnxDNe73BsPDQ==)
|
secret: custom_text
|
||||||
# secret: ${random.value} #Does not work - every time generates new value
|
|
||||||
jasypt:
|
|
||||||
encryptor:
|
|
||||||
password: ${JASYPT_PASSWORD}
|
|
||||||
algorithm: PBEWITHHMACSHA512ANDAES_256
|
|
||||||
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
# Production file upload configuration
|
||||||
spring:
|
spring:
|
||||||
config:
|
config:
|
||||||
activate:
|
activate:
|
||||||
on-profile: local
|
on-profile: production
|
||||||
datasource:
|
file:
|
||||||
url: jdbc:mysql://localhost:23306/support-portal
|
upload:
|
||||||
jpa:
|
directory: /var/uploads/blog-images
|
||||||
show-sql: true
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
net.shyshkin: debug
|
|
||||||
|
|
||||||
---
|
|
||||||
spring:
|
|
||||||
config:
|
|
||||||
activate:
|
|
||||||
on-profile: aws-local
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://localhost:3306/support_portal
|
|
||||||
username: support_portal_user
|
|
||||||
password: Supp0rt_Porta!_P@ssword
|
|
||||||
mail:
|
|
||||||
host: email-smtp.eu-north-1.amazonaws.com
|
|
||||||
port: 587
|
|
||||||
username: AKIAVW7XGDOWFHHCELIH
|
|
||||||
password: BJyWOWS1xWYR35MRCFn3BuuQ6vY+k7DRsdAvOfqDs/Fk
|
|
||||||
|
|
||||||
# we want to test (1) from localhost, (2) from S3 bucket Static Web Site, (3) from our EC2 instance
|
|
||||||
app:
|
app:
|
||||||
email:
|
base-url: https://yourproductiondomain.com
|
||||||
from: d.art.shishkin@gmail.com
|
|
||||||
carbon-copy: d.art.shishkin@gmail.com
|
|
||||||
cors:
|
cors:
|
||||||
allowed-origins: http://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://support-portal.shyshkin.net,http://portal.shyshkin.net
|
allowed-origins: https://yourfrontenddomain.com,https://youradmindomain.com
|
||||||
server:
|
|
||||||
port: 5000
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
net.shyshkin: debug
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
# Development file upload configuration with custom directory
|
||||||
spring:
|
spring:
|
||||||
config:
|
config:
|
||||||
activate:
|
activate:
|
||||||
on-profile: aws-rds
|
on-profile: dev-custom-upload
|
||||||
datasource:
|
file:
|
||||||
url: jdbc:mysql://portal-db.coaum9neetxc.eu-north-1.rds.amazonaws.com:3306/support_portal
|
upload:
|
||||||
username: ENC(MPap/iQmyyLSeulVzLLq4nQ5dcwMyJ1cbW+bW7MOU4pN7CHQULbaDn8/5VszOP9F)
|
directory: ${user.home}/blog-uploads
|
||||||
password: ENC(nC0PV+0wPW+73o2uOh4Zg7EA34vdwZKpkPD4CIKvjDDXQ+dGXjykTuHUl3jlxkRC/00IpFurk/UJ9hTpZ6QqGA==)
|
|
||||||
mail:
|
|
||||||
host: email-smtp.eu-north-1.amazonaws.com
|
|
||||||
port: 587
|
|
||||||
username: ENC(CgaSXOMqTmswes1PgAYp3ICcoIVVXyKUlDR1Se963Vja02cBIor/2884e2OEFKW4XhBClTbuZCVdHK0vRRNqYg==)
|
|
||||||
password: ENC(GA8XsfU8vmat/7A8qEhrVz0Y47THxNT8jQ29wSg035fozwW7m+fKhJMQd4tgxL9dPfOzSXYzkffL0fG1AihWiHl99H9iBeXndDSvOhskvh4=)
|
|
||||||
|
|
||||||
# we want to test (1) from localhost, (2) from S3 bucket Static Web Site, (3) from our EC2 instance
|
|
||||||
app:
|
|
||||||
email:
|
|
||||||
from: d.art.shishkin@gmail.com
|
|
||||||
carbon-copy: d.art.shishkin@gmail.com
|
|
||||||
cors:
|
|
||||||
allowed-origins: http://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://support-portal.shyshkin.net,http://portal.shyshkin.net
|
|
||||||
server:
|
|
||||||
port: 5000
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
net.shyshkin: debug
|
|
||||||
|
|
||||||
#####
|
|
||||||
#
|
|
||||||
# HTTPS configuration
|
|
||||||
#
|
|
||||||
#####
|
|
||||||
|
|
||||||
server.ssl:
|
|
||||||
enabled: true # Enable HTTPS support (only accept HTTPS requests)
|
|
||||||
key-alias: securedPortal # Alias that identifies the key in the key store
|
|
||||||
key-store: classpath:securedPortal-keystore.p12 # Keystore location
|
|
||||||
key-store-password: ENC(nqDHyVFmySdbaCOZfj4EiQLRYyLSPLRLq/OzncqlsFIuWvh8caiOapAb+zrKR1+A) # Keystore password
|
|
||||||
key-store-type: PKCS12 # Keystore format
|
|
||||||
|
|
||||||
---
|
|
||||||
spring:
|
|
||||||
config:
|
|
||||||
activate:
|
|
||||||
on-profile: image-s3
|
|
||||||
app:
|
|
||||||
amazon-s3:
|
|
||||||
bucket-name: portal-user-profile-images
|
|
||||||
|
|
||||||
---
|
|
||||||
spring:
|
|
||||||
config:
|
|
||||||
activate:
|
|
||||||
on-profile: image-s3-localstack
|
|
||||||
app:
|
|
||||||
amazon-s3:
|
|
||||||
bucket-name: portal-user-profile-images
|
|
||||||
config:
|
|
||||||
aws:
|
|
||||||
region: eu-north-1
|
|
||||||
s3:
|
|
||||||
url: http://127.0.0.1:4566
|
|
||||||
bucket-name: portal-user-profile-images
|
|
||||||
access-key: localstack
|
|
||||||
secret-key: localstack
|
|
||||||
|
|
||||||
|
|
||||||
@ -114,6 +114,9 @@ class UserResourceTest extends BaseUserTest {
|
|||||||
//when
|
//when
|
||||||
ResponseEntity<User> responseEntity = restTemplate.postForEntity("/user/register", fakeUser, User.class);
|
ResponseEntity<User> responseEntity = restTemplate.postForEntity("/user/register", fakeUser, User.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//then
|
//then
|
||||||
log.debug("Response Entity: {}", responseEntity);
|
log.debug("Response Entity: {}", responseEntity);
|
||||||
assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
|
assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
|
||||||
@ -132,6 +135,7 @@ class UserResourceTest extends BaseUserTest {
|
|||||||
user = registeredUser;
|
user = registeredUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(40)
|
@Order(40)
|
||||||
void registerUser_usernameExists() {
|
void registerUser_usernameExists() {
|
||||||
|
|||||||
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 1.7 MiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 3.9 MiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 391 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 1.7 MiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 3.8 MiB |
|
After Width: | Height: | Size: 391 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 238 KiB |
|
After Width: | Height: | Size: 3.9 MiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 198 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 3.9 MiB |
|
After Width: | Height: | Size: 238 KiB |
|
After Width: | Height: | Size: 238 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 198 KiB |
|
After Width: | Height: | Size: 391 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 3.9 MiB |
|
After Width: | Height: | Size: 391 KiB |
|
After Width: | Height: | Size: 198 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 3.8 MiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 198 KiB |
|
After Width: | Height: | Size: 391 KiB |