Commit 7f2b5b6b authored by it20118068's avatar it20118068

Update Backend

parent 3d73a085
......@@ -17,6 +17,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -51,65 +52,44 @@ public class ShrasthraBackendController {
responseDto = backendService.audioToSign(file);
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.VIDEO_TO_SIGN, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto videoToSign(@RequestParam("file") MultipartFile file, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.videoToSign(file);
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.VOCAL_TRAINING, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto vocalTraining(@RequestParam("file") MultipartFile file, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.vocalTraining(file);
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.GET_ALL_LESSONS, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto getAllLessonsById(@RequestBody ProcessRequestDto processRequestDto, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.getAllLessonsById(processRequestDto);
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.START_QUIZ, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto startQuiz(@RequestBody ProcessRequestDto processRequestDto, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.startQuiz(processRequestDto);
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.GET_QUIZ, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto getQuizByUID(@RequestBody ProcessRequestDto processRequestDto, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.getQuizByUID(processRequestDto);
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.GET_URL, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto getSignURL(@RequestBody ProcessRequestDto processRequestDto, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.getSignURL(processRequestDto);
return responseDto;
}
// @RequestMapping(value = REST_CONTROLLER_URL.DETECT_DYNAMIC_SIGN, method = RequestMethod.POST)
// public @ResponseBody ProcessResponseDto saveQuotation(@RequestParam("file") MultipartFile file, HttpServletRequest request){
// ProcessResponseDto responseDto = new ProcessResponseDto();
//
// // Check if the file is not empty and process it
// if (!file.isEmpty()) {
// try {
// // Convert the file to bytes
// byte[] fileBytes = file.getBytes();
//
//
// RestTemplate restTemplate = new RestTemplate();
//
// // Set the URL of your Python Flask API
// String url = "http://127.0.0.1:5000/api/data";
//
// // Create headers and set content type as multipart/form-data
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
//
// // Create the request body with the file as a part
// MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
// requestBody.add("fileData", new ByteArrayResource(fileBytes) {
// @Override
// public String getFilename() {
// return file.getOriginalFilename();
// }
// });
//
// // Create the request entity with headers and body
// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
//
// // Make the POST request to the second API
// ResponseEntity<ProcessResponseDto> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, ProcessResponseDto.class);
//
// // Retrieve the response body
// ProcessResponseDto responseBody = response.getBody();
//
// // Print the response
// System.out.println(responseBody.getSign());
//
//
// } catch (Exception e) {
//// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to process the video file.");
// }
// } else {
//// return ResponseEntity.badRequest().body("No video file provided.");
// }
//
// return responseDto;
// }
}
package shrasthra.backend.dao.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import static javax.persistence.GenerationType.IDENTITY;
@Entity
@Table(name = "lessons", catalog = "shrasthra" )
public class Lessons {
private Integer id;
private Integer lesson_id;
private String content;
private String img_url;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "lesson_id")
public Integer getLesson_id() {
return lesson_id;
}
public void setLesson_id(Integer lesson_id) {
this.lesson_id = lesson_id;
}
@Column(name = "content")
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Column(name = "image_url")
public String getImg_url() {
return img_url;
}
public void setImg_url(String img_url) {
this.img_url = img_url;
}
}
package shrasthra.backend.dao.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import static javax.persistence.GenerationType.IDENTITY;
@Entity
@Table(name = "quiz", catalog = "shrasthra")
public class Quiz {
private Integer id;
private Integer paper_i;
private Integer userid;
private Integer qid;
private Boolean isCorrect;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPaper_i() {
return paper_i;
}
public void setPaper_i(Integer paper_i) {
this.paper_i = paper_i;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public Integer getQid() {
return qid;
}
public void setQid(Integer qid) {
this.qid = qid;
}
public Boolean getIsCorrect() {
return isCorrect;
}
public void setIsCorrect(Boolean isCorrect) {
this.isCorrect = isCorrect;
}
}
package shrasthra.backend.dao.dto;
import lombok.Data;
@Data
public class LessonsDto {
private Integer id;
private Integer lesson_id;
private String content;
private String img_url;
}
package shrasthra.backend.dao.dto;
import lombok.Data;
import shrasthra.backend.dao.domain.McqWord;
@Data
public class McqWordDto {
// private Integer id;
// private String label;
// private String value;
// private String opt1;
// private String opt2;
// private String opt3;
// private String opt4;
private McqWord word;
private boolean isCorrect;
}
......@@ -5,4 +5,7 @@ import lombok.Data;
@Data
public class ProcessRequestDto {
private byte[] video;
private Integer userID;
private Integer lessonId;
private String value;
}
package shrasthra.backend.dao.dto;
import java.util.List;
import lombok.Data;
import shrasthra.backend.dao.domain.Lessons;
import shrasthra.backend.dao.domain.SignMap;
@Data
......@@ -9,4 +12,11 @@ public class ProcessResponseDto {
private String message;
private String sign;
private SignMap signMap;
private boolean isValid;
private List<Lessons> lessons;
private List<QuizDto> quizDtoList;
private List<McqWordDto> mcqWordDtolist;
private String value;
private String url;
}
package shrasthra.backend.dao.dto;
import lombok.Data;
import shrasthra.backend.dao.domain.McqWord;
@Data
public class QuizDto {
private Integer id;
private Integer paper_i;
private Integer userid;
private Integer qid;
private Boolean isCorrect;
private McqWord mcqWord;
}
package shrasthra.backend.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import shrasthra.backend.dao.domain.Lessons;
public interface LessonsRepository extends JpaRepository<Lessons, Integer>{
@Query("SELECT l FROM Lessons l WHERE l.lesson_id=:lesson_id")
public List<Lessons> findLessonsByLessonId(@Param("lesson_id") Integer lesson_id);
}
package shrasthra.backend.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import shrasthra.backend.dao.domain.McqWord;
public interface McqWordRepository extends JpaRepository<McqWord, Integer>{
@Query(value ="SELECT * FROM shrasthra.mcq_words ORDER BY RAND() LIMIT 2",nativeQuery = true)
public List<McqWord> generateQuiz();
}
package shrasthra.backend.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import shrasthra.backend.dao.domain.Quiz;
public interface QuizRepository extends JpaRepository<Quiz, Integer>{
@Query("SELECT q FROM Quiz q WHERE q.userid=:uid")
public List<Quiz> findQuizesByUid(@Param("uid") Integer uid);
}
......@@ -10,4 +10,7 @@ public interface SignMapRepository extends JpaRepository<SignMap, Integer>{
@Query("SELECT s FROM SignMap s WHERE s.label=:label")
public SignMap findSignMapByLabel(@Param("label") String label);
@Query("SELECT s FROM SignMap s WHERE s.value=:value")
public SignMap findSignMapByValue(@Param("value") String value);
}
......@@ -8,7 +8,14 @@ import shrasthra.backend.dao.dto.ProcessResponseDto;
public interface ShrasthraBackendService {
public ProcessResponseDto detectDynamicSign(MultipartFile file);
public ProcessResponseDto audioToSign(MultipartFile file);
public ProcessResponseDto videoToSign(MultipartFile file);
public ProcessResponseDto vocalTraining(MultipartFile file);
public ProcessResponseDto getAllLessonsById(ProcessRequestDto processRequestDto);
public ProcessResponseDto startQuiz(ProcessRequestDto processRequestDto);
public ProcessResponseDto getQuizByUID(ProcessRequestDto processRequestDto);
public ProcessResponseDto getSignMapByValue(ProcessRequestDto processRequestDto);
public ProcessResponseDto getSignURL(ProcessRequestDto processRequestDto);
}
......@@ -4,9 +4,13 @@ public class REST_CONTROLLER_URL {
public static final String USER_REGISTRATION = "/user/userRegistration";
public static final String DETECT_DYNAMIC_SIGN = "/sign/detectDynamicSign";
public static final String AUDIO_TO_SIGN = "/sign/audioToSign";
public static final String VIDEO_TO_SIGN = "/sign/videoToSign";
public static final String VOCAL_TRAINING = "/sign/vocalTraining";
public static final String GET_ALL_LESSONS = "/lessons/getAllLessons";
public static final String START_QUIZ = "/quiz/startQuiz";
public static final String GET_QUIZ = "/quiz/getQuiz";
public static final String GET_URL = "/sign/getURL";
}
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