This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 150e7cf1 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Merge branch 'feature_remove_badge' into 'development'

added functionality to remove badge

See merge request sharing/codeability-sharing-platform!201
parents 518fd927 8633583c
Branches
1 merge request!201added functionality to remove badge
......@@ -117,15 +117,14 @@ public class ReviewService {
}
Review review = reviewO.get();
review
.getComments()
.stream()
.forEach(reviewRating -> {
reviewRating.setStatus(status);
addHistoryEntry(review, reviewRating, userService.getUserWithAuthorities(), status, "");
List<ReviewRating> reviewRatings = review.getComments().stream().collect(Collectors.toList());
reviewRatingRepository.save(reviewRating);
});
for (ReviewRating reviewRating : reviewRatings) {
reviewRating.setStatus(status);
addHistoryEntry(review, reviewRating, userService.getUserWithAuthorities(), status, "");
reviewRatingRepository.save(reviewRating);
}
}
public void updateReview(ReviewDTO review) {
......@@ -413,6 +412,24 @@ public class ReviewService {
);
}
public void removeBadge(Long id) {
Review review = reviewRepository.findById(id).orElseThrow();
updateStatus(review.getId(), ReviewStatus.REVIEW_IN_PROGRESS);
statisticsService.removeBadgeForStatisticsByExerciseID(review.getResourceID());
notifyReviewers(
review.getId(),
EMAIL_START +
review.getResource() +
" has been removed from the badge list and is no longer displayed when people search for it."
);
notifyRequester(
review.getId(),
EMAIL_START +
review.getResource() +
" has been removed from the badge list and is no longer displayed when people search for it."
);
}
public boolean requestReviewForExercise(ReviewRequest request) {
String id = request.getResource();
if (reviewRepository.findOneByResource(id).isPresent()) {
......
......@@ -84,6 +84,24 @@ public class StatisticsService {
}
}
public void removeBadgeForStatisticsByExerciseID(String exerciseID) {
Optional<Statistics> statistics = statisticsRepository.findByExerciseID(exerciseID);
if (statistics.isPresent()) {
Statistics statistics1 = statistics.get();
statistics1.setBadgeRewarded(false);
statisticsRepository.save(statistics1);
log.debug("Badge removed for exercise: {}", exerciseID);
} else {
log.debug("No statistics found for exercise: {}", exerciseID);
Statistics statistics1 = new Statistics();
statistics1.setExerciseID(exerciseID);
statistics1.setBadgeRewarded(false);
statistics1.setDownloads(0);
statistics1.setViews(0);
statisticsRepository.save(statistics1);
}
}
/**
* Delete the "id" statistics.
*
......
......@@ -172,6 +172,14 @@ public class ReviewResource {
return ResponseEntity.ok().build();
}
@PostMapping("/review/removeBadge")
@PreAuthorize(ADMIN_ROLE)
public ResponseEntity<Void> removeBadge(@RequestBody ReviewDTO review) {
log.debug("REST request to remove badge for resource: {}", review.getResource());
reviewService.removeBadge(review.getId());
return ResponseEntity.ok().build();
}
@PostMapping("/review/changeStatus")
@PreAuthorize(USER_ROLE)
public ResponseEntity<UserDTO> changeStatus(@RequestBody boolean status) {
......
......@@ -119,7 +119,10 @@
<fa-icon icon="check-circle"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="review.create.rewardBadge">Reward Badge</span>
</button>
<button *ngIf="review.badgeRewarded" type="button" (click)="removeBadge(review)" class="m-1 btn btn-warning btn-sm">
<fa-icon icon="times-circle"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="review.create.removeBadge">Remove Badge</span>
</button>
<button
*ngIf="!review.badgeRewarded"
type="submit"
......
......@@ -131,4 +131,10 @@ export class ReviewManagementComponent implements OnInit, OnChanges {
this.reviewManagementService.rewardBadge(review).subscribe(() => this.loadAll());
}
removeBadge(review: Review) {
review.status = review.status?.map(() => 'REVIEW_IN_PROGRESS');
this.reviewManagementService.removeBadge(review).subscribe(() => this.loadAll());
}
}
......@@ -52,6 +52,10 @@ export class ReviewManagementService {
return this.http.post<Review>(this.resourceUrl + '/rewardBadge', review).pipe(tap(() => this.resetStatistics()));
}
removeBadge(review: Review): Observable<Review> {
return this.http.post<Review>(this.resourceUrl + '/removeBadge', review).pipe(tap(() => this.resetStatistics()));
}
private reviewStatisticsCache: BehaviorSubject<ReviewStatisticsDTO> | undefined;
public getReviewStatistics(): Observable<ReviewStatisticsDTO> {
......
......@@ -13,6 +13,7 @@
"requested": "Review Angefragt",
"rewarded": "Badge verliehen",
"rewardBadge": "Badge verleihen",
"removeBadge": "Badge zurückziehen",
"comments": "Kommentare ansehen",
"exerciseName": "Aufgaben Name",
"userEmail": "Benutzer Email",
......
......@@ -14,6 +14,7 @@
"requested": "Review Requested",
"rewarded": "Badge Rewarded",
"rewardBadge": "Reward Badge",
"removeBadge": "Remove Badge",
"exerciseName": "Enter exercise name",
"userEmail": "Enter user email",
"requestedReviewsByOther": "Requested Reviews by Others",
......
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