added every delete endpoint required
This commit is contained in:
parent
a80fb2b297
commit
93c161be4c
@ -11,7 +11,6 @@ import ovh.herisson.Clyde.Services.TeacherCourseService;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -119,4 +118,20 @@ public class CourseController {
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("course/{id}")
|
||||
public ResponseEntity<String> deleteUser(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Course toDelete = courseServ.findById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
|
||||
courseServ.delete(courseServ.findById(id));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -67,4 +67,18 @@ public class CurriculumController {
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/curriculum/{id}")
|
||||
public ResponseEntity<String > deleteCurriculum(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Curriculum toDelete = curriculumServ.findById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
curriculumServ.delete(toDelete);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@ -68,4 +66,18 @@ public class InscriptionController {
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
@DeleteMapping("/request/register/{id}")
|
||||
public ResponseEntity<String > deleteRequest(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
InscriptionRequest toDelete = inscriptionServ.getById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
inscriptionServ.delete(toDelete);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -127,7 +127,12 @@ public class UserController {
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
userService.delete(userService.getUserById(id));
|
||||
User toDelete = userService.getUserById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
userService.delete(toDelete);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -77,4 +77,7 @@ public class CourseService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void delete(Course course) {
|
||||
courseRepo.delete(course);
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,7 @@ public class CurriculumService {
|
||||
return curriculumRepo.findById(id);
|
||||
}
|
||||
|
||||
public void delete(Curriculum curriculum) {
|
||||
curriculumRepo.delete(curriculum);
|
||||
}
|
||||
}
|
@ -87,4 +87,8 @@ public class InscriptionService {
|
||||
save(inscrRequest);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void delete(InscriptionRequest toDelete) {
|
||||
inscriptionRepo.delete(toDelete);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,10 @@ public class ProtectionService {
|
||||
* @return all the user data without the password
|
||||
*/
|
||||
public static HashMap<String,Object> userWithoutPassword(User user){
|
||||
|
||||
if (user ==null)
|
||||
return null;
|
||||
|
||||
HashMap<String,Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("regNo",user.getRegNo());
|
||||
@ -42,6 +46,9 @@ public class ProtectionService {
|
||||
|
||||
|
||||
public static HashMap<String,Object> courseWithoutPassword(Course course){
|
||||
if (course == null)
|
||||
return null;
|
||||
|
||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("courseId",course.getCourseID());
|
||||
@ -64,6 +71,10 @@ public class ProtectionService {
|
||||
|
||||
|
||||
public static Map<String, Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
||||
|
||||
if (inscriptionRequest == null)
|
||||
return null;
|
||||
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("id", inscriptionRequest.getId());
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
public class Course {
|
||||
@ -11,6 +13,7 @@ public class Course {
|
||||
private String title;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.SET_NULL)
|
||||
@JoinColumn(name = "Users")
|
||||
private User owner;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user