dodane poprawne wyswietlanie wyników u studenta
This commit is contained in:
parent
35eb2591ff
commit
812a74447d
|
@ -26,6 +26,7 @@ import studycave.studycaverestservice.model.studyGroup.CreateGroupDto;
|
|||
import studycave.studycaverestservice.model.studyGroup.GroupService;
|
||||
import studycave.studycaverestservice.model.studyGroup.dto.*;
|
||||
import studycave.studycaverestservice.model.studyGroupMember.StudyGroupMemberRepository;
|
||||
import studycave.studycaverestservice.model.user.User;
|
||||
import studycave.studycaverestservice.model.user.UserRepository;
|
||||
|
||||
@RestController
|
||||
|
@ -100,7 +101,10 @@ public class GroupController {
|
|||
|
||||
@GetMapping("/{group_id}/content/{type}")
|
||||
public ResponseEntity<?> getContent(@PathVariable(required = true) Integer group_id, @PathVariable(required = true) String type) {
|
||||
return this.groupService.getContent(group_id,type);
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String currentPrincipalName = authentication.getName();
|
||||
Optional<User> user = userRepository.findByUsername(currentPrincipalName);
|
||||
return this.groupService.getContent(group_id,type, user.get());
|
||||
}
|
||||
|
||||
@DeleteMapping("/{group_id}/content/{type}/{content_id}")
|
||||
|
|
|
@ -291,11 +291,24 @@ public class TestController {
|
|||
|
||||
ArrayList<SimpleTestDTO> testDTOs = new ArrayList<SimpleTestDTO>();
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String currentPrincipalName = authentication.getName();
|
||||
Optional<User> userCheck = userRepository.findByUsername(currentPrincipalName);
|
||||
User usersTests = null;
|
||||
if (userCheck.isPresent())
|
||||
usersTests = userCheck.get();
|
||||
|
||||
List<SimpleTest> tests = simpleTestRepository.findByGroupIdNullAndOptionalPermissionAndOptionalOwner(permission, ownerId);
|
||||
for (SimpleTest test : tests) {
|
||||
String username = userRepository.findById((long) test.getIdOwner()).get().getUsername();
|
||||
SimpleTestDTO testDTO = modelMapper.map(test, SimpleTestDTO.class);
|
||||
testDTO.setOwner(username);
|
||||
if (usersTests != null){
|
||||
List<TestResult> testResults = testResultRepository.findByIdOwnerAndIdTest(usersTests.getId(), test.getId());
|
||||
testDTO.setGrade(testResults.get(testResults.size() - 1).getUserScore());
|
||||
testDTO.setMaxScore(testResults.get(testResults.size() - 1).getMaxScore());
|
||||
}
|
||||
|
||||
if(test.getGroupId() != null)
|
||||
testDTO.setGroup(groupRepository.findById(test.getGroupId()).orElse(null).getName());
|
||||
testDTOs.add(testDTO);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class SimpleTestDTO {
|
|||
private Date editDate;
|
||||
@ApiModelProperty(value = "Default value for note", required = true,example = "public")
|
||||
private String permission;
|
||||
private Long grade;
|
||||
private Float grade;
|
||||
private String group;
|
||||
|
||||
private int maxScore;
|
||||
|
|
|
@ -415,7 +415,7 @@ public class GroupService {
|
|||
}
|
||||
|
||||
|
||||
public ResponseEntity<?> getContent(Integer group_id, String type) {
|
||||
public ResponseEntity<?> getContent(Integer group_id, String type, User user) {
|
||||
List<ContentDto> contents = new ArrayList<>();
|
||||
|
||||
switch (type){
|
||||
|
@ -426,9 +426,23 @@ public class GroupService {
|
|||
ContentDto contentTest = new ContentDto();
|
||||
contentTest.setId(t.getId());
|
||||
contentTest.setOwner((userRepository.findById(t.getIdOwner()).orElse(null)).getUsername());
|
||||
long grade = 0;
|
||||
if (user != null){
|
||||
for (UserActivity userActivity : t.getActivity()){
|
||||
if (userActivity.getToUser() != null && userActivity.getToUser().equals(user)){
|
||||
grade = userActivity.getPoints();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
contentTest.setAddDate();
|
||||
contentTest.setGrade((long) 0);
|
||||
contentTest.setGrade(grade);
|
||||
contentTest.setTitle(t.getTitle());
|
||||
long maxScore = 0;
|
||||
for (Question question : t.getQuestions()){
|
||||
maxScore += question.getPoints();
|
||||
}
|
||||
contentTest.setMaxScore(maxScore);
|
||||
contents.add(contentTest);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ public class ContentDto {
|
|||
private Date addDate;
|
||||
private String owner;
|
||||
private Long grade;
|
||||
private Long maxScore;
|
||||
|
||||
public void setAddDate() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue