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
19 changes: 19 additions & 0 deletions src/main/java/com/app/backend/controller/StudentApiController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.app.backend.controller;

import com.app.backend.model.StudentModel;
import com.app.backend.service.impl.StudentServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/")
public interface StudentApiController {
@GetMapping("/students")
public List<StudentModel> getAllStudents();
@PostMapping("/newStudent")
public StudentModel createStudent(@RequestBody StudentModel newStudent);
@GetMapping("/students/{id}")
public StudentModel getStudentById(@PathVariable int id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.app.backend.controller.impl;

import com.app.backend.controller.StudentApiController;
import com.app.backend.model.StudentModel;
import com.app.backend.service.StudentService;
import com.app.backend.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class StudentApiControllerImpl implements StudentApiController {

@Autowired
StudentService studentService;
@Override
public List<StudentModel> getAllStudents(){
return studentService.getStudentsList();
}
@Override
public StudentModel createStudent(@RequestBody StudentModel newStudent){
return studentService.createStudent(newStudent);
}

@Override
public StudentModel getStudentById(@PathVariable int id){
return studentService.getStudentById(id);
}
}
65 changes: 65 additions & 0 deletions src/main/java/com/app/backend/model/StudentModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.app.backend.model;

import java.util.Date;

public class StudentModel {
public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

private String firstName;

public String getPatLastName() {
return patLastName;
}

public void setPatLastName(String patLastName) {
this.patLastName = patLastName;
}

private String patLastName;

public String getMatLastName() {
return matLastName;
}

public void setMatLastName(String matLastName) {
this.matLastName = matLastName;
}

private String matLastName;

public Date getDateOfBirth() {
return dateOfBirth;
}

public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}

private Date dateOfBirth;

private String email;

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

private String phone;

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/app/backend/service/StudentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.app.backend.service;

import com.app.backend.model.StudentModel;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public interface StudentService {

List<StudentModel> students = new ArrayList<>();

public List<StudentModel> getStudentsList();
public StudentModel createStudent(StudentModel newStudent);
public StudentModel getStudentById(int id);
}
21 changes: 21 additions & 0 deletions src/main/java/com/app/backend/service/impl/StudentServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.app.backend.service.impl;

import com.app.backend.model.StudentModel;
import com.app.backend.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
public List<StudentModel> getStudentsList() {
return this.students;
}
public StudentModel createStudent(StudentModel newStudent){
this.students.add(newStudent);
return newStudent;
}
public StudentModel getStudentById(int id){
return this.students.get(id);
}
}