Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.scoalaonline.api.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("DELETE", "GET", "PUT", "POST")
.maxAge(3600);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public ResponseEntity<Corporatist> addCorporatist (@RequestBody Corporatist corp
* @param corporatist which is the updated entity
* @return the updated Corporatist with the Http status created.
*/

@PutMapping(value = ("/{id}"))
public ResponseEntity<Corporatist> updateCorporatist (@PathVariable("id") long id,
@RequestBody Corporatist corporatist) {
Expand All @@ -75,4 +74,21 @@ public ResponseEntity<Corporatist> updateCorporatist (@PathVariable("id") long i
);
}
}

/**
* Deletes a Corporatist entity from the database.
* @param id which is the entity's id to be deleted
* @return the deleted Corporatist with the Http status created.
*/
@DeleteMapping(value = ("/{id}"))
public ResponseEntity<HttpStatus> deleteCorporatist (@PathVariable("id") long id) {
if (corporatistService.corporatistExists(id)) {
corporatistService.deleteCorporatist(id);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} else {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cannot delete non-existing Corporatist", new ResourceNotFoundException()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public ResponseEntity<Department> getDepartmentById(@PathVariable("id") long id)
return new ResponseEntity<>(department, HttpStatus.OK);
}


/**
* Adds a department entity into the database.
* @param department which is the entity to be added
Expand All @@ -57,16 +56,16 @@ public ResponseEntity<Department> addDepartment (@RequestBody Department departm
return new ResponseEntity<>(savedDepartment, HttpStatus.CREATED);
}


/**
* Updates a Department entity from the database.
* @param id which is the entity's id to be changed
* @param department which is the updated entity
* @return the updated Department with the Http status created.
*/

@PutMapping(value = ("/{id}"))
public ResponseEntity<Department> updateDepartment (@PathVariable("id") long id,
@RequestBody Department department) {
@RequestBody Department department) {
if (departmentService.departmentExists(id)) {
Department updatedDepartment = departmentService.updateDepartment(id, department);
return new ResponseEntity<>(updatedDepartment, HttpStatus.ACCEPTED);
Expand All @@ -76,4 +75,21 @@ public ResponseEntity<Department> updateDepartment (@PathVariable("id") long id,
);
}
}

/**
* Deletes a Department entity from the database.
* @param id which is the entity's id to be deleted
* @return the deleted Department with the Http status created.
*/
@DeleteMapping(value = ("/{id}"))
public ResponseEntity<HttpStatus> deleteDepartment (@PathVariable("id") long id) {
if (departmentService.departmentExists(id)) {
departmentService.deleteDepartment(id);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} else {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cannot delete non-existing Department", new ResourceNotFoundException()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.scoalaonline.api.controller;

import net.bytebuddy.implementation.bind.annotation.Super;
import org.scoalaonline.api.model.Corporatist;
import org.scoalaonline.api.model.Department;
import org.scoalaonline.api.model.Supervisor;
import org.scoalaonline.api.service.SupervisorService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -59,13 +57,13 @@ public ResponseEntity<Supervisor> addSupervisor (@RequestBody Supervisor supervi
return new ResponseEntity<>(savedSupervisor, HttpStatus.CREATED);
}


/**
* Updates a Supervisor entity from the database.
* @param id which is the entity's id to be changed
* @param supervisor which is the updated entity
* @return the updated Supervisor with the Http status created.
*/

@PutMapping(value = ("/{id}"))
public ResponseEntity<Supervisor> updateSupervisor (@PathVariable("id") long id,
@RequestBody Supervisor supervisor) {
Expand All @@ -78,4 +76,22 @@ public ResponseEntity<Supervisor> updateSupervisor (@PathVariable("id") long id,
);
}
}

/**
* Deletes a Supervisor entity from the database.
* @param id which is the entity's id to be deleted
* @return the deleted Supervisor with the Http status created.
*/
@DeleteMapping(value = ("/{id}"))
public ResponseEntity<HttpStatus> deleteSupervisor (@PathVariable("id") long id) {
if (supervisorService.supervisorExists(id)) {
supervisorService.deleteSupervisor(id);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} else {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cannot delete non-existing Supervisor", new ResourceNotFoundException()
);
}
}

}