Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sujata #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
53 changes: 53 additions & 0 deletions src/main/java/com/example/demo/Models/ResultModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.demo.Models;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "resultrecord")
public class ResultModel {

public ResultModel() {}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;

private String paperId;
private String studentName;
private String studentPrn;
private int marks;
private String examName;
public String getPaperId() {
return paperId;
}
public void setPaperId(String paperId) {
this.paperId = paperId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentPrn() {
return studentPrn;
}
public void setStudentPrn(String studentPrn) {
this.studentPrn = studentPrn;
}
public int getMarks() {
return marks;
}
public void setMarks(int marks) {
this.marks = marks;
}
public String getExamName() {
return examName;
}
public void setExamName(String examName) {
this.examName = examName;
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/example/demo/RestComponents/ResultDataRest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.demo.RestComponents;

import org.springframework.beans.factory.annotation.Autowired;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.Models.ResultModel;
import com.example.demo.Models.StudentModel;
import com.example.demo.ServicesForRest.ResultModelService;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ResultDataRest {

@Autowired
private ResultModelService resultModelService;

@PostMapping("/postresultdata")
public ResponseEntity<ResultModel> saveStudent(@RequestBody ResultModel result){
System.out.println("saveStudent url");
ResultModel savedResult = resultModelService.saveStudent(result);
return ResponseEntity.ok(savedResult);
}

@GetMapping("/getAllStudentResult")
public ResponseEntity<List<ResultModel>> getAllStudentResult(){
List<ResultModel> results = resultModelService.getAllStudents();
return ResponseEntity.ok(results);
}

@GetMapping("/getResultByPRN/{prn}")
public ResponseEntity<ResultModel> getResultByPRN(@PathVariable String prn){
ResultModel result = resultModelService.getResultByPRN(prn);
if(result == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(result);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.demo.ServicesForRest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.Models.ResultModel;
import com.example.demo.jpaRepositories.ResultModelRepository;

import java.util.List;

@Service
public class ResultModelService {

@Autowired
private ResultModelRepository resultModelRepository;

public List<ResultModel> getAllResultModels() {
return resultModelRepository.findAll();
}

public ResultModel postAllResultModels(ResultModel result) {
return resultModelRepository.save(result);
}

public ResultModel saveStudent(ResultModel student) {
return resultModelRepository.save(student);
}

public ResultModel saveResult(ResultModel result) {
return resultModelRepository.save(result);
}

public List<ResultModel> getAllStudents() {
return resultModelRepository.findAll();
}

public ResultModel getResultByPRN(String prn) {
return resultModelRepository.findByStudentPrn(prn);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.demo.jpaRepositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.demo.Models.ResultModel;

@Repository
public interface ResultModelRepository extends JpaRepository<ResultModel, Long> {

ResultModel findByStudentPrn(String prn);
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring.datasource.url=jdbc:mysql://localhost:3306/parikshaportal
spring.datasource.username=root
spring.datasource.password=8052608851
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
server.servlet.context-path=/