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

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

Erster Durchstich

parent a59bd6ed
No related merge requests found
Showing
with 109 additions and 2 deletions
package at.ac.uibk.gitsearch.repository;
import at.ac.uibk.gitsearch.domain.User;
import at.ac.uibk.gitsearch.domain.UserWatchList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
......@@ -16,4 +19,13 @@ public interface UserWatchListRepository extends JpaRepository<UserWatchList, Lo
@Query("select userWatchList from UserWatchList userWatchList where userWatchList.userId.login = ?#{principal.username}")
List<UserWatchList> findByUserIdIsCurrentUser();
/**
* Returns all watchlists of the current user.
*
* @param userId the id of the user
* @return the list of watchlists
*/
List<UserWatchList> findByUserId(long UserId);
}
......@@ -13,7 +13,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static org.elasticsearch.index.query.QueryBuilders.*;
......@@ -66,6 +68,19 @@ public class UserWatchListService {
.map(userWatchListMapper::toDto);
}
/**
* Get all the userWatchLists.
*
* @param pageable the pagination information.
* @return the list of entities.
*/
@Transactional(readOnly = true)
public List<UserWatchListDTO> findByUserIdIsCurrentUser() {
log.debug("Request to get all UserWatchLists");
return userWatchListRepository.findByUserIdIsCurrentUser().stream()
.map(userWatchListMapper::toDto).collect(Collectors.toList());
}
/**
* Get one userWatchList by id.
......
......@@ -18,6 +18,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
......@@ -60,6 +61,7 @@ public class UserWatchListResource {
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("/user-watch-lists")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<UserWatchListDTO> createUserWatchList(@Valid @RequestBody UserWatchListDTO userWatchListDTO) throws URISyntaxException {
log.debug("REST request to save UserWatchList : {}", userWatchListDTO);
if (userWatchListDTO.getId() != null) {
......@@ -81,6 +83,7 @@ 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);
if (userWatchListDTO.getId() == null) {
......@@ -100,6 +103,7 @@ public class UserWatchListResource {
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of userWatchLists in body.
*/
@GetMapping("/user-watch-lists")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<List<UserWatchListDTO>> getAllUserWatchLists(UserWatchListCriteria criteria, Pageable pageable) {
log.debug("REST request to get UserWatchLists by criteria: {}", criteria);
Page<UserWatchListDTO> page = userWatchListQueryService.findByCriteria(criteria, pageable);
......@@ -107,6 +111,18 @@ public class UserWatchListResource {
return ResponseEntity.ok().headers(headers).body(page.getContent());
}
/**
* {@code GET /user-watch-lists} : get all the userWatchLists.
*
* @param pageable the pagination information.
* @param criteria the criteria which the requested entities should match.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of userWatchLists in body.
*/
@GetMapping("/my-user-watch-lists")
public ResponseEntity<List<UserWatchListDTO>> getUserWatchListsOfCurrentUser() {
List<UserWatchListDTO> page = userWatchListService.findByUserIdIsCurrentUser();
return ResponseEntity.ok().body(page);
}
/**
* {@code GET /user-watch-lists/count} : count all the userWatchLists.
*
......@@ -114,6 +130,7 @@ public class UserWatchListResource {
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the count in body.
*/
@GetMapping("/user-watch-lists/count")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<Long> countUserWatchLists(UserWatchListCriteria criteria) {
log.debug("REST request to count UserWatchLists by criteria: {}", criteria);
return ResponseEntity.ok().body(userWatchListQueryService.countByCriteria(criteria));
......@@ -126,6 +143,7 @@ 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) {
log.debug("REST request to get UserWatchList : {}", id);
Optional<UserWatchListDTO> userWatchListDTO = userWatchListService.findOne(id);
......@@ -139,6 +157,7 @@ public class UserWatchListResource {
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/user-watch-lists/{id}")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<Void> deleteUserWatchList(@PathVariable Long id) {
log.debug("REST request to delete UserWatchList : {}", id);
userWatchListService.delete(id);
......@@ -154,6 +173,7 @@ public class UserWatchListResource {
* @return the result of the search.
*/
@GetMapping("/_search/user-watch-lists")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseEntity<List<UserWatchListDTO>> searchUserWatchLists(@RequestParam String query, Pageable pageable) {
log.debug("REST request to search for a page of UserWatchLists for query {}", query);
Page<UserWatchListDTO> page = userWatchListService.search(query, pageable);
......
......@@ -28,6 +28,10 @@ export class UserWatchListService {
return this.http.get<IUserWatchList>(`${this.resourceUrl}/${id}`, { observe: 'response' });
}
/** returns the watchlists of the current user */
findMyWatchlists(): Observable<EntityArrayResponseType> {
return this.http.get<IUserWatchList[]>(`${SERVER_API_URL}/api/my-user-watch-lists`, { observe: 'response' });
}
query(req?: any): Observable<EntityArrayResponseType> {
const options = createRequestOption(req);
return this.http.get<IUserWatchList[]>(this.resourceUrl, { params: options, observe: 'response' });
......
......@@ -288,6 +288,9 @@
<span class="spawn-submenu" jhiTranslate="global.menu.account.settingsDescription"
*ngSwitchCase="true">Manage your user settings</span>
<span class="spawn-submenu"
*ngSwitchCase="true">My Watchlists</span>
<a class="dropdown-item" routerLink="account/password" routerLinkActive="active"
*ngSwitchCase="true" (click)="collapseNavbar()">
<fa-icon icon="lock" [fixedWidth]="true"></fa-icon>
......
......@@ -73,6 +73,8 @@
</form>
</div>
</ng-container>
<jhi-watchlist>
</jhi-watchlist>
</div>
......@@ -8,11 +8,13 @@ import { ExerciseModule } from 'app/exercise/exercise.module';
import { SearchComponent } from './search.component';
import { SearchInputComponent } from './search-input/search-input.component';
import { WatchlistComponent } from '../watchlist/watchlist.component';
@NgModule({
imports: [RouterModule.forChild([SEARCH_ROUTE]), GitSearchV2SharedModule, QueryParamModule, InfiniteScrollModule, ExerciseModule],
declarations: [SearchComponent, SearchInputComponent],
imports: [RouterModule.forChild([SEARCH_ROUTE]), GitSearchV2SharedModule, QueryParamModule, InfiniteScrollModule,
ExerciseModule],
declarations: [SearchComponent, SearchInputComponent, WatchlistComponent],
exports: [SearchComponent],
})
export class SearchModule {}
<div >
<div *ngFor="let watchList of myWatchLists">{{watchList.name}}
</div>
</div>
import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { UserWatchListService } from '../entities/user-watch-list/user-watch-list.service';
import { IUserWatchList } from 'app/shared/model/user-watch-list.model';
@Component({
selector: 'jhi-watchlist',
templateUrl: './watchlist.component.html',
styleUrls: ['./watchlist.component.scss'],
})
export class WatchlistComponent implements OnInit, OnDestroy {
myWatchLists: IUserWatchList[] | undefined;
constructor(
protected watchListService: UserWatchListService,
) {
}
ngOnInit(): void {
if (!this.myWatchLists) {
this.watchListService.findMyWatchlists().subscribe((data: HttpResponse<IUserWatchList[]>) => {
if (data.body) {
this.myWatchLists = data.body;
/*
this.myWatchLists = [];
for (let i = 0; i < data.body.length; i++) {
this.myWatchLists.push(data.body[i]);
}
*/
}
})
}
}
ngOnDestroy(): 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