diff --git a/Springboot/Springboot/.vscode/launch.json b/Springboot/Springboot/.vscode/launch.json new file mode 100644 index 0000000..ecd0b8f --- /dev/null +++ b/Springboot/Springboot/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "type": "java", + "name": "Spring Boot-SpringbootApplication", + "request": "launch", + "cwd": "${workspaceFolder}", + "mainClass": "com.program.Springboot.SpringbootApplication", + "projectName": "Springboot", + "args": "", + "envFile": "${workspaceFolder}/.env" + } + ] +} \ No newline at end of file diff --git a/Springboot/Springboot/src/main/java/com/program/Springboot/controller/StudentController.java b/Springboot/Springboot/src/main/java/com/program/Springboot/controller/StudentController.java index 6a371ac..cf8e60e 100644 --- a/Springboot/Springboot/src/main/java/com/program/Springboot/controller/StudentController.java +++ b/Springboot/Springboot/src/main/java/com/program/Springboot/controller/StudentController.java @@ -19,11 +19,11 @@ @RestController @RequestMapping("/api") // All endpoints will start with /api public class StudentController { - + @Autowired private final StudentService studentService; // Constructor Injection (best practice) - @Autowired + public StudentController(StudentService studentService) { this.studentService = studentService; } diff --git a/Springboot/Springboot/src/main/java/com/program/Springboot/service/impl/StudentServiceImpl.java b/Springboot/Springboot/src/main/java/com/program/Springboot/service/impl/StudentServiceImpl.java index a2b71b2..ad6b42e 100644 --- a/Springboot/Springboot/src/main/java/com/program/Springboot/service/impl/StudentServiceImpl.java +++ b/Springboot/Springboot/src/main/java/com/program/Springboot/service/impl/StudentServiceImpl.java @@ -11,7 +11,9 @@ import com.program.Springboot.model.Student; import com.program.Springboot.service.StudentService; -public class StudentServiceImpl extends StudentService { + +@Service +public class StudentServiceImpl implements StudentService { // Simulated database (key = pkStudentID, value = Student object) private final Map studentDB = new HashMap<>(); @@ -30,9 +32,9 @@ public Optional getStudentById(Long id) { @Override public Student addStudent(Student student) { - // store student using their ID as the key + studentDB.put(student.getPkStudentID(), student); return student; - } + } @Override public Student updateStudent(Long id, Student updatedStudent) { @@ -54,9 +56,9 @@ public Student updateStudent(Long id, Student updatedStudent) { public boolean deleteStudent(Long id) { if (studentDB.containsKey(id)) { studentDB.remove(id); - return false; + return true; } - return true; + return false; } } \ No newline at end of file diff --git a/Springboot/Springboot/src/main/resources/application.properties b/Springboot/Springboot/src/main/resources/application.properties index 6f582e0..9ab9860 100644 --- a/Springboot/Springboot/src/main/resources/application.properties +++ b/Springboot/Springboot/src/main/resources/application.properties @@ -1,2 +1,2 @@ spring.application.name=Springboot -server.port = 9O90 +server.port = 9090 diff --git a/Springboot/Springboot/target/classes/application.properties b/Springboot/Springboot/target/classes/application.properties index 6f582e0..9ab9860 100644 --- a/Springboot/Springboot/target/classes/application.properties +++ b/Springboot/Springboot/target/classes/application.properties @@ -1,2 +1,2 @@ spring.application.name=Springboot -server.port = 9O90 +server.port = 9090 diff --git a/Springboot/Springboot/target/classes/com/program/Springboot/controller/StudentController.class b/Springboot/Springboot/target/classes/com/program/Springboot/controller/StudentController.class index c7829b4..842ea6a 100644 Binary files a/Springboot/Springboot/target/classes/com/program/Springboot/controller/StudentController.class and b/Springboot/Springboot/target/classes/com/program/Springboot/controller/StudentController.class differ diff --git a/Springboot/Springboot/target/classes/com/program/Springboot/service/impl/StudentServiceImpl.class b/Springboot/Springboot/target/classes/com/program/Springboot/service/impl/StudentServiceImpl.class index d031ff7..86aac02 100644 Binary files a/Springboot/Springboot/target/classes/com/program/Springboot/service/impl/StudentServiceImpl.class and b/Springboot/Springboot/target/classes/com/program/Springboot/service/impl/StudentServiceImpl.class differ