PUNKT-29 dodane endpointy do obslugi rankingów
This commit is contained in:
parent
fa4d9a36fc
commit
84ac8ccc2b
|
@ -99,12 +99,12 @@ public class GroupController {
|
|||
}
|
||||
|
||||
@GetMapping("/{group_id}/content/{type}")
|
||||
public ResponseEntity<?> getContent(@PathVariable(required = true) Long group_id, @PathVariable(required = true) String type) {
|
||||
public ResponseEntity<?> getContent(@PathVariable(required = true) Integer group_id, @PathVariable(required = true) String type) {
|
||||
return this.groupService.getContent(group_id,type);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{group_id}/content/{type}/{content_id}")
|
||||
public ResponseEntity<?> deleteContent(@PathVariable(required = true) Long group_id, @PathVariable(required = true) String type, @PathVariable(required = true) Long content_id) {
|
||||
public ResponseEntity<?> deleteContent(@PathVariable(required = true) Integer group_id, @PathVariable(required = true) String type, @PathVariable(required = true) Long content_id) {
|
||||
return this.groupService.deleteContent(group_id, type, content_id);
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class GroupController {
|
|||
}
|
||||
|
||||
@GetMapping("/{groupId}/content/{type}/unverified")
|
||||
public ResponseEntity<?> getUnverifiedContent(@PathVariable(required = true) Long groupId,
|
||||
public ResponseEntity<?> getUnverifiedContent(@PathVariable(required = true) Integer groupId,
|
||||
@PathVariable(required = true) String type) {
|
||||
return this.groupService.getUnverifiedContent(groupId, type);
|
||||
}
|
||||
|
@ -186,4 +186,16 @@ public class GroupController {
|
|||
public ResponseEntity<?> getGroupTestLeaderboard(@PathVariable(required = true) Integer group_id) {
|
||||
return this.groupService.getGroupTestLeaderboard(group_id);
|
||||
}
|
||||
|
||||
@GetMapping("/{groupId}/tests")
|
||||
public ResponseEntity<?> listTestsInGroup(@PathVariable Integer groupId) {
|
||||
return groupService.getGroupTests(groupId);
|
||||
}
|
||||
|
||||
@GetMapping("/{groupId}/tests/{testId}/results")
|
||||
public ResponseEntity<?> listTestsResultsInGroup(@PathVariable Integer groupId, @PathVariable Long testId) {
|
||||
return groupService.getGroupTestsWithResults(groupId, testId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ public interface SetRepository extends JpaRepository<Set, Long> {
|
|||
|
||||
|
||||
@Query("select t from Set t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'VERIFIED' )")
|
||||
List<Set> findSetByGroup(@Param("g") Long g);
|
||||
List<Set> findSetByGroup(@Param("g") Integer g);
|
||||
|
||||
|
||||
@Query("select t from Set t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'UNVERIFIED' )")
|
||||
List<Set> findWaitingSetByGroupKey(@Param("g") Long g);
|
||||
List<Set> findWaitingSetByGroupKey(@Param("g") Integer g);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ public interface MaterialRepository extends JpaRepository<Material, Long> {
|
|||
|
||||
|
||||
@Query("select t from Material t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'VERIFIED' )")
|
||||
List<Material> findMaterialByGroup(@Param("g") Long g);
|
||||
List<Material> findMaterialByGroup(@Param("g") Integer g);
|
||||
|
||||
@Query("select t from Material t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'UNVERIFIED' )")
|
||||
List<Material> findWaitingMaterialByGroupKey(@Param("g") Long g);
|
||||
List<Material> findWaitingMaterialByGroupKey(@Param("g") Integer g);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package studycave.studycaverestservice.model.simpleTest.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -13,6 +14,7 @@ import java.sql.Date;
|
|||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SimpleTestDTO {
|
||||
private Long id;
|
||||
private String title;
|
||||
|
@ -26,4 +28,6 @@ public class SimpleTestDTO {
|
|||
private Long grade;
|
||||
private String group;
|
||||
|
||||
private int maxScore;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package studycave.studycaverestservice.model.studyGroup;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
@ -28,12 +26,15 @@ import studycave.studycaverestservice.model.flashcardset.Set;
|
|||
import studycave.studycaverestservice.model.flashcardset.SetRepository;
|
||||
import studycave.studycaverestservice.model.material.Material;
|
||||
import studycave.studycaverestservice.model.material.MaterialRepository;
|
||||
import studycave.studycaverestservice.model.simpleTest.dto.SimpleTestDTO;
|
||||
import studycave.studycaverestservice.model.studyGroup.dto.*;
|
||||
import studycave.studycaverestservice.model.studyGroupMember.StudyGroupMember;
|
||||
import studycave.studycaverestservice.model.studyGroupMember.StudyGroupMemberRepository;
|
||||
import studycave.studycaverestservice.model.test.Test;
|
||||
import studycave.studycaverestservice.model.test.TestRepository;
|
||||
import studycave.studycaverestservice.model.test.dto.TestResultResponseDTO;
|
||||
import studycave.studycaverestservice.model.test.question.*;
|
||||
import studycave.studycaverestservice.model.test.result.TestResult;
|
||||
import studycave.studycaverestservice.model.test.result.TestResultRepository;
|
||||
import studycave.studycaverestservice.model.user.User;
|
||||
import studycave.studycaverestservice.model.user.UserRepository;
|
||||
|
@ -176,6 +177,45 @@ public class GroupService {
|
|||
return new ResponseEntity<>(groupKey, HttpStatus.OK);
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getGroupTests(Integer group_id) {
|
||||
ArrayList<SimpleTestDTO> simpleTestDTOS = new ArrayList<SimpleTestDTO>();
|
||||
List<Test> tests = testRepository.findAllByGroupIdOrderByAddDateDesc(group_id);
|
||||
for (Test test : tests) {
|
||||
SimpleTestDTO simpleTestDTO = new SimpleTestDTO();
|
||||
simpleTestDTO.setId(test.getId());
|
||||
simpleTestDTO.setTitle(test.getTitle());
|
||||
int testScore = 0;
|
||||
for (Question question : test.getQuestions())
|
||||
testScore += question.getPoints();
|
||||
simpleTestDTO.setMaxScore(testScore);
|
||||
|
||||
simpleTestDTOS.add(simpleTestDTO);
|
||||
}
|
||||
return new ResponseEntity<List<SimpleTestDTO>>(simpleTestDTOS,HttpStatus.OK);
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getGroupTestsWithResults(Integer groupId, Long testId) {
|
||||
Optional<Test> test = testRepository.findByIdAndGroupId(testId, groupId);
|
||||
|
||||
if (!test.isPresent())
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
List<TestResult> testResults = testResultRepository.findAllByIdTestOrderByIdTestDesc(testId);
|
||||
|
||||
List<TestResultResponseDTO> testResultResponseDTOS = new ArrayList<>();
|
||||
|
||||
for (TestResult testResult : testResults) {
|
||||
Optional<User> userCheck = userRepository.findById(testResult.getIdOwner());
|
||||
if (userCheck.isPresent()) {
|
||||
User user = userCheck.get();
|
||||
testResultResponseDTOS.add(new TestResultResponseDTO(user.getName(), user.getSurname(), testResult.getUserScore(), (testResult.getUserScore()/testResult.getMaxScore()) * 100));
|
||||
}
|
||||
}
|
||||
Collections.sort(testResultResponseDTOS,
|
||||
Comparator.comparing(TestResultResponseDTO::getName));
|
||||
return new ResponseEntity<List<TestResultResponseDTO>>(testResultResponseDTOS,HttpStatus.OK);
|
||||
}
|
||||
|
||||
public List<SimpleStudyGroupMemberDTO> getMyGroups(Long id) {
|
||||
// User user = new User();
|
||||
// user = this.userRepository.findByUsername(username).orElse(null);
|
||||
|
@ -339,7 +379,7 @@ public class GroupService {
|
|||
}
|
||||
|
||||
|
||||
public ResponseEntity<?> getContent(Long group_id, String type) {
|
||||
public ResponseEntity<?> getContent(Integer group_id, String type) {
|
||||
List<ContentDto> contents = new ArrayList<>();
|
||||
|
||||
switch (type){
|
||||
|
@ -391,7 +431,7 @@ public class GroupService {
|
|||
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getUnverifiedContent(Long group_id, String type){
|
||||
public ResponseEntity<?> getUnverifiedContent(Integer group_id, String type){
|
||||
List<ContentDto> contents = new ArrayList<>();
|
||||
|
||||
switch (type){
|
||||
|
@ -598,7 +638,7 @@ public class GroupService {
|
|||
return new ResponseEntity<>("Usunięto komentarz", HttpStatus.OK);
|
||||
}
|
||||
|
||||
public ResponseEntity<?> deleteContent(Long group_id, String type, Long content_id){
|
||||
public ResponseEntity<?> deleteContent(Integer group_id, String type, Long content_id){
|
||||
switch (type) {
|
||||
case "tests":
|
||||
Test test = this.testRepository.findById(content_id).orElse(null);
|
||||
|
|
|
@ -5,15 +5,21 @@ import org.springframework.data.jpa.repository.Query;
|
|||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TestRepository extends JpaRepository<Test, Long> {
|
||||
|
||||
Optional<Test> findByIdAndGroupId(Long testId, Integer groupId);
|
||||
|
||||
@Query("select t from Test t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'VERIFIED' )")
|
||||
List<Test> findTestByGroup(@Param("g") Long g);
|
||||
List<Test> findTestByGroup(@Param("g") Integer g);
|
||||
|
||||
|
||||
|
||||
@Query("select t from Test t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'UNVERIFIED' )")
|
||||
List<Test> findWaitingTestByGroupKey(@Param("g") Long g);
|
||||
List<Test> findWaitingTestByGroupKey(@Param("g") Integer g);
|
||||
|
||||
|
||||
List<Test> findAllByGroupIdOrderByAddDateDesc(Integer id);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package studycave.studycaverestservice.model.test.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TestResultResponseDTO {
|
||||
|
||||
@Getter
|
||||
private String name;
|
||||
|
||||
@Getter
|
||||
private String surname;
|
||||
|
||||
@Getter
|
||||
private float userScore;
|
||||
|
||||
private float percent;
|
||||
|
||||
public float getPercent(){
|
||||
DecimalFormat df = new DecimalFormat();
|
||||
df.setMaximumFractionDigits(2);
|
||||
return Float.parseFloat(df.format(this.percent));
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ import java.util.List;
|
|||
|
||||
public interface TestResultRepository extends JpaRepository<TestResult,Long> {
|
||||
|
||||
List<TestResult> findAllByIdTestOrderByIdTestDesc(Long testId);
|
||||
|
||||
List<TestResult> findByIdOwner(Long id);
|
||||
|
||||
List<TestResult> findByIdOwnerAndIdTest(Long id, Long id2);
|
||||
|
|
Loading…
Reference in New Issue