Commit 7bcb9a4f authored by vivaddadhi's avatar vivaddadhi

finish conversion to mysql DB

parent 4200bc4e
......@@ -23,11 +23,13 @@ ext {
}
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-data-jpa'
// implementation 'org.springframework.cloud:spring-cloud-starter-config'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
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.database=test
\ No newline at end of file
#spring.data.mongodb.uri=mongodb+srv://userNisum:NisumCohort2021@cluster0.8ekps.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
#spring.data.mongodb.database=test
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
com.StudentServices.MarksService.exception.ErrorDetails
com/StudentServices/MarksService/MarksServiceApplication.java
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
com/StudentServices/MarksService/model/StudentMarks.java
com.StudentServices.MarksService.model.StudentMarks
com/StudentServices/MarksService/controller/StudentMarksController.java
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 {
// (PUT) update studentmark by id
@PutMapping("/studentMarks/{id}/{course}")
ResponseEntity<StudentMarks> updateStudent(@PathVariable String id, @PathVariable String course, @RequestBody String grade) throws ResourceNotFoundException {
StudentMarks student = studentService.getStudentById(id).
orElseThrow( () -> new ResourceNotFoundException("Student was not found: " + id));
if (student.getMarks().get(course).length() > 0) {
student.getMarks().put(course, grade);
} else {
throw new ResourceNotFoundException("course not found");
}
studentService.updateStudent(student);
return ResponseEntity.ok(student);
// @PutMapping("/studentMarks/{id}/{course}")
// ResponseEntity<StudentMarks> updateStudent(@PathVariable String id, @PathVariable String course, @RequestBody String grade) throws ResourceNotFoundException {
// StudentMarks student = studentService.getStudentById(id).
// orElseThrow( () -> new ResourceNotFoundException("Student was not found: " + id));
//
// if (student.getMarks().get(course).length() > 0) {
// student.getMarks().put(course, grade);
// } else {
// throw new ResourceNotFoundException("course not found");
// }
//
// studentService.updateStudent(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
......
package com.StudentServices.MarksService.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.Entity;
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 {
@Id
private String emailAddress;
private HashMap<String, String> marks;
private Float marks;
public StudentMarks() {}
public StudentMarks(String emailAddress, HashMap<String, String> marks) {
public StudentMarks(String emailAddress, Float marks) {
this.emailAddress = emailAddress;
this.marks = marks;
}
public String getEmailAddress() {
return emailAddress;
}
......@@ -30,12 +32,14 @@ public class StudentMarks {
this.emailAddress = emailAddress;
}
public HashMap<String, String> getMarks() {
public Float getMarks() {
return marks;
}
public void setMarks(HashMap<String, String> marks) {
public void setMarks(Float marks) {
this.marks = marks;
}
}
package com.StudentServices.MarksService.repository;
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;
@Repository
public interface StudentRepository extends MongoRepository <StudentMarks, String> {
@Repository
public interface StudentRepository extends JpaRepository<StudentMarks, String> {
}
......@@ -30,6 +30,7 @@ public class StudentService {
public Optional<StudentMarks> getStudentById(String 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.database=test
\ No newline at end of file
#spring.data.mongodb.uri=mongodb+srv://userNisum:NisumCohort2021@cluster0.8ekps.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
#spring.data.mongodb.database=test
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