Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #197 from WisdomWorks/dev-herry-ho
Browse files Browse the repository at this point in the history
Dev herry ho
  • Loading branch information
HoXuanHieu authored Apr 7, 2024
2 parents e1edd2b + a9f861f commit aec5495
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.codeE.controller.Common;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/ping")
public class PingController {
@GetMapping
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<?> pingAPI(){
return ResponseEntity.status(HttpStatus.OK).body(Map.of("message", "Ping to api successful"));
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/example/codeE/controller/ReportController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.codeE.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reports")
@Validated
public class ReportController {
@GetMapping
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<?> getOverviewScoreExerciseReport(@PathVariable String exerciseId){
return ResponseEntity.status(HttpStatus.OK).body("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface CourseStudentRepository extends JpaRepository<CourseStudent, String> {

String deleteByStudentIdAndCourseIdSql = "DELETE FROM course_student cs WHERE cs.student_id = ?1 AND cs.course_id = ?2";
@Modifying
@Transactional
@Query(value = deleteByStudentIdAndCourseIdSql, nativeQuery = true)
void deleteByStudentIdAndCourseId(String studentId, String courseId);

String checkExistingStudentIdAndCourseIdSql = "SELECT COUNT(*) FROM course_student cs WHERE cs.student_id = ?1 AND cs.course_id = ?2";
String deleteAllStudentsByCourseIdSql = "DELETE FROM course_student cs WHERE cs.course_id = ?1";
String getAllStudentsInCourseSql = "SELECT * FROM course_student cs WHERE cs.course_id = ?1";

@Query(value = getAllStudentsInCourseSql, nativeQuery = true)
List<CourseStudent> getAllStudentsInCourse(String courseId);
@Query(value = checkExistingStudentIdAndCourseIdSql, nativeQuery = true)
Long existsByStudentIdAndCourseId(String studentId, String courseId);

String deleteAllStudentsByCourseIdSql = "DELETE FROM course_student cs WHERE cs.course_id = ?1";
@Modifying
@Transactional
@Query(value = deleteAllStudentsByCourseIdSql, nativeQuery = true)
void deleteAllStudentsByCourseId(String courseId);

@Modifying
@Transactional
@Query(value = deleteByStudentIdAndCourseIdSql, nativeQuery = true)
void deleteByStudentIdAndCourseId(String studentId, String courseId);
//new u.user_id, u.username, u.name, u.email, u.password, u.role, u.created_date, u.updated_date
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.codeE.request.report;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class OverviewScoreReport {
private int AScore;
private int BScore;
private int CScore;
private int numberSubmission;
private int numberStudent;
}
19 changes: 15 additions & 4 deletions src/main/java/com/example/codeE/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
Expand All @@ -28,6 +29,8 @@
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {
@Autowired
private Environment environment;
@Autowired
private UserImpl userService;
@Autowired
Expand All @@ -39,17 +42,24 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(request -> request
.requestMatchers("/auth/**", "/public/**").permitAll()
.requestMatchers("/ping").permitAll()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**",
"/swagger-resources/**", "/webjars/**")
.permitAll()
.requestMatchers("/users/**").hasAnyAuthority( "teacher","admin")
// .requestMatchers("/users/**").permitAll()
.requestMatchers("/topics/**").hasAnyAuthority("student", "teacher")
.requestMatchers("/exercises/**").hasAnyAuthority("student", "teacher")
.requestMatchers("/materials/**").hasAnyAuthority("student", "teacher")
// .requestMatchers("/courses/**").hasAnyAuthority("teacher", "admin", "student")
.requestMatchers("/courses/**").permitAll()
.requestMatchers("/courses/**").hasAnyAuthority("teacher", "admin", "student")
.requestMatchers("/groups/**").hasAnyAuthority("teacher")
.requestMatchers("/reports/**").hasAnyAuthority("teacher")
// .requestMatchers("/courses/**").permitAll()
// .requestMatchers("/users/**").permitAll()
// .requestMatchers("/topics/**").permitAll()
// .requestMatchers("/exercises/**").permitAll()
// .requestMatchers("/materials/**").permitAll()
// .requestMatchers("/groups/**").permitAll()
// .requestMatchers("/reports/**").permitAll()
.anyRequest().authenticated())
.sessionManagement(manager -> manager.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider()).addFilterBefore(
Expand All @@ -68,10 +78,11 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();

config.setAllowCredentials(true);
config.addAllowedOrigin("http://localhost:4000");
config.addAllowedOrigin("http://localhost:4001");
// config.addAllowedOrigin(environment.getProperty("url.admin.ui"));
// config.addAllowedOrigin(environment.getProperty("url.user.ui"));
config.addAllowedHeader("*");
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/example/codeE/service/report/ReportImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.example.codeE.service.report;

import com.example.codeE.model.exercise.Exercise;
import com.example.codeE.repository.*;
import com.example.codeE.request.exercise.essay.EssaySubmissionsResponse;
import com.example.codeE.request.report.OverviewScoreReport;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.NoSuchElementException;

public class ReportImpl implements ReportService{
@Autowired
private ExerciseRepository exerciseRepository;
@Autowired
private TopicRepository topicRepository;
@Autowired
private CourseStudentRepository courseStudentRepository;
@Autowired
private QuizSubmissionRepository quizSubmissionRepository;
@Autowired
private EssaySubmissionRepository essaySubmissionRepository;
@Autowired
private CodeSubmissionRepository codeSubmissionRepository;
@Autowired


@Override
public OverviewScoreReport getOverviewScoreReportByExerciseId(String exerciseId) {
OverviewScoreReport result = new OverviewScoreReport();
var exercise = this.exerciseRepository.findById(exerciseId).orElseThrow(() -> new NoSuchElementException("No exercise found by id: " +exerciseId));
if(exercise.isShowAll()){
String courseId = this.topicRepository.findById(exercise.getTopicId()).orElseThrow(() -> new NoSuchElementException("No topic found by id: " +exercise.getTopicId())).getCourseId();
var courseStudents = this.courseStudentRepository.getAllStudentsInCourse(courseId);
result.setNumberStudent(courseStudents.size());

}else {

}
return result;
}
private OverviewScoreReport getAllSubmission(Exercise exercise){
OverviewScoreReport result = new OverviewScoreReport();
switch (exercise.getType()){
case "code" ->{}
case "file" ->{}
case "quiz" ->{}
case "essay" -> {
var essays = this.essaySubmissionRepository.findAll();

}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.codeE.service.report;

import com.example.codeE.request.report.OverviewScoreReport;

public interface ReportService {
OverviewScoreReport getOverviewScoreReportByExerciseId(String exerciseId);
}

0 comments on commit aec5495

Please sign in to comment.