Skip to content

Commit

Permalink
Merge pull request #109 from correctexam/develop
Browse files Browse the repository at this point in the history
close #432
  • Loading branch information
barais authored Dec 13, 2023
2 parents 9252863 + fa82c00 commit b5f9d84
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/main/java/fr/istic/domain/Answer2HybridGradedComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ public static PanacheQuery<Answer2HybridGradedComment> findAllWithResponseIdAndH
public static PanacheQuery<Answer2HybridGradedComment> findAllAnswerHybridGradedCommentByAnswerId(long responseId){
return find("select c from Answer2HybridGradedComment c where c.studentResponse.id =?1", responseId);
}
public static PanacheQuery<Answer2HybridGradedComment> findAllAnswerHybridGradedCommentByCommentId(long hybridCommentId){
return find("select c from Answer2HybridGradedComment c join fetch c.studentResponse st join fetch st.hybridcommentsValues ah2 join fetch ah2.hybridcomments as h2 where c.hybridcomments.id =?1", hybridCommentId);
public static PanacheQuery<Answer2HybridGradedComment> findAllAnswerHybridGradedCommentByCommentIdWithStepvalueUpperThan0(long hybridcommentId){
return find("select c from Answer2HybridGradedComment c where c.hybridcomments.id =?1 and c.stepValue >0", hybridcommentId);
}

public static PanacheQuery<Answer2HybridGradedComment> findAllAnswerHybridGradedCommentByCommentId(long hybridcommentId){
return find("select c from Answer2HybridGradedComment c where c.hybridcomments.id =?1", hybridcommentId);
}

public static PanacheQuery<Answer2HybridGradedComment> findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0(long hybridCommentId){
return find("select c from Answer2HybridGradedComment c join fetch c.studentResponse st join fetch st.hybridcommentsValues ah2 join fetch ah2.hybridcomments as h2 where c.hybridcomments.id =?1 and c.stepValue >0", hybridCommentId);
}

public static PanacheQuery<Answer2HybridGradedComment> canAccess(long commentId, String login) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public HybridGradedCommentDTO persistOrUpdate(HybridGradedCommentDTO hybridGrade
}
hybridGradedComment = HybridGradedComment.persistOrUpdate(hybridGradedComment);
if (shouldUpdate){
List<Answer2HybridGradedComment> ans = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentId(hybridGradedComment.id).list().stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList());
List<Answer2HybridGradedComment> ans = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0(hybridGradedComment.id).list(); //.stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList());
for( Answer2HybridGradedComment an : ans){
var st = an.studentResponse;
var ans2 = an.studentResponse.hybridcommentsValues;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/fr/istic/web/rest/GradedCommentResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.istic.domain.Authority;
import fr.istic.domain.GradedComment;
import fr.istic.domain.Question;
import fr.istic.domain.StudentResponse;
import fr.istic.domain.User;
import fr.istic.security.AuthoritiesConstants;
import fr.istic.service.GradedCommentService;
Expand Down Expand Up @@ -185,4 +186,17 @@ public Response getGradedComment(@PathParam("id") Long id, @Context SecurityCont
Optional<GradedCommentDTO> gradedCommentDTO = gradedCommentService.findOne(id);
return ResponseUtil.wrapOrNotFound(gradedCommentDTO);
}

@GET
@Path("/countHowManyUse/{id}")
@RolesAllowed({AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN})
public Response getUsedOfGradedComment(@PathParam("id") Long id, @Context SecurityContext ctx) {
log.debug("REST request to get GradedComment : {}", id);
if (!securityService.canAccess(ctx, id, GradedComment.class )){
return Response.status(403, "Current user cannot access to this ressource").build();
}
long l = StudentResponse.findAllByGradedCommentsIds(id).count();
return Response.ok(Long.valueOf(l)).build();
}

}
15 changes: 15 additions & 0 deletions src/main/java/fr/istic/web/rest/HybridGradedCommentResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import static javax.ws.rs.core.UriBuilder.fromPath;

import fr.istic.domain.Answer2HybridGradedComment;
import fr.istic.domain.Authority;
import fr.istic.domain.GradedComment;
import fr.istic.domain.HybridGradedComment;
import fr.istic.domain.Question;
import fr.istic.domain.StudentResponse;
import fr.istic.domain.TextComment;
import fr.istic.domain.User;
import fr.istic.security.AuthoritiesConstants;
import fr.istic.service.HybridGradedCommentService;
Expand Down Expand Up @@ -188,4 +191,16 @@ public Response getHybridGradedComment(@PathParam("id") Long id) {
Optional<HybridGradedCommentDTO> hybridGradedCommentDTO = hybridGradedCommentService.findOne(id);
return ResponseUtil.wrapOrNotFound(hybridGradedCommentDTO);
}

@GET
@Path("/countHowManyUse/{id}")
@RolesAllowed({AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN})
public Response getUsedOfGradedComment(@PathParam("id") Long id, @Context SecurityContext ctx) {
log.debug("REST request to get count HybridGradedCommentUse : {}", id);
if (!securityService.canAccess(ctx, id, HybridGradedComment.class )){
return Response.status(403, "Current user cannot access to this ressource").build();
}
long l = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentIdWithStepvalueUpperThan0(id).count();
return Response.ok(Long.valueOf(l)).build();
}
}
16 changes: 16 additions & 0 deletions src/main/java/fr/istic/web/rest/TextCommentResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.slf4j.LoggerFactory;

import fr.istic.domain.Authority;
import fr.istic.domain.GradedComment;
import fr.istic.domain.StudentResponse;
import fr.istic.domain.TextComment;
import fr.istic.domain.User;
import fr.istic.security.AuthoritiesConstants;
Expand Down Expand Up @@ -181,4 +183,18 @@ public Response getTextComment(@PathParam("id") Long id, @Context SecurityContex
Optional<TextCommentDTO> textCommentDTO = textCommentService.findOne(id);
return ResponseUtil.wrapOrNotFound(textCommentDTO);
}


@GET
@Path("/countHowManyUse/{id}")
@RolesAllowed({AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN})
public Response getUsedOfGradedComment(@PathParam("id") Long id, @Context SecurityContext ctx) {
log.debug("REST request to get count textcommentUse : {}", id);
if (!securityService.canAccess(ctx, id, TextComment.class )){
return Response.status(403, "Current user cannot access to this ressource").build();
}
long l = StudentResponse.findAllByTextCommentsIds(id).count();
return Response.ok(Long.valueOf(l)).build();
}

}

0 comments on commit b5f9d84

Please sign in to comment.