├── .idea ├── .gitignore ├── vcs.xml ├── encodings.xml ├── misc.xml └── workspace.xml ├── src └── main │ ├── java │ └── edu │ │ └── icet │ │ ├── repository │ │ ├── CourseRepository.java │ │ ├── ProgramRepository.java │ │ ├── FacultyRepository.java │ │ ├── LecturerRepository.java │ │ └── RegisterRepository.java │ │ ├── dto │ │ ├── Email.java │ │ ├── MessageRequest.java │ │ ├── MessageResponse.java │ │ ├── PayDetails.java │ │ ├── Course.java │ │ ├── Program.java │ │ ├── Faculty.java │ │ ├── Lecturer.java │ │ └── Register.java │ │ ├── Main.java │ │ ├── config │ │ ├── Config.java │ │ └── PaypalConfig.java │ │ ├── service │ │ ├── CourseService.java │ │ ├── ProgramService.java │ │ ├── FacultyService.java │ │ ├── RegisterService.java │ │ ├── LecturerService.java │ │ ├── EmailSenderService.java │ │ ├── PaypalService.java │ │ └── impl │ │ │ ├── CourseServiceImpl.java │ │ │ ├── FacultyServiceImpl.java │ │ │ ├── LecturerServiceImpl.java │ │ │ ├── RegisterServiceImpl.java │ │ │ └── ProgramServiceImpl.java │ │ ├── entity │ │ ├── FacultyEntity.java │ │ ├── ProgramEntity.java │ │ ├── LecturerEntity.java │ │ ├── CourseEntity.java │ │ └── RegisterEntity.java │ │ └── controller │ │ ├── EmailSenderController.java │ │ ├── PaypalController.java │ │ ├── ChatController.java │ │ ├── CoursesController.java │ │ ├── ProgramController.java │ │ ├── FacultyController.java │ │ ├── RegisterController.java │ │ └── LecturerController.java │ └── resources │ └── application.yml ├── .gitignore ├── LICENSE.md ├── pom.xml └── README.md /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/repository/CourseRepository.java: -------------------------------------------------------------------------------- 1 | package edu.icet.repository; 2 | 3 | import edu.icet.entity.CourseEntity; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface CourseRepository extends JpaRepository { 7 | 8 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/repository/ProgramRepository.java: -------------------------------------------------------------------------------- 1 | package edu.icet.repository; 2 | 3 | import edu.icet.entity.ProgramEntity; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface ProgramRepository extends JpaRepository { 7 | } -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/Email.java: -------------------------------------------------------------------------------- 1 | 2 | package edu.icet.dto; 3 | 4 | import lombok.*; 5 | 6 | @Setter 7 | @Getter 8 | @Data 9 | @ToString 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Email { 13 | private String email; 14 | private String password; 15 | 16 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/Main.java: -------------------------------------------------------------------------------- 1 | package edu.icet; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Main { 8 | public static void main(String[] args) { 9 | SpringApplication.run(Main.class); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/MessageRequest.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | @ToString 11 | @Data 12 | public class MessageRequest { 13 | private String message; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/MessageResponse.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | @Data 9 | @NoArgsConstructor 10 | @ToString 11 | @AllArgsConstructor 12 | public class MessageResponse { 13 | private String responseMessage; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/repository/FacultyRepository.java: -------------------------------------------------------------------------------- 1 | package edu.icet.repository; 2 | 3 | import edu.icet.entity.FacultyEntity; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface FacultyRepository extends JpaRepository { 9 | 10 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/config/Config.java: -------------------------------------------------------------------------------- 1 | package edu.icet.config; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class Config{ 9 | @Bean 10 | public ModelMapper getMapper(){ 11 | return new ModelMapper(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/repository/LecturerRepository.java: -------------------------------------------------------------------------------- 1 | package edu.icet.repository; 2 | 3 | import edu.icet.entity.LecturerEntity; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface LecturerRepository extends JpaRepository { 9 | List findByFaculty(String faculty); 10 | List findByLecturerNameContainingIgnoreCase(String lecturerName); 11 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/PayDetails.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @ToString 13 | 14 | public class PayDetails { 15 | private double price; 16 | private String currency; 17 | private String method; 18 | private String intent; 19 | private String description; 20 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/CourseService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import edu.icet.dto.Course; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.util.List; 7 | 8 | public interface CourseService { 9 | List getAll(); 10 | void addCourse(Course course, MultipartFile imageFile); 11 | Course searchCourseById(Long id); 12 | void deleteCourseById(Long id); 13 | void updateCourseById(Course course, MultipartFile imageFile); 14 | 15 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/repository/RegisterRepository.java: -------------------------------------------------------------------------------- 1 | package edu.icet.repository; 2 | 3 | 4 | import edu.icet.entity.RegisterEntity; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | 8 | import java.util.List; 9 | 10 | public interface RegisterRepository extends JpaRepository { 11 | RegisterEntity findByEmail(String email); 12 | List findByOrderByCreatedDateDesc(Pageable pageable); 13 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/ProgramService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import edu.icet.dto.Program; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.util.List; 7 | 8 | public interface ProgramService { 9 | List getAllProgram(); 10 | void addProgram(Program program, MultipartFile imageFile); 11 | void updateProgramById(Program program, MultipartFile imageFile); 12 | void deleteProgramById(Long id); 13 | Program searchProgramById(Long id); 14 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/FacultyService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import edu.icet.dto.Faculty; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.io.IOException; 7 | import java.util.List; 8 | 9 | public interface FacultyService { 10 | List getAll(); 11 | void addFaculty(Faculty faculty, MultipartFile imageFile) throws IOException; 12 | Faculty searchFacultyById(Long id); 13 | void deleteFacultyById(Long id); 14 | void updateFacultyById(Faculty faculty, MultipartFile imageFile) throws IOException; 15 | 16 | } -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/Course.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @ToString 12 | public class Course { 13 | private Long courseId; 14 | private String courseName; 15 | private String subjects; 16 | private Double courseFee; 17 | private String fulDetails; 18 | private String description; 19 | private String courseImageName; 20 | private String courseImageType; 21 | private byte[] courseImageData; 22 | 23 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/Program.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDateTime; 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | public class Program { 12 | private Long programId; 13 | private String programName; 14 | private String programMission; 15 | private String programDetails; 16 | private String programVenue; 17 | private LocalDateTime programDateTime; 18 | private String programImageName; 19 | private String programImageType; 20 | private byte[] programImageData; 21 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/Faculty.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import edu.icet.entity.FacultyEntity; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.ToString; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @ToString 13 | public class Faculty { 14 | private Long facultyId; 15 | private String name; 16 | private String description; 17 | private String specializations; 18 | private String icon; 19 | private FacultyEntity faculty; 20 | private String facImageName; 21 | private String faImageType; 22 | private byte[] facImageData; 23 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/Lecturer.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import edu.icet.entity.FacultyEntity; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | public class Lecturer { 12 | private Long lecturer_id; 13 | private String lecturerName; 14 | private String lecturerExperience; 15 | private String lecturerDegrees; 16 | private FacultyEntity facultyEntity; 17 | private String learnSubjects; 18 | private String faculty; 19 | private String lecturerImageName; 20 | private String lecturerImageType; 21 | private byte[] lecturerImageData; 22 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/RegisterService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import edu.icet.dto.Register; 4 | import edu.icet.entity.RegisterEntity; 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import java.io.IOException; 8 | import java.util.List; 9 | 10 | public interface RegisterService { 11 | 12 | List getAll(); 13 | void addUser(Register user, MultipartFile imageFile) throws IOException; 14 | Register searchUserById(Long id); 15 | void deleteUserById(Long id); 16 | RegisterEntity findByEmail(String email); 17 | void updateUserById(Register user, MultipartFile imageFile) throws IOException; 18 | List getLastUsers(int count); 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/LecturerService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import edu.icet.dto.Lecturer; 4 | import edu.icet.entity.LecturerEntity; 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import java.io.IOException; 8 | import java.util.List; 9 | 10 | public interface LecturerService { 11 | List getAllLecturer(); 12 | void addLecturer(Lecturer lecturer, MultipartFile imageFile) throws IOException; 13 | Lecturer searchLecturerById(Long id); 14 | void deleteLecturerById(Long id); 15 | void updateLecturerById(Lecturer lecturer, MultipartFile imageFile) throws IOException; 16 | List searchLecturerByFaculty(String faculty); 17 | List searchLecturerByName(String lecturerName); 18 | 19 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/entity/FacultyEntity.java: -------------------------------------------------------------------------------- 1 | package edu.icet.entity; 2 | 3 | 4 | import jakarta.persistence.*; 5 | import jakarta.transaction.Transactional; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @Data 11 | @Transactional 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @Entity 15 | @Table(name = "faculty") 16 | public class FacultyEntity { 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | @Column(name = "faculty_id") 21 | private Long facultyId; 22 | 23 | private String name; 24 | private String description; 25 | private String specializations; 26 | private String icon; 27 | private String facImageName; 28 | private String facImageType; 29 | 30 | @Lob 31 | @Column(name = "fac_image_data", columnDefinition = "BLOB") 32 | private byte[] facImageData; 33 | 34 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/entity/ProgramEntity.java: -------------------------------------------------------------------------------- 1 | package edu.icet.entity; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Entity 14 | @Table(name = "programs") 15 | public class ProgramEntity { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long programId; 20 | 21 | private String programName; 22 | private String programMission; 23 | private String programDetails; 24 | private String programVenue; 25 | private LocalDateTime programDateTime; 26 | 27 | private String programImageName; 28 | private String programImageType; 29 | 30 | @Lob 31 | @Column(name = "imageData", columnDefinition = "BLOB") 32 | private byte[] programImageData; 33 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/entity/LecturerEntity.java: -------------------------------------------------------------------------------- 1 | package edu.icet.entity; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Entity 12 | @Table(name = "lecturer") 13 | public class LecturerEntity { 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) 16 | @Column(name = "lecturer_id") 17 | private Long lecturer_id; 18 | 19 | private String lecturerName; 20 | private String lecturerExperience; 21 | private String lecturerDegrees; 22 | private String learnSubjects; 23 | private String faculty; 24 | 25 | private String lecturerImageName; 26 | private String lecturerImageType; 27 | 28 | @Lob 29 | @Column(name = "lecturer_image_data", columnDefinition = "BLOB") 30 | private byte[] lecturerImageData; 31 | 32 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/EmailSenderService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.mail.SimpleMailMessage; 5 | import org.springframework.mail.javamail.JavaMailSender; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class EmailSenderService { 10 | @Autowired 11 | private JavaMailSender mailSender; 12 | 13 | public void sendEmail(String toEmail, 14 | String subject, 15 | String body) { 16 | SimpleMailMessage message = new SimpleMailMessage(); 17 | message.setFrom("chathupachamika765@gmail.com"); 18 | message.setTo(toEmail); 19 | message.setText(body); 20 | message.setSubject(subject); 21 | mailSender.send(message); 22 | System.out.println("Mail sent successfully."); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/entity/CourseEntity.java: -------------------------------------------------------------------------------- 1 | package edu.icet.entity; 2 | 3 | import jakarta.persistence.*; 4 | import jakarta.transaction.Transactional; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @Data 10 | @Transactional 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Entity 14 | @Table(name = "course") 15 | public class CourseEntity { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | @Column(name = "course_id") 20 | private Long courseId; 21 | 22 | private String courseName; 23 | private String subjects; 24 | private Double courseFee; 25 | private String description; 26 | private String fulDetails; 27 | private String courseImageName; 28 | private String courseImageType; 29 | 30 | @Lob 31 | @Column(name = "course_image_data", columnDefinition = "BLOB") 32 | private byte[] courseImageData; 33 | 34 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/dto/Register.java: -------------------------------------------------------------------------------- 1 | package edu.icet.dto; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.ToString; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @ToString 15 | public class Register { 16 | 17 | private Long reg_id; 18 | private String program; 19 | private String title; 20 | private String referral; 21 | private String shortName; 22 | private String fullName; 23 | private Date dob; 24 | private String country; 25 | private String passport; 26 | private String mobile; 27 | private String email; 28 | private String address; 29 | private String username; 30 | private Faculty faculty; 31 | private String password; 32 | private String imageName; 33 | private String imageType; 34 | private byte[] imageData; 35 | 36 | 37 | } -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9090 3 | 4 | paypal: 5 | mode: sandbox 6 | client: 7 | id: AXF3IX8bmXTk3ogAOySIZrRb0S9tTRJGQmcwC9_0m-KucXXWzjF4uD412FAWK1lWoXWdO4LxBgDvtU9U 8 | secret: ECB-vp_BI3nCivfdO3RU2eIgcKKpW_-ONEQmlwLGHbdFYQ3VaMHXfFVgc3bMGLw5XiOHBh-wMX08mChZ 9 | 10 | spring: 11 | datasource: 12 | url: jdbc:mysql://localhost:3306/campus 13 | username: root 14 | password: 1234 15 | 16 | jpa: 17 | hibernate: 18 | ddl-auto: update 19 | 20 | mail: 21 | host: smtp.gmail.com 22 | port: 587 23 | username: chathupachamika765@gmail.com 24 | password: hzwwtarfzjoxedqc 25 | properties: 26 | mail: 27 | smtp: 28 | auth: true 29 | starttls: 30 | enable: true 31 | 32 | ai: 33 | api: 34 | url: https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent 35 | key: AIzaSyBn7-BNPtxDzD-OXB_sqRzOve-z9NNBc7Y 36 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [YEAR] [YOUR NAME] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/entity/RegisterEntity.java: -------------------------------------------------------------------------------- 1 | package edu.icet.entity; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.*; 5 | 6 | import java.time.LocalDateTime; 7 | import java.util.Date; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @ToString 13 | @Entity 14 | @Table(name = "registered_guys") 15 | public class RegisterEntity { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long reg_id; 20 | private String program; 21 | private String title; 22 | private String referral; 23 | private String shortName; 24 | private String fullName; 25 | private Date dob; 26 | private String country; 27 | private String passport; 28 | private String mobile; 29 | private String email; 30 | private String address; 31 | private String username; 32 | private String password; 33 | 34 | @Column(name = "created_date") 35 | private LocalDateTime createdDate; 36 | 37 | private String imageName; 38 | private String imageType; 39 | 40 | @Lob 41 | @Column(name = "imageData", columnDefinition = "BLOB") 42 | private byte[] imageData; 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/EmailSenderController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import edu.icet.dto.Email; 4 | import edu.icet.entity.RegisterEntity; 5 | import edu.icet.service.EmailSenderService; 6 | import edu.icet.service.RegisterService; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | @CrossOrigin 11 | @RestController 12 | @RequestMapping("/forgot-password") 13 | @RequiredArgsConstructor 14 | public class EmailSenderController { 15 | 16 | private final EmailSenderService service; 17 | private final RegisterService registerService; 18 | 19 | @PostMapping("/post") 20 | public String sendForgotPasswordEmail(@RequestBody Email request) { 21 | RegisterEntity user = registerService.findByEmail(request.getEmail()); 22 | if (user != null) { 23 | String subject = "Password Reset Request - Your Password: " + user.getPassword(); 24 | String body = "Click the link to reset your password."; 25 | service.sendEmail(request.getEmail(), subject, body); 26 | return "Password reset email sent successfully."; 27 | } 28 | return "Email not found."; 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/config/PaypalConfig.java: -------------------------------------------------------------------------------- 1 | 2 | package edu.icet.config; 3 | 4 | import com.paypal.base.rest.APIContext; 5 | import com.paypal.base.rest.OAuthTokenCredential; 6 | import com.paypal.base.rest.PayPalRESTException; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | @Configuration 15 | public class PaypalConfig { 16 | @Value("${paypal.client.id}") 17 | private String clientId; 18 | @Value("${paypal.client.secret}") 19 | private String clientSecret; 20 | @Value("${paypal.mode}") 21 | private String mode; 22 | 23 | @Bean 24 | public Map paypalSDKConfig(){ 25 | Map configMap=new HashMap<>(); 26 | configMap.put("mode",mode); 27 | return configMap; 28 | } 29 | 30 | @Bean 31 | public OAuthTokenCredential oAuthTokenCredential(){ 32 | return new OAuthTokenCredential(clientId, clientSecret, paypalSDKConfig()); 33 | } 34 | 35 | @Bean 36 | public APIContext apiContext() throws PayPalRESTException{ 37 | APIContext context = new APIContext(oAuthTokenCredential().getAccessToken()); 38 | context.setConfigurationMap(paypalSDKConfig()); 39 | return context; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/PaypalService.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service; 2 | 3 | import com.paypal.api.payments.*; 4 | import com.paypal.base.rest.APIContext; 5 | import com.paypal.base.rest.PayPalRESTException; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.math.BigDecimal; 10 | import java.math.RoundingMode; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | @Service 15 | public class PaypalService { 16 | 17 | @Autowired 18 | private APIContext apiContext; 19 | 20 | public Payment createPayment( 21 | Double total, 22 | String currency, 23 | String method, 24 | String intent, 25 | String description, 26 | String cancelUrl, 27 | String successUrl) throws PayPalRESTException { 28 | Amount amount = new Amount(); 29 | amount.setCurrency(currency); 30 | total = new BigDecimal(total).setScale(2, RoundingMode.HALF_UP).doubleValue(); 31 | amount.setTotal(String.format("%.2f", total)); 32 | 33 | Transaction transaction = new Transaction(); 34 | transaction.setDescription(description); 35 | transaction.setAmount(amount); 36 | 37 | List transactions = new ArrayList<>(); 38 | transactions.add(transaction); 39 | 40 | Payer payer = new Payer(); 41 | payer.setPaymentMethod(method.toString()); 42 | 43 | Payment payment = new Payment(); 44 | payment.setIntent(intent.toString()); 45 | payment.setPayer(payer); 46 | payment.setTransactions(transactions); 47 | RedirectUrls redirectUrls = new RedirectUrls(); 48 | redirectUrls.setCancelUrl(cancelUrl); 49 | redirectUrls.setReturnUrl(successUrl); 50 | payment.setRedirectUrls(redirectUrls); 51 | return payment.create(apiContext); 52 | } 53 | 54 | public Payment executePayment(String paymentId, String payerId) throws PayPalRESTException{ 55 | Payment payment = new Payment(); 56 | payment.setId(paymentId); 57 | PaymentExecution paymentExecute = new PaymentExecution(); 58 | paymentExecute.setPayerId(payerId); 59 | return payment.execute(apiContext, paymentExecute); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/impl/CourseServiceImpl.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service.impl; 2 | 3 | import edu.icet.dto.Course; 4 | import edu.icet.entity.CourseEntity; 5 | import edu.icet.repository.CourseRepository; 6 | import edu.icet.service.CourseService; 7 | import lombok.RequiredArgsConstructor; 8 | import org.modelmapper.ModelMapper; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | @Service 17 | @RequiredArgsConstructor 18 | public class CourseServiceImpl implements CourseService { 19 | 20 | private final CourseRepository repository; 21 | private final ModelMapper mapper; 22 | 23 | @Override 24 | public List getAll() { 25 | return repository.findAll().stream() 26 | .map(courseEntity -> mapper.map(courseEntity, Course.class)) 27 | .collect(Collectors.toList()); 28 | } 29 | 30 | @Override 31 | public void addCourse(Course course, MultipartFile imageFile) { 32 | try { 33 | CourseEntity courseEntity = mapper.map(course, CourseEntity.class); 34 | courseEntity.setCourseImageData(imageFile.getBytes()); 35 | repository.save(courseEntity); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Override 42 | public Course searchCourseById(Long id) { 43 | return repository.findById(id) 44 | .map(courseEntity -> mapper.map(courseEntity, Course.class)) 45 | .orElse(null); 46 | } 47 | 48 | @Override 49 | public void deleteCourseById(Long id) { 50 | repository.deleteById(id); 51 | } 52 | 53 | @Override 54 | public void updateCourseById(Course course, MultipartFile imageFile) { 55 | try { 56 | CourseEntity existingCourse = repository.findById(course.getCourseId()).orElse(null); 57 | if (existingCourse != null) { 58 | mapper.map(course, existingCourse); 59 | if (imageFile != null && !imageFile.isEmpty()) { 60 | existingCourse.setCourseImageData(imageFile.getBytes()); 61 | } 62 | repository.save(existingCourse); 63 | } 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | new 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 3.3.5 15 | 16 | 17 | 23 18 | 23 19 | UTF-8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-mail 26 | 27 | 28 | 29 | com.fasterxml.jackson.core 30 | jackson-databind 31 | 2.15.2 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-thymeleaf 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-devtools 41 | runtime 42 | true 43 | 44 | 45 | com.paypal.sdk 46 | rest-api-sdk 47 | 1.4.2 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-web 52 | 53 | 54 | org.projectlombok 55 | lombok 56 | 1.18.34 57 | provided 58 | 59 | 60 | org.modelmapper 61 | modelmapper 62 | 3.2.1 63 | 64 | 65 | com.mysql 66 | mysql-connector-j 67 | 9.1.0 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-starter-data-jpa 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/PaypalController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import com.paypal.api.payments.Links; 4 | import com.paypal.api.payments.Payment; 5 | import com.paypal.base.rest.PayPalRESTException; 6 | import edu.icet.dto.PayDetails; 7 | import edu.icet.service.PaypalService; 8 | import lombok.RequiredArgsConstructor; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.Map; 14 | 15 | @RestController 16 | @RequestMapping("/payment") 17 | @RequiredArgsConstructor 18 | @CrossOrigin() 19 | public class PaypalController { 20 | 21 | @Autowired 22 | private PaypalService service; 23 | 24 | private static final String SUCCESS_URL = "pay/success"; 25 | private static final String CANCEL_URL = "pay/cancel"; 26 | 27 | @PostMapping("/pay") 28 | public ResponseEntity payment(@RequestBody PayDetails payDetails) { 29 | try { 30 | Payment payment = service.createPayment( 31 | payDetails.getPrice(), 32 | payDetails.getCurrency(), 33 | payDetails.getMethod(), 34 | payDetails.getIntent(), 35 | payDetails.getDescription(), 36 | "http://localhost:8080/" + CANCEL_URL, 37 | "http://localhost:8080/" + SUCCESS_URL 38 | ); 39 | for (Links link : payment.getLinks()) { 40 | if ("approval_url".equals(link.getRel())) { 41 | return ResponseEntity.ok().body(Map.of("redirectUrl", link.getHref())); 42 | } 43 | } 44 | } catch (PayPalRESTException e) { 45 | return ResponseEntity.status(500).body(Map.of("error", "Payment initiation failed", "details", e.getMessage())); 46 | } 47 | return ResponseEntity.status(500).body(Map.of("error", "Unknown error occurred")); 48 | } 49 | 50 | @GetMapping(value = CANCEL_URL) 51 | public ResponseEntity cancelPay() { 52 | return ResponseEntity.ok().body(Map.of("status", "cancelled", "message", "Payment was cancelled by the user.")); 53 | } 54 | 55 | @GetMapping(value = SUCCESS_URL) 56 | public ResponseEntity successPay(@RequestParam("paymentId") String paymentId, @RequestParam("PayerID") String payerId) { 57 | try { 58 | Payment payment = service.executePayment(paymentId, payerId); 59 | if ("approved".equals(payment.getState())) { 60 | return ResponseEntity.ok().body(Map.of("status", "approved", "paymentDetails", payment.toJSON())); 61 | } 62 | } catch (PayPalRESTException e) { 63 | return ResponseEntity.status(500).body(Map.of("error", "Payment execution failed", "details", e.getMessage())); 64 | } 65 | return ResponseEntity.status(400).body(Map.of("error", "Payment was not approved")); 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/ChatController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import edu.icet.dto.MessageRequest; 6 | import edu.icet.dto.MessageResponse; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | @CrossOrigin 13 | @RestController 14 | @RequestMapping("/api/chat") 15 | public class ChatController { 16 | 17 | @Value("${ai.api.url}") 18 | private String aiApiUrl; 19 | 20 | @Value("${ai.api.key}") 21 | private String apiKey; 22 | 23 | @PostMapping("/sendMessage") 24 | public ResponseEntity sendMessage(@RequestBody MessageRequest request) { 25 | try { 26 | RestTemplate restTemplate = new RestTemplate(); 27 | String fullUrl = aiApiUrl + "?key=" + apiKey; 28 | 29 | var aiRequest = """ 30 | { 31 | "contents": [ 32 | { "parts": [{ "text": "%s" }] } 33 | ] 34 | } 35 | """.formatted(request.getMessage()); 36 | 37 | var headers = new org.springframework.http.HttpHeaders(); 38 | headers.set("Content-Type", "application/json"); 39 | 40 | var entity = new org.springframework.http.HttpEntity<>(aiRequest, headers); 41 | var aiResponse = restTemplate.postForEntity(fullUrl, entity, String.class); 42 | 43 | String aiText = "Sorry, something went wrong."; 44 | if (aiResponse.getStatusCode().is2xxSuccessful()) { 45 | var body = aiResponse.getBody(); 46 | assert body != null; 47 | aiText = parseAiResponse(body); 48 | } 49 | return ResponseEntity.ok(new MessageResponse(aiText)); 50 | 51 | } catch (Exception ex) { 52 | ex.printStackTrace(); 53 | return ResponseEntity.status(500).body(new MessageResponse("An error occurred while processing your request.")); 54 | } 55 | } 56 | 57 | private String parseAiResponse(String responseBody) { 58 | try { 59 | ObjectMapper mapper = new ObjectMapper(); 60 | JsonNode root = mapper.readTree(responseBody); 61 | JsonNode candidates = root.path("candidates"); 62 | if (candidates.isArray() && candidates.size() > 0) { 63 | JsonNode content = candidates.get(0).path("content"); 64 | JsonNode parts = content.path("parts"); 65 | if (parts.isArray() && parts.size() > 0) { 66 | return parts.get(0).path("text").asText(); 67 | } 68 | } 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | return "Sorry, I encountered an error parsing the response."; 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/impl/FacultyServiceImpl.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service.impl; 2 | 3 | import edu.icet.dto.Faculty; 4 | import edu.icet.entity.FacultyEntity; 5 | import edu.icet.repository.FacultyRepository; 6 | import edu.icet.service.FacultyService; 7 | import jakarta.persistence.EntityNotFoundException; 8 | import lombok.RequiredArgsConstructor; 9 | import org.modelmapper.ModelMapper; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.IOException; 15 | import java.util.List; 16 | import java.util.Optional; 17 | import java.util.stream.Collectors; 18 | 19 | @Service 20 | @RequiredArgsConstructor 21 | public class FacultyServiceImpl implements FacultyService { 22 | @Autowired 23 | private final FacultyRepository repository; 24 | private final ModelMapper mapper; 25 | 26 | @Override 27 | public List getAll() { 28 | return repository.findAll().stream() 29 | .map(entity -> mapper.map(entity, Faculty.class)) 30 | .collect(Collectors.toList()); 31 | } 32 | 33 | @Override 34 | public void addFaculty(Faculty faculty, MultipartFile imageFile) throws IOException { 35 | if (imageFile != null && !imageFile.isEmpty()) { 36 | faculty.setFacImageName(imageFile.getOriginalFilename()); 37 | faculty.setFaImageType(imageFile.getContentType()); 38 | faculty.setFacImageData(imageFile.getBytes()); 39 | } 40 | FacultyEntity entity = mapper.map(faculty, FacultyEntity.class); 41 | repository.save(entity); 42 | } 43 | 44 | @Override 45 | public Faculty searchFacultyById(Long id) { 46 | return repository.findById(id) 47 | .map(entity -> mapper.map(entity, Faculty.class)) 48 | .orElse(null); 49 | } 50 | 51 | @Override 52 | public void deleteFacultyById(Long id) { 53 | if (repository.existsById(id)) { 54 | repository.deleteById(id); 55 | } 56 | } 57 | 58 | @Override 59 | public void updateFacultyById(Faculty faculty, MultipartFile imageFile) throws IOException { 60 | Optional existingEntityOpt = repository.findById(faculty.getFacultyId()); 61 | 62 | if (existingEntityOpt.isPresent()) { 63 | FacultyEntity existingEntity = existingEntityOpt.get(); 64 | 65 | existingEntity.setName(faculty.getName()); 66 | existingEntity.setDescription(faculty.getDescription()); 67 | existingEntity.setSpecializations(faculty.getSpecializations()); 68 | existingEntity.setIcon(faculty.getIcon()); 69 | 70 | if (imageFile != null && !imageFile.isEmpty()) { 71 | existingEntity.setFacImageName(imageFile.getOriginalFilename()); 72 | existingEntity.setFacImageType(imageFile.getContentType()); 73 | existingEntity.setFacImageData(imageFile.getBytes()); 74 | } 75 | repository.save(existingEntity); 76 | } else { 77 | throw new EntityNotFoundException("Faculty with ID " + faculty.getFacultyId() + " not found"); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/CoursesController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import edu.icet.dto.Course; 4 | import edu.icet.service.CourseService; 5 | import jakarta.persistence.EntityNotFoundException; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.*; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | @CrossOrigin 17 | @RestController 18 | @RequestMapping("/course") 19 | @RequiredArgsConstructor 20 | public class CoursesController { 21 | @Autowired 22 | private final CourseService service; 23 | 24 | @GetMapping("/get-all") 25 | public ResponseEntity> getCourse() { 26 | return ResponseEntity.ok(service.getAll()); 27 | } 28 | 29 | @PostMapping("/add-user") 30 | @ResponseStatus(HttpStatus.CREATED) 31 | public ResponseEntity> addCourse(@RequestPart("user") Course course, 32 | @RequestPart("imageFile") MultipartFile imageFile) { 33 | Map response = new HashMap<>(); 34 | service.addCourse(course, imageFile); 35 | response.put("message", "Course created successfully"); 36 | return ResponseEntity.status(HttpStatus.CREATED).body(response); 37 | } 38 | 39 | @GetMapping("/searchCourse-by-id/{id}") 40 | public ResponseEntity getCourseById(@PathVariable Long id) { 41 | try { 42 | Course course = service.searchCourseById(id); 43 | return ResponseEntity.ok(course); 44 | } catch (EntityNotFoundException e) { 45 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Course not found with ID: " + id); 46 | } 47 | } 48 | 49 | @DeleteMapping("/deleteCourse-by-id/{id}") 50 | public ResponseEntity> deleteCourseById(@PathVariable Long id) { 51 | Map response = new HashMap<>(); 52 | try { 53 | service.deleteCourseById(id); 54 | response.put("message", "Course deleted successfully"); 55 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); 56 | } catch (EntityNotFoundException e) { 57 | response.put("error", "Course not found with ID: " + id); 58 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 59 | } 60 | } 61 | 62 | @PutMapping("/update-course") 63 | @ResponseStatus(HttpStatus.ACCEPTED) 64 | public ResponseEntity> updateLecturer( 65 | @RequestPart("course") Course course, 66 | @RequestPart(value = "imageFile", required = false) MultipartFile imageFile) { 67 | Map response = new HashMap<>(); 68 | try { 69 | service.updateCourseById(course, imageFile); 70 | response.put("message", "Course updated successfully"); 71 | return ResponseEntity.ok(response); 72 | } catch (EntityNotFoundException e) { 73 | response.put("error", "Course not found with ID: " + course.getCourseId()); 74 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/impl/LecturerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service.impl; 2 | 3 | import edu.icet.dto.Lecturer; 4 | import edu.icet.entity.LecturerEntity; 5 | import edu.icet.repository.FacultyRepository; 6 | import edu.icet.repository.LecturerRepository; 7 | import edu.icet.service.LecturerService; 8 | import jakarta.persistence.EntityNotFoundException; 9 | import lombok.RequiredArgsConstructor; 10 | import org.modelmapper.ModelMapper; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.IOException; 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | @Service 19 | @RequiredArgsConstructor 20 | public class LecturerServiceImpl implements LecturerService { 21 | private final LecturerRepository lecturerRepository; 22 | private final FacultyRepository facultyRepository; 23 | private final ModelMapper mapper; 24 | 25 | @Override 26 | public List getAllLecturer() { 27 | return lecturerRepository.findAll().stream() 28 | .map(entity -> mapper.map(entity, Lecturer.class)) 29 | .collect(Collectors.toList()); 30 | } 31 | 32 | @Override 33 | public void addLecturer(Lecturer lecturer, MultipartFile imageFile) throws IOException { 34 | LecturerEntity entity = mapper.map(lecturer, LecturerEntity.class); 35 | 36 | if (imageFile != null && !imageFile.isEmpty()) { 37 | entity.setLecturerImageName(imageFile.getOriginalFilename()); 38 | entity.setLecturerImageType(imageFile.getContentType()); 39 | entity.setLecturerImageData(imageFile.getBytes()); 40 | } 41 | 42 | lecturerRepository.save(entity); 43 | } 44 | 45 | @Override 46 | public Lecturer searchLecturerById(Long id) { 47 | return lecturerRepository.findById(id) 48 | .map(entity -> mapper.map(entity, Lecturer.class)) 49 | .orElseThrow(() -> new EntityNotFoundException("Lecturer with ID " + id + " not found")); 50 | } 51 | 52 | @Override 53 | public void deleteLecturerById(Long id) { 54 | if (lecturerRepository.existsById(id)) { 55 | lecturerRepository.deleteById(id); 56 | } else { 57 | throw new EntityNotFoundException("Lecturer with ID " + id + " not found"); 58 | } 59 | } 60 | 61 | @Override 62 | public void updateLecturerById(Lecturer lecturer, MultipartFile imageFile) throws IOException { 63 | LecturerEntity existingEntity = lecturerRepository.findById(lecturer.getLecturer_id()) 64 | .orElseThrow(() -> new EntityNotFoundException("Lecturer with ID " + lecturer.getLecturer_id() + " not found")); 65 | 66 | existingEntity.setLecturerName(lecturer.getLecturerName()); 67 | existingEntity.setLecturerExperience(lecturer.getLecturerExperience()); 68 | existingEntity.setLecturerDegrees(lecturer.getLecturerDegrees()); 69 | 70 | if (imageFile != null && !imageFile.isEmpty()) { 71 | existingEntity.setLecturerImageName(imageFile.getOriginalFilename()); 72 | existingEntity.setLecturerImageType(imageFile.getContentType()); 73 | existingEntity.setLecturerImageData(imageFile.getBytes()); 74 | } 75 | 76 | lecturerRepository.save(existingEntity); 77 | } 78 | 79 | @Override 80 | public List searchLecturerByFaculty(String faculty) { 81 | return lecturerRepository.findByFaculty(faculty); 82 | } 83 | 84 | @Override 85 | public List searchLecturerByName(String lecturerName) { 86 | return lecturerRepository.findByLecturerNameContainingIgnoreCase(lecturerName); 87 | } 88 | 89 | 90 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/ProgramController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import edu.icet.dto.Program; 4 | import edu.icet.service.ProgramService; 5 | import jakarta.persistence.EntityNotFoundException; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.*; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | @CrossOrigin 18 | @RestController 19 | @RequestMapping("/program") 20 | @RequiredArgsConstructor 21 | public class ProgramController { 22 | 23 | @Autowired 24 | private final ProgramService service; 25 | 26 | @GetMapping("/get-allPrograms") 27 | public ResponseEntity> getPrograms() { 28 | return ResponseEntity.ok(service.getAllProgram()); 29 | } 30 | 31 | @PostMapping("/add-Program") 32 | @ResponseStatus(HttpStatus.CREATED) 33 | public ResponseEntity> addProgram( 34 | @RequestPart("Program") Program program, 35 | @RequestPart("imageFile") MultipartFile imageFile) { 36 | 37 | Map response = new HashMap<>(); 38 | try { 39 | service.addProgram(program, imageFile); 40 | response.put("message", "Program created successfully"); 41 | return ResponseEntity.status(HttpStatus.CREATED).body(response); 42 | } catch (Exception e) { 43 | response.put("error", "Program creation failed: " + e.getMessage()); 44 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 45 | } 46 | } 47 | 48 | @GetMapping("/searchProgram-by-id/{id}") 49 | public ResponseEntity getProgramById(@PathVariable Long id) { 50 | try { 51 | Program program = service.searchProgramById(id); // Updated return type to Program 52 | return ResponseEntity.ok(program); 53 | } catch (EntityNotFoundException e) { 54 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Program not found with ID: " + id); 55 | } 56 | } 57 | 58 | @DeleteMapping("/deleteProgram-by-id/{id}") 59 | public ResponseEntity> deleteProgramById(@PathVariable Long id) { 60 | Map response = new HashMap<>(); 61 | try { 62 | service.deleteProgramById(id); 63 | response.put("message", "Program deleted successfully"); 64 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); 65 | } catch (EntityNotFoundException e) { 66 | response.put("error", "Program not found with ID: " + id); 67 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 68 | } 69 | } 70 | 71 | @PutMapping("/update-Program") 72 | @ResponseStatus(HttpStatus.ACCEPTED) 73 | public ResponseEntity> updateProgram( 74 | @RequestPart("Program") Program program, 75 | @RequestPart(value = "imageFile", required = false) MultipartFile imageFile) { 76 | 77 | Map response = new HashMap<>(); 78 | try { 79 | service.updateProgramById(program, imageFile); 80 | response.put("message", "Program updated successfully"); 81 | return ResponseEntity.ok(response); 82 | } catch (EntityNotFoundException e) { 83 | response.put("error", "Program not found with ID: " + program.getProgramId()); 84 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/FacultyController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import edu.icet.dto.Faculty; 4 | import edu.icet.service.FacultyService; 5 | import jakarta.persistence.EntityNotFoundException; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.*; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import java.io.IOException; 14 | import java.util.HashMap; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | @CrossOrigin 19 | @RestController 20 | @RequestMapping("/faculty") 21 | @RequiredArgsConstructor 22 | public class FacultyController { 23 | @Autowired 24 | private final FacultyService service; 25 | 26 | @GetMapping("/get-allFaculty") 27 | public ResponseEntity> getFaculties() { 28 | return ResponseEntity.ok(service.getAll()); 29 | } 30 | 31 | @PostMapping("/add-faculty") 32 | @ResponseStatus(HttpStatus.CREATED) 33 | public ResponseEntity> addFaculty(@RequestPart("faculty") Faculty faculty, 34 | @RequestPart("imageFile") MultipartFile imageFile) { 35 | Map response = new HashMap<>(); 36 | try { 37 | service.addFaculty(faculty, imageFile); 38 | response.put("message", "Faculty created successfully"); 39 | return ResponseEntity.status(HttpStatus.CREATED).body(response); 40 | } catch (IOException e) { 41 | response.put("error", "Error creating faculty: " + e.getMessage()); 42 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 43 | } 44 | } 45 | 46 | @GetMapping("/searchFaculty-by-id/{id}") 47 | public ResponseEntity getFacultyById(@PathVariable Long id) { 48 | try { 49 | Faculty faculty = service.searchFacultyById(id); 50 | return ResponseEntity.ok(faculty); 51 | } catch (EntityNotFoundException e) { 52 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Faculty not found with ID: " + id); 53 | } 54 | } 55 | 56 | @DeleteMapping("/deleteFaculty-by-id/{id}") 57 | public ResponseEntity> deleteFacultyById(@PathVariable Long id) { 58 | Map response = new HashMap<>(); 59 | try { 60 | service.deleteFacultyById(id); 61 | response.put("message", "Faculty deleted successfully"); 62 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); 63 | } catch (EntityNotFoundException e) { 64 | response.put("error", "Faculty not found with ID: " + id); 65 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 66 | } 67 | } 68 | 69 | @PutMapping("/update-faculty") 70 | @ResponseStatus(HttpStatus.ACCEPTED) 71 | public ResponseEntity> updateFaculty( 72 | @RequestPart("faculty") Faculty faculty, 73 | @RequestPart(value = "imageFile", required = false) MultipartFile imageFile) { 74 | Map response = new HashMap<>(); 75 | try { 76 | service.updateFacultyById(faculty, imageFile); 77 | response.put("message", "Faculty updated successfully"); 78 | return ResponseEntity.ok(response); 79 | } catch (IOException e) { 80 | response.put("error", "Error updating faculty: " + e.getMessage()); 81 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 82 | } catch (EntityNotFoundException e) { 83 | response.put("error", "Faculty not found with ID: " + faculty.getFacultyId()); 84 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/RegisterController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import edu.icet.dto.Register; 4 | import edu.icet.entity.RegisterEntity; 5 | import edu.icet.service.RegisterService; 6 | import jakarta.persistence.EntityNotFoundException; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.IOException; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | @CrossOrigin 20 | @RestController 21 | @RequestMapping("/register") 22 | @RequiredArgsConstructor 23 | public class RegisterController { 24 | @Autowired 25 | private final RegisterService service; 26 | 27 | @GetMapping("/get-all") 28 | public ResponseEntity> getUser() { 29 | return ResponseEntity.ok(service.getAll()); 30 | } 31 | 32 | @PostMapping("/add-user") 33 | @ResponseStatus(HttpStatus.CREATED) 34 | public ResponseEntity> addUser(@RequestPart("user") Register register, 35 | @RequestPart("imageFile") MultipartFile imageFile) { 36 | Map response = new HashMap<>(); 37 | try { 38 | service.addUser(register, imageFile); 39 | response.put("message", "User created successfully"); 40 | return ResponseEntity.status(HttpStatus.CREATED).body(response); 41 | } catch (IOException e) { 42 | response.put("error", "Error creating User: " + e.getMessage()); 43 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 44 | } 45 | } 46 | 47 | @GetMapping("/searchUser-by-id/{id}") 48 | public ResponseEntity getLecturerById(@PathVariable Long id) { 49 | try { 50 | Register register = service.searchUserById(id); 51 | return ResponseEntity.ok(register); 52 | } catch (EntityNotFoundException e) { 53 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User not found with ID: " + id); 54 | } 55 | } 56 | 57 | @DeleteMapping("/deleteUser-by-id/{id}") 58 | public ResponseEntity> deleteLecturerById(@PathVariable Long id) { 59 | Map response = new HashMap<>(); 60 | try { 61 | service.deleteUserById(id); 62 | response.put("message", "User deleted successfully"); 63 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); 64 | } catch (EntityNotFoundException e) { 65 | response.put("error", "User not found with ID: " + id); 66 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 67 | } 68 | } 69 | 70 | @PutMapping("/update-user") 71 | @ResponseStatus(HttpStatus.ACCEPTED) 72 | public ResponseEntity> updateLecturer( 73 | @RequestPart("user") Register register, 74 | @RequestPart(value = "imageFile", required = false) MultipartFile imageFile) { 75 | Map response = new HashMap<>(); 76 | try { 77 | service.updateUserById(register, imageFile); 78 | response.put("message", "User updated successfully"); 79 | return ResponseEntity.ok(response); 80 | } catch (IOException e) { 81 | response.put("error", "Error updating User: " + e.getMessage()); 82 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 83 | } catch (EntityNotFoundException e) { 84 | response.put("error", "Lecturer not found with ID: " + register.getReg_id()); 85 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 86 | } 87 | } 88 | @GetMapping("/get-last-users/{count}") 89 | public ResponseEntity> getLastUsers(@PathVariable int count) { 90 | List lastUsers = service.getLastUsers(count); 91 | return ResponseEntity.ok(lastUsers); 92 | } 93 | } -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/impl/RegisterServiceImpl.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service.impl; 2 | 3 | import edu.icet.dto.Register; 4 | import edu.icet.entity.RegisterEntity; 5 | import edu.icet.repository.RegisterRepository; 6 | import edu.icet.service.RegisterService; 7 | import jakarta.persistence.EntityNotFoundException; 8 | import lombok.RequiredArgsConstructor; 9 | import org.modelmapper.ModelMapper; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.data.domain.PageRequest; 12 | import org.springframework.data.domain.Pageable; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.web.multipart.MultipartFile; 15 | 16 | import java.io.IOException; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.Optional; 20 | 21 | @Service 22 | @RequiredArgsConstructor 23 | public class RegisterServiceImpl implements RegisterService { 24 | @Autowired 25 | private final RegisterRepository repository; 26 | private final ModelMapper mapper; 27 | 28 | @Override 29 | public List getAll() { 30 | List customerArrayList = new ArrayList<>(); 31 | repository.findAll().forEach(entity->{ 32 | customerArrayList.add(mapper.map(entity, Register.class)); 33 | }); 34 | return customerArrayList; 35 | } 36 | 37 | @Override 38 | public void addUser(Register user, MultipartFile imageFile) throws IOException { 39 | if (imageFile != null && !imageFile.isEmpty()) { 40 | user.setImageName(imageFile.getOriginalFilename()); 41 | user.setImageType(imageFile.getContentType()); 42 | user.setImageData(imageFile.getBytes()); 43 | } 44 | RegisterEntity entity = mapper.map(user, RegisterEntity.class); 45 | repository.save(entity); 46 | } 47 | 48 | @Override 49 | public Register searchUserById(Long id) { 50 | Optional entity = repository.findById(id); 51 | return entity.map(e -> mapper.map(e, Register.class)).orElse(null); 52 | } 53 | 54 | @Override 55 | public void deleteUserById(Long id) { 56 | if (repository.existsById(id)) { 57 | repository.deleteById(id); 58 | } 59 | } 60 | 61 | @Override 62 | public RegisterEntity findByEmail(String email) { 63 | return repository.findByEmail(email); 64 | } 65 | @Override 66 | public void updateUserById(Register user, MultipartFile imageFile) throws IOException { 67 | Optional existingEntityOpt = repository.findById(user.getReg_id()); 68 | 69 | if (existingEntityOpt.isPresent()) { 70 | RegisterEntity existingEntity = existingEntityOpt.get(); 71 | 72 | existingEntity.setProgram(user.getProgram()); 73 | existingEntity.setTitle(user.getTitle()); 74 | existingEntity.setReferral(user.getReferral()); 75 | existingEntity.setShortName(user.getShortName()); 76 | existingEntity.setFullName(user.getFullName()); 77 | existingEntity.setDob(user.getDob()); 78 | existingEntity.setCountry(user.getCountry()); 79 | existingEntity.setPassport(user.getPassport()); 80 | existingEntity.setMobile(user.getMobile()); 81 | existingEntity.setEmail(user.getEmail()); 82 | existingEntity.setAddress(user.getAddress()); 83 | 84 | existingEntity.setUsername(user.getUsername()); 85 | existingEntity.setPassword(user.getPassword()); 86 | 87 | if (imageFile != null && !imageFile.isEmpty()) { 88 | existingEntity.setImageName(imageFile.getOriginalFilename()); 89 | existingEntity.setImageType(imageFile.getContentType()); 90 | existingEntity.setImageData(imageFile.getBytes()); 91 | } 92 | 93 | repository.save(existingEntity); 94 | } else { 95 | throw new EntityNotFoundException("User with ID " + user.getReg_id() + " not found"); 96 | } 97 | } 98 | 99 | @Override 100 | public List getLastUsers(int count) { 101 | Pageable pageable = PageRequest.of(0, count); 102 | return repository.findByOrderByCreatedDateDesc(pageable); 103 | } 104 | 105 | } 106 | 107 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZONY Campus Backend 🚀 🎓 2 | 3 | **Smart Learning Management System (LMS) powered by Spring Boot** - A comprehensive backend solution for managing educational institutions, courses, and user interactions. This repository implements secure authentication, role-based access control, and integrations with external services. 4 | 5 | --- 6 | 7 | ## 🌟 Features 8 | 9 | - 👥 **User Management** 10 | - Secure user registration and authentication 11 | - Profile management and updates 12 | - Role-based access control 13 | 14 | - 📚 **Course Management** 15 | - Create, read, update, and delete courses 16 | - Course enrollment and progress tracking 17 | - Assignment and resource management 18 | 19 | - 👨‍🏫 **Faculty Management** 20 | - Faculty assignment to courses 21 | - Teaching schedule management 22 | - Performance tracking 23 | 24 | - 💳 **Payment Integration** 25 | - Secure payment processing 26 | - Fee management 27 | - Transaction history 28 | 29 | - 📱 **Notifications** 30 | - Real-time updates 31 | - Email notifications 32 | - SMS alerts (optional) 33 | 34 | --- 35 | 36 | ## 🛠️ Tech Stack 37 | 38 | - **Backend Framework**: Java Spring Boot 39 | - **Security**: Spring Security, JWT Authentication 40 | - **Database**: MySQL 41 | - **ORM**: Hibernate 42 | - **Build Tool**: Maven 43 | - **Documentation**: Swagger/OpenAPI 44 | 45 | --- 46 | 47 | ## 📦 Installation 48 | 49 | 1. **Prerequisites** 50 | ```bash 51 | - Java 11 or higher 52 | - MySQL 8.0 or higher 53 | - Maven 3.6+ 54 | ``` 55 | 56 | 2. **Clone the repository** 57 | ```bash 58 | git clone https://github.com/Chathupachamika/ZONY_Campus-backend.git 59 | cd ZONY_Campus-backend 60 | ``` 61 | 62 | 3. **Configure Database** 63 | Create a new MySQL database and update `application.properties`: 64 | ```properties 65 | spring.datasource.url=jdbc:mysql://localhost:3306/zony_campus 66 | spring.datasource.username=your_username 67 | spring.datasource.password=your_password 68 | ``` 69 | 70 | 4. **Build and Run** 71 | ```bash 72 | mvn clean install 73 | mvn spring-boot:run 74 | ``` 75 | 76 | --- 77 | 78 | ## 🚀 API Endpoints 79 | 80 | ### Authentication 81 | - **POST** `/api/auth/register` - Register new user 82 | - **POST** `/api/auth/login` - User login 83 | - **GET** `/api/auth/profile` - Get user profile 84 | 85 | ### Courses 86 | - **GET** `/api/courses` - List all courses 87 | - **POST** `/api/courses` - Create new course 88 | - **GET** `/api/courses/{id}` - Get course details 89 | - **PUT** `/api/courses/{id}` - Update course 90 | - **DELETE** `/api/courses/{id}` - Delete course 91 | 92 | ### Faculty 93 | - **GET** `/api/faculty` - List all faculty members 94 | - **POST** `/api/faculty` - Add new faculty 95 | - **PUT** `/api/faculty/{id}` - Update faculty details 96 | 97 | ### Payments 98 | - **POST** `/api/payments/process` - Process payment 99 | - **GET** `/api/payments/history` - Get payment history 100 | 101 | --- 102 | 103 | ## 📂 Project Structure 104 | 105 | ```plaintext 106 | ZONY_Campus-backend/ 107 | ├── src/ 108 | │ ├── main/ 109 | │ │ ├── java/ 110 | │ │ │ └── com/zony/campus/ 111 | │ │ │ ├── config/ 112 | │ │ │ ├── controller/ 113 | │ │ │ ├── model/ 114 | │ │ │ ├── repository/ 115 | │ │ │ ├── service/ 116 | │ │ │ └── util/ 117 | │ │ └── resources/ 118 | │ │ └── application.properties 119 | │ └── test/ 120 | ├── pom.xml 121 | └── README.md 122 | ``` 123 | 124 | --- 125 | 126 | ## 🔐 Security Considerations 127 | 128 | - Implements JWT-based authentication 129 | - Role-based access control (RBAC) 130 | - Password encryption using BCrypt 131 | - Input validation and sanitization 132 | - CORS configuration 133 | - Rate limiting for API endpoints 134 | 135 | --- 136 | 137 | ## 🚀 Deployment 138 | 139 | 1. **Build the JAR file** 140 | ```bash 141 | mvn clean package 142 | ``` 143 | 144 | 2. **Run the application** 145 | ```bash 146 | java -jar target/zony-campus-backend.jar 147 | ``` 148 | 149 | --- 150 | 151 | ## 🧪 Testing 152 | 153 | Run the test suite: 154 | ```bash 155 | mvn test 156 | ``` 157 | 158 | --- 159 | 160 | ## 📖 Documentation 161 | 162 | API documentation is available at: 163 | - Swagger UI: `http://localhost:8080/swagger-ui.html` 164 | - API Docs: `http://localhost:8080/v3/api-docs` 165 | 166 | --- 167 | 168 | ## 🤝 Contributing 169 | 170 | 1. Fork the repository 171 | 2. Create your feature branch (`git checkout -b feature/AmazingFeature`) 172 | 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) 173 | 4. Push to the branch (`git push origin feature/AmazingFeature`) 174 | 5. Open a Pull Request 175 | 176 | --- 177 | 178 | ## 📜 License 179 | 180 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 181 | 182 | --- 183 | 184 | ## 📧 Contact 185 | 186 | Chathupa Chamika - [chathupachamika765@gmail.com] 187 | 188 | Project Link: [https://github.com/Chathupachamika/ZONY_Campus-backend](https://github.com/Chathupachamika/ZONY_Campus-backend) 189 | 190 | --- 191 | Made with ❤️ by the Chathupa Chamika 192 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/service/impl/ProgramServiceImpl.java: -------------------------------------------------------------------------------- 1 | package edu.icet.service.impl; 2 | 3 | import edu.icet.dto.Program; 4 | import edu.icet.entity.ProgramEntity; 5 | import edu.icet.repository.ProgramRepository; 6 | import edu.icet.service.ProgramService; 7 | import jakarta.persistence.EntityNotFoundException; 8 | import lombok.RequiredArgsConstructor; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | import java.util.Optional; 15 | import java.util.stream.Collectors; 16 | 17 | @Service 18 | @RequiredArgsConstructor 19 | public class ProgramServiceImpl implements ProgramService { 20 | 21 | private final ProgramRepository programRepository; 22 | 23 | @Override 24 | public List getAllProgram() { 25 | return programRepository.findAll() 26 | .stream() 27 | .map(this::convertToDto) 28 | .collect(Collectors.toList()); 29 | } 30 | 31 | @Override 32 | public void addProgram(Program program, MultipartFile imageFile) { 33 | ProgramEntity programEntity = convertToEntity(program); 34 | if (imageFile != null && !imageFile.isEmpty()) { 35 | try { 36 | programEntity.setProgramImageName(imageFile.getOriginalFilename()); 37 | programEntity.setProgramImageType(imageFile.getContentType()); 38 | programEntity.setProgramImageData(imageFile.getBytes()); 39 | } catch (IOException e) { 40 | throw new RuntimeException("Failed to store image file: " + e.getMessage()); 41 | } 42 | } 43 | programRepository.save(programEntity); 44 | } 45 | 46 | @Override 47 | public void updateProgramById(Program program, MultipartFile imageFile) { 48 | Optional existingProgramOpt = programRepository.findById(program.getProgramId()); 49 | if (existingProgramOpt.isPresent()) { 50 | ProgramEntity existingProgram = existingProgramOpt.get(); 51 | existingProgram.setProgramName(program.getProgramName()); 52 | existingProgram.setProgramMission(program.getProgramMission()); 53 | existingProgram.setProgramDetails(program.getProgramDetails()); 54 | existingProgram.setProgramVenue(program.getProgramVenue()); 55 | existingProgram.setProgramDateTime(program.getProgramDateTime()); 56 | 57 | if (imageFile != null && !imageFile.isEmpty()) { 58 | try { 59 | existingProgram.setProgramImageName(imageFile.getOriginalFilename()); 60 | existingProgram.setProgramImageType(imageFile.getContentType()); 61 | existingProgram.setProgramImageData(imageFile.getBytes()); 62 | } catch (IOException e) { 63 | throw new RuntimeException("Failed to store image file: " + e.getMessage()); 64 | } 65 | } 66 | programRepository.save(existingProgram); 67 | } else { 68 | throw new EntityNotFoundException("Program not found with ID: " + program.getProgramId()); 69 | } 70 | } 71 | 72 | @Override 73 | public void deleteProgramById(Long id) { 74 | if (programRepository.existsById(id)) { 75 | programRepository.deleteById(id); 76 | } else { 77 | throw new EntityNotFoundException("Program not found with ID: " + id); 78 | } 79 | } 80 | 81 | @Override 82 | public Program searchProgramById(Long id) { 83 | ProgramEntity programEntity = programRepository.findById(id) 84 | .orElseThrow(() -> new EntityNotFoundException("Program not found with ID: " + id)); 85 | return convertToDto(programEntity); 86 | } 87 | 88 | private Program convertToDto(ProgramEntity programEntity) { 89 | return new Program( 90 | programEntity.getProgramId(), 91 | programEntity.getProgramName(), 92 | programEntity.getProgramMission(), 93 | programEntity.getProgramDetails(), 94 | programEntity.getProgramVenue(), 95 | programEntity.getProgramDateTime(), 96 | programEntity.getProgramImageName(), 97 | programEntity.getProgramImageType(), 98 | programEntity.getProgramImageData() 99 | ); 100 | } 101 | 102 | private ProgramEntity convertToEntity(Program program) { 103 | ProgramEntity programEntity = new ProgramEntity(); 104 | programEntity.setProgramId(program.getProgramId()); 105 | programEntity.setProgramName(program.getProgramName()); 106 | programEntity.setProgramMission(program.getProgramMission()); 107 | programEntity.setProgramDetails(program.getProgramDetails()); 108 | programEntity.setProgramVenue(program.getProgramVenue()); 109 | programEntity.setProgramDateTime(program.getProgramDateTime()); 110 | programEntity.setProgramImageName(program.getProgramImageName()); 111 | programEntity.setProgramImageType(program.getProgramImageType()); 112 | programEntity.setProgramImageData(program.getProgramImageData()); 113 | return programEntity; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/edu/icet/controller/LecturerController.java: -------------------------------------------------------------------------------- 1 | package edu.icet.controller; 2 | 3 | import edu.icet.dto.Lecturer; 4 | import edu.icet.entity.LecturerEntity; 5 | import edu.icet.service.LecturerService; 6 | import jakarta.persistence.EntityNotFoundException; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.IOException; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | @CrossOrigin 20 | @RestController 21 | @RequestMapping("/lecturer") 22 | @RequiredArgsConstructor 23 | public class LecturerController { 24 | @Autowired 25 | private final LecturerService service; 26 | 27 | @GetMapping("/get-allLecturer") 28 | public ResponseEntity> getLecturers() { 29 | return ResponseEntity.ok(service.getAllLecturer()); 30 | } 31 | 32 | @PostMapping("/add-lecturer") 33 | @ResponseStatus(HttpStatus.CREATED) 34 | public ResponseEntity> addLecturer(@RequestPart("lecturer") Lecturer lecturer, 35 | @RequestPart("imageFile") MultipartFile imageFile) { 36 | Map response = new HashMap<>(); 37 | try { 38 | service.addLecturer(lecturer, imageFile); 39 | response.put("message", "Lecturer created successfully"); 40 | return ResponseEntity.status(HttpStatus.CREATED).body(response); 41 | } catch (IOException e) { 42 | response.put("error", "Error creating lecturer: " + e.getMessage()); 43 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 44 | } 45 | } 46 | 47 | @GetMapping("/searchLecturer-by-id/{id}") 48 | public ResponseEntity getLecturerById(@PathVariable Long id) { 49 | try { 50 | Lecturer lecturer = service.searchLecturerById(id); 51 | return ResponseEntity.ok(lecturer); 52 | } catch (EntityNotFoundException e) { 53 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Lecturer not found with ID: " + id); 54 | } 55 | } 56 | 57 | @GetMapping("/searchLecturer-by-faculty/{faculty}") 58 | public ResponseEntity getLecturerByFaculty(@PathVariable String faculty) { 59 | try { 60 | List lecturers = service.searchLecturerByFaculty(faculty); 61 | if (lecturers.isEmpty()) { 62 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No lecturers found for faculty: " + faculty); 63 | } 64 | return ResponseEntity.ok(lecturers); 65 | } catch (Exception e) { 66 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred while searching for lecturers."); 67 | } 68 | } 69 | 70 | @GetMapping("/searchLecturer-by-name/{lecturerName}") 71 | public ResponseEntity getLecturerByName(@PathVariable String lecturerName) { 72 | try { 73 | List lecturers = service.searchLecturerByName(lecturerName); 74 | if (lecturers.isEmpty()) { 75 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No lecturers found with name: " + lecturerName); 76 | } 77 | return ResponseEntity.ok(lecturers); 78 | } catch (Exception e) { 79 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred while searching for lecturers."); 80 | } 81 | } 82 | 83 | @DeleteMapping("/deleteLecturer-by-id/{id}") 84 | public ResponseEntity> deleteLecturerById(@PathVariable Long id) { 85 | Map response = new HashMap<>(); 86 | try { 87 | service.deleteLecturerById(id); 88 | response.put("message", "Lecturer deleted successfully"); 89 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(response); 90 | } catch (EntityNotFoundException e) { 91 | response.put("error", "Lecturer not found with ID: " + id); 92 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 93 | } 94 | } 95 | 96 | @PutMapping("/update-lecturer") 97 | @ResponseStatus(HttpStatus.ACCEPTED) 98 | public ResponseEntity> updateLecturer( 99 | @RequestPart("lecturer") Lecturer lecturer, 100 | @RequestPart(value = "imageFile", required = false) MultipartFile imageFile) { 101 | Map response = new HashMap<>(); 102 | try { 103 | service.updateLecturerById(lecturer, imageFile); 104 | response.put("message", "Lecturer updated successfully"); 105 | return ResponseEntity.ok(response); 106 | } catch (IOException e) { 107 | response.put("error", "Error updating lecturer: " + e.getMessage()); 108 | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); 109 | } catch (EntityNotFoundException e) { 110 | response.put("error", "Lecturer not found with ID: " + lecturer.getLecturer_id()); 111 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 66 | 67 | 69 | { 70 | "associatedIndex": 1 71 | } 72 | 73 | 74 | 77 | 88 | 89 | 92 | 93 | 94 | 95 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 1734717387517 118 | 122 | 123 | 124 | --------------------------------------------------------------------------------