Commit 7bcb9a4f authored by vivaddadhi's avatar vivaddadhi

finish conversion to mysql DB

parent 4200bc4e
...@@ -23,11 +23,13 @@ ext { ...@@ -23,11 +23,13 @@ ext {
} }
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' // implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// implementation 'org.springframework.cloud:spring-cloud-starter-config' // implementation 'org.springframework.cloud:spring-cloud-starter-config'
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
} }
......
spring.data.mongodb.uri=mongodb+srv://userNisum:NisumCohort2021@cluster0.8ekps.mongodb.net/myFirstDatabase?retryWrites=true&w=majority #spring.data.mongodb.uri=mongodb+srv://userNisum:NisumCohort2021@cluster0.8ekps.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
spring.data.mongodb.database=test #spring.data.mongodb.database=test
\ No newline at end of file
server.port=9091
# JPA
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/StudentMarks
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.jpa.generate-ddl=false
#spring.datasource.schema=classpath:studentaddress.sql
\ No newline at end of file
...@@ -4,13 +4,13 @@ com/StudentServices/MarksService/exception/ErrorDetails.java ...@@ -4,13 +4,13 @@ com/StudentServices/MarksService/exception/ErrorDetails.java
com.StudentServices.MarksService.exception.ErrorDetails com.StudentServices.MarksService.exception.ErrorDetails
com/StudentServices/MarksService/MarksServiceApplication.java com/StudentServices/MarksService/MarksServiceApplication.java
com.StudentServices.MarksService.MarksServiceApplication com.StudentServices.MarksService.MarksServiceApplication
com/StudentServices/MarksService/exception/GlobalExceptionHandler.java
com.StudentServices.MarksService.exception.GlobalExceptionHandler
com/StudentServices/MarksService/model/StudentMarks.java
com.StudentServices.MarksService.model.StudentMarks
com/StudentServices/MarksService/repository/StudentRepository.java
com.StudentServices.MarksService.repository.StudentRepository
com/StudentServices/MarksService/service/StudentService.java com/StudentServices/MarksService/service/StudentService.java
com.StudentServices.MarksService.service.StudentService com.StudentServices.MarksService.service.StudentService
com/StudentServices/MarksService/model/StudentMarks.java
com.StudentServices.MarksService.model.StudentMarks
com/StudentServices/MarksService/controller/StudentMarksController.java com/StudentServices/MarksService/controller/StudentMarksController.java
com.StudentServices.MarksService.controller.StudentMarksController com.StudentServices.MarksService.controller.StudentMarksController
com/StudentServices/MarksService/repository/StudentRepository.java
com.StudentServices.MarksService.repository.StudentRepository
com/StudentServices/MarksService/exception/GlobalExceptionHandler.java
com.StudentServices.MarksService.exception.GlobalExceptionHandler
...@@ -42,19 +42,29 @@ public class StudentMarksController { ...@@ -42,19 +42,29 @@ public class StudentMarksController {
// (PUT) update studentmark by id // (PUT) update studentmark by id
@PutMapping("/studentMarks/{id}/{course}") // @PutMapping("/studentMarks/{id}/{course}")
ResponseEntity<StudentMarks> updateStudent(@PathVariable String id, @PathVariable String course, @RequestBody String grade) throws ResourceNotFoundException { // ResponseEntity<StudentMarks> updateStudent(@PathVariable String id, @PathVariable String course, @RequestBody String grade) throws ResourceNotFoundException {
StudentMarks student = studentService.getStudentById(id). // StudentMarks student = studentService.getStudentById(id).
orElseThrow( () -> new ResourceNotFoundException("Student was not found: " + id)); // orElseThrow( () -> new ResourceNotFoundException("Student was not found: " + id));
//
if (student.getMarks().get(course).length() > 0) { // if (student.getMarks().get(course).length() > 0) {
student.getMarks().put(course, grade); // student.getMarks().put(course, grade);
} else { // } else {
throw new ResourceNotFoundException("course not found"); // throw new ResourceNotFoundException("course not found");
} // }
//
studentService.updateStudent(student); // studentService.updateStudent(student);
return ResponseEntity.ok(student); // return ResponseEntity.ok(student);
// }
@PutMapping("/studentMarks/{id}")
ResponseEntity<StudentMarks> updateStudent(@PathVariable String id, @RequestBody StudentMarks studentMarks) throws ResourceNotFoundException {
StudentMarks studentMarks1 = studentService.getStudentById(id)
.orElseThrow(() -> new ResourceNotFoundException("Student was not found: " + id));
studentMarks1.setMarks(studentMarks.getMarks());
studentService.updateStudent(studentMarks1);
return ResponseEntity.ok(studentMarks1);
} }
// (DELETE) delete studentmark by id // (DELETE) delete studentmark by id
......
package com.StudentServices.MarksService.model; package com.StudentServices.MarksService.model;
import org.springframework.data.annotation.Id; import javax.persistence.Entity;
import org.springframework.data.mongodb.core.mapping.Document; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.HashMap;
@Document(collection = "StudentScemaV1")
@Entity
@Table(name = "student_marks_table")
public class StudentMarks { public class StudentMarks {
@Id @Id
private String emailAddress; private String emailAddress;
private HashMap<String, String> marks; private Float marks;
public StudentMarks() {} public StudentMarks() {}
public StudentMarks(String emailAddress, Float marks) {
public StudentMarks(String emailAddress, HashMap<String, String> marks) {
this.emailAddress = emailAddress; this.emailAddress = emailAddress;
this.marks = marks; this.marks = marks;
} }
public String getEmailAddress() { public String getEmailAddress() {
return emailAddress; return emailAddress;
} }
...@@ -30,12 +32,14 @@ public class StudentMarks { ...@@ -30,12 +32,14 @@ public class StudentMarks {
this.emailAddress = emailAddress; this.emailAddress = emailAddress;
} }
public HashMap<String, String> getMarks() { public Float getMarks() {
return marks; return marks;
} }
public void setMarks(HashMap<String, String> marks) { public void setMarks(Float marks) {
this.marks = marks; this.marks = marks;
} }
} }
package com.StudentServices.MarksService.repository; package com.StudentServices.MarksService.repository;
import com.StudentServices.MarksService.model.StudentMarks; import com.StudentServices.MarksService.model.StudentMarks;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository
public interface StudentRepository extends MongoRepository <StudentMarks, String> {
@Repository
public interface StudentRepository extends JpaRepository<StudentMarks, String> {
} }
...@@ -30,6 +30,7 @@ public class StudentService { ...@@ -30,6 +30,7 @@ public class StudentService {
public Optional<StudentMarks> getStudentById(String ID) { public Optional<StudentMarks> getStudentById(String ID) {
return studentRepository.findById(ID); return studentRepository.findById(ID);
// return studentRepository.findOne(studentMarks);
} }
......
spring.data.mongodb.uri=mongodb+srv://userNisum:NisumCohort2021@cluster0.8ekps.mongodb.net/myFirstDatabase?retryWrites=true&w=majority #spring.data.mongodb.uri=mongodb+srv://userNisum:NisumCohort2021@cluster0.8ekps.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
spring.data.mongodb.database=test #spring.data.mongodb.database=test
\ No newline at end of file
server.port=9091
# JPA
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/StudentMarks
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.jpa.generate-ddl=false
#spring.datasource.schema=classpath:studentaddress.sql
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment