Skip to content
Permalink
Browse files
back-end code
  • Loading branch information
pokkakillr committed Mar 3, 2023
1 parent 1f54fc9 commit 154311c6a7e10768d4f2bc07ea0fce3d5bba9a80
Show file tree
Hide file tree
Showing 24 changed files with 740 additions and 0 deletions.
BIN +6 KB .DS_Store
Binary file not shown.
BIN +6 KB back-end/.DS_Store
Binary file not shown.
@@ -0,0 +1,30 @@
package dev.phoenix.trainingApplicationSystem;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@RestController
public class TrainingApplicationSystemApplication {

public static void main(String[] args) {
SpringApplication.run(TrainingApplicationSystemApplication.class, args);
}
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(false).maxAge(3600);
}
};
}
}
@@ -0,0 +1,37 @@
package dev.phoenix.trainingApplicationSystem.controllers;

import dev.phoenix.trainingApplicationSystem.services.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/my-courses")
public class ApplicationController {
@Autowired
private ApplicationService applicationService;

//adding to the sessionIDList
@PostMapping("/sessionList/{userID}/{sessionID}")
public ResponseEntity<String> applyToCourses(@PathVariable String userID,@PathVariable String sessionID){
System.out.println("session payload "+ sessionID);
return new ResponseEntity<>(applicationService.addCourseIds(userID,sessionID), HttpStatus.CREATED);
}

//Get sessionIdList by userID
@GetMapping("/{userID}")
public ResponseEntity<List> getSessionList(@PathVariable String userID){
return new ResponseEntity<>(applicationService.getSessionIdListByUserID(userID), HttpStatus.CREATED);
}

// to delete the course id from the list

@DeleteMapping("/users/{userID}/sessions/{sessionID}")
public ResponseEntity<String> dropCourse(@PathVariable String userID, @PathVariable String sessionID){
return new ResponseEntity<>(applicationService.deleteCourseIds(userID,sessionID), HttpStatus.CREATED);
}

}
@@ -0,0 +1,47 @@
package dev.phoenix.trainingApplicationSystem.controllers;

import dev.phoenix.trainingApplicationSystem.services.CourseListService;
import dev.phoenix.trainingApplicationSystem.model.CourseItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/course-list")
public class CourseListController{
@Autowired
private CourseListService courseListService;
//to get all training information
@GetMapping
public ResponseEntity<List<CourseItem>> getAllCourses() {
return new ResponseEntity<List<CourseItem>>(courseListService.findAllCourses(), HttpStatus.OK);
}
//To get the single training information

@GetMapping("/{sessionID}")
public ResponseEntity<Optional<CourseItem>> getSingleCourse(@PathVariable String sessionID){
return new ResponseEntity<Optional<CourseItem>>(courseListService.findCoursesBySessionID(sessionID), HttpStatus.OK);
}
//To get the whole training description for the array of sessionids passed
@GetMapping("/list/courses")
public ResponseEntity<List<CourseItem>> getCoursesByIds(@RequestParam List<String> sessionIDs) {
List<CourseItem> courses = courseListService.findCoursesByIds(sessionIDs);
if (courses.isEmpty()) {
return ResponseEntity.noContent().build();
} else {
return ResponseEntity.ok(courses);
}
}





}




@@ -0,0 +1,38 @@
package dev.phoenix.trainingApplicationSystem.controllers;

import dev.phoenix.trainingApplicationSystem.services.JobListService;
import dev.phoenix.trainingApplicationSystem.model.JobItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/job-list")
public class JobListController {
@Autowired
private JobListService jobListService;

@GetMapping
public ResponseEntity<List<JobItem>> getAllJobs() {
return new ResponseEntity<List<JobItem>>(jobListService.findAllJobs(), HttpStatus.OK);
}

@GetMapping("/{jobID}")
public ResponseEntity<Optional<JobItem>> getSingleJob(@PathVariable String jobID){
return new ResponseEntity<Optional<JobItem>>(jobListService.findJobsByJobID(jobID), HttpStatus.OK);
}

@GetMapping("/type/{fieldType}")
public ResponseEntity<Optional<List<JobItem>>> getAllJobByFieldType(@PathVariable String fieldType){
return new ResponseEntity<Optional<List<JobItem>>>(jobListService.findAllJobsByFieldType(fieldType), HttpStatus.OK);
}

}


@@ -0,0 +1,47 @@
package dev.phoenix.trainingApplicationSystem.controllers;

import dev.phoenix.trainingApplicationSystem.services.UserService;
import dev.phoenix.trainingApplicationSystem.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;


import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Optional;


@RestController
@RequestMapping("/api/user")
public class UserController{
@Autowired
private UserService userService;
//to get a User object from a user name
@GetMapping("/{userName}")
public ResponseEntity<Optional<User>> getSingleUserName(@PathVariable String userName){
return new ResponseEntity<Optional<User>>(userService.findByUserName(userName), HttpStatus.OK);
}
//to post the information given by the user at the time of registration
@PostMapping("/register")
public ResponseEntity<String> addNewUserOnRegister(@RequestBody User user){
return new ResponseEntity<>(userService.addNewUser(user,user.getUserName()), HttpStatus.CREATED);
}
//To check authentication of the user at the time of login
@PostMapping("/login")
public ResponseEntity<?> loginExistingUser(@RequestBody Map <String,String> payload) {
Optional<User> user = userService.login(payload.get("userName"), payload.get("password"));
if (user != null) {
return ResponseEntity.ok(user);
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
}
//to update the information of the user on edit details
@PutMapping("/users/{userID}")
public ResponseEntity<Void> updateUser(@PathVariable String userID, @RequestBody User updatedUser) {
userService.updateUser(userID, updatedUser);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
@@ -0,0 +1,34 @@
package dev.phoenix.trainingApplicationSystem.controllers;

import dev.phoenix.trainingApplicationSystem.services.UserJobTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/job-field-type")
public class UserJobTypeController{
@Autowired
private UserJobTypeService userJobTypeService;

//adding to fieldtype list
@PostMapping("/fieldTypeList/{fieldType}/{userID}")
public ResponseEntity<String> addFieldTypeByUserID(@PathVariable String fieldType,@PathVariable String userID){
System.out.println("jobtype payload "+fieldType);
return new ResponseEntity<>(userJobTypeService.addJobTypeList(fieldType,userID), HttpStatus.CREATED);
}


@GetMapping("/list/{userID}")
public ResponseEntity<List> getFieldTypeList(@PathVariable String userID){
return new ResponseEntity<>(userJobTypeService.getJobTypeListByUserID(userID), HttpStatus.CREATED);
}

}




@@ -0,0 +1,29 @@
package dev.phoenix.trainingApplicationSystem.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;
@Document(collection="applied-courses-list")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApplicationListItem {
@Id
private ObjectId id;

private String userID;


private List sessionIDList;

public ApplicationListItem(String userID, List sessionIDList) {
this.userID = userID;
this.sessionIDList = sessionIDList;
}

}
@@ -0,0 +1,36 @@
package dev.phoenix.trainingApplicationSystem.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

@Document(collection = "course-list")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CourseItem {
@Id
private ObjectId id;
private String sessionID;
private String sessionName;
private String sessionDescription;
private String sessionInstructor;
private String sessionDuration;
private List<String> sessionLevel;
private String Location;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date sessionStartDate;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date sessionEndDate;
private String fieldType;
private String sessionModules;
private String imageURL;

}
@@ -0,0 +1,27 @@
package dev.phoenix.trainingApplicationSystem.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "job-list")
@Data
@AllArgsConstructor
@NoArgsConstructor

public class JobItem {
@Id
private ObjectId id;
private String jobID;
private String jobTitle;
private String jobCompany;
private String applyLink;
private String fieldType;

private String jobDescription;
private String salaryRange;
private String preRequisites;
}
@@ -0,0 +1,52 @@
package dev.phoenix.trainingApplicationSystem.model;

import dev.phoenix.trainingApplicationSystem.model.CourseItem;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DocumentReference;


import java.util.List;
import java.util.Map;

@Document(collection = "users")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
@Id
private ObjectId id;
private String userID;
private String userName;
private String password;
private String userFName;
private String userLName;
private String userEmail;

public User(String userName, String password) {
this.userName = userName;
this.password = password;
}
public String getPassword() {
return password;
}

public User(String userID, String userName, String password, String userFName, String userLName, String userEmail) {
this.userID = userID;
this.userName = userName;
this.password = password;
this.userFName = userFName;
this.userLName = userLName;
this.userEmail = userEmail;
}

public User (Map user){
this.setUserEmail(user.get("userEmail").toString());
}
@DocumentReference
private List<CourseItem> sessionIDs;
}

0 comments on commit 154311c

Please sign in to comment.