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

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

Diverse Fixes

parent 9f081d80
Branches
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
......@@ -45,7 +45,7 @@ public class UserWatchList implements Serializable {
@JsonIgnoreProperties(value = "userWatchLists", allowSetters = true)
private User userId;
@OneToMany(mappedBy = "watchlist", orphanRemoval = true, cascade = CascadeType.PERSIST)
@OneToMany(mappedBy = "watchlist", orphanRemoval = true)
private Set<WatchListEntry> watchListEntries;
// jhipster-needle-entity-add-field - JHipster will add fields here
......
......@@ -77,8 +77,13 @@ public class UserWatchListService {
* @return the persisted entity.
*/
public UserWatchListDTO save(UserWatchListDTO userWatchListDTO) {
Optional<UserWatchList> previous = userWatchListDTO.getId()!=null?userWatchListRepository.findById(userWatchListDTO.getId()):Optional.empty();
log.debug("Request to save UserWatchList : {}", userWatchListDTO);
UserWatchList userWatchList = userWatchListMapper.toEntity(userWatchListDTO);
if(previous.isPresent()) {
userWatchList.setWatchListEntries(previous.get().getWatchListEntries());
}
userWatchList = userWatchListRepository.save(userWatchList);
UserWatchListDTO result = userWatchListMapper.toDto(userWatchList);
return result;
......
......@@ -156,9 +156,14 @@ public class UserWatchListResource {
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/user-watch-lists")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<UserWatchListDTO> updateUserWatchList(@Valid @RequestBody UserWatchListDTO userWatchListDTO) throws URISyntaxException {
log.debug("REST request to update UserWatchList : {}", userWatchListDTO);
Long id = userWatchListDTO.getId();
if(id==null) {
return ResponseEntity.notFound().headers(HeaderUtil.createFailureAlert(applicationName, true, "UserWatchList", "not found",
"There was an error: id was null.")).build();
}
userWatchListService.checkAccessToWatchList(id, "searchExercisesOnWatchlist");
if (userWatchListDTO.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
......@@ -228,8 +233,8 @@ public class UserWatchListResource {
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the userWatchListDTO, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/user-watch-lists/{id}")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<UserWatchListDTO> getUserWatchList(@PathVariable Long id) {
userWatchListService.checkAccessToWatchList(id, "searchExercisesOnWatchlist");
log.debug("REST request to get UserWatchList : {}", id);
Optional<UserWatchListDTO> userWatchListDTO = userWatchListService.findOne(id);
return ResponseUtil.wrapOrNotFound(userWatchListDTO);
......
......@@ -23,7 +23,7 @@
<div class="table-responsive" id="entities" *ngIf="userWatchLists && userWatchLists.length > 0">
<div class="table-responsive" id="entities" >
<div class="col-sm-12">
<form name="searchForm" class="form-inline">
<div class="input-group w-100 mt-3">
......
......@@ -87,16 +87,23 @@ export class BookmarkComponent implements OnInit, OnDestroy {
})
.subscribe((res: HttpResponse<IUserWatchList[]>) =>
{ this.paginateUserWatchLists(res.body, res.headers);
this.loadCurrent(); });
if(!this.loadCurrent()) {
// should reset also current watchlist
}
});
}
private loadCurrent(): void {
private loadCurrent(): boolean {
let found = false;
this.userWatchLists.every( (uwl) => {
if(this.isSelected(uwl)) {
this.view(uwl);
found = true;
return false;
}
return true;})
return true;});
return found;
}
reset(): void {
......
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