|
1 | | -/* eslint-disable max-classes-per-file */ |
2 | 1 | import { HttpClient } from '@angular/common/http'; |
3 | 2 | import { Injectable } from '@angular/core'; |
4 | | -import { Store } from '@ngrx/store'; |
5 | 3 | import { Observable } from 'rxjs'; |
6 | 4 |
|
7 | 5 | import { NotificationsService } from '../../shared/notifications/notifications.service'; |
8 | 6 | import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; |
9 | 7 | import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; |
10 | 8 | import { RequestParam } from '../cache/models/request-param.model'; |
11 | 9 | import { ObjectCacheService } from '../cache/object-cache.service'; |
12 | | -import { CoreState } from '../core-state.model'; |
| 10 | +import { |
| 11 | + DeleteData, |
| 12 | + DeleteDataImpl, |
| 13 | +} from '../data/base/delete-data'; |
13 | 14 | import { IdentifiableDataService } from '../data/base/identifiable-data.service'; |
14 | | -import { ChangeAnalyzer } from '../data/change-analyzer'; |
15 | | -import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service'; |
| 15 | +import { SearchDataImpl } from '../data/base/search-data'; |
16 | 16 | import { FindListOptions } from '../data/find-list-options.model'; |
17 | 17 | import { PaginatedList } from '../data/paginated-list.model'; |
18 | 18 | import { RemoteData } from '../data/remote-data'; |
19 | 19 | import { RequestService } from '../data/request.service'; |
20 | | -import { UpdateDataServiceImpl } from '../data/update-data.service'; |
21 | 20 | import { HALEndpointService } from '../shared/hal-endpoint.service'; |
22 | 21 | import { NoContent } from '../shared/NoContent.model'; |
23 | 22 | import { Suggestion } from './models/suggestion.model'; |
24 | | -import { SuggestionSource } from './models/suggestion-source.model'; |
25 | | -import { SuggestionTarget } from './models/suggestion-target.model'; |
26 | | -import { SuggestionSourceDataService } from './source/suggestion-source-data.service'; |
27 | | -import { SuggestionTargetDataService } from './target/suggestion-target-data.service'; |
28 | | - |
29 | | -/* tslint:disable:max-classes-per-file */ |
30 | | - |
31 | | -/** |
32 | | - * A private UpdateDataServiceImpl implementation to delegate specific methods to. |
33 | | - */ |
34 | | -export class SuggestionDataServiceImpl extends UpdateDataServiceImpl<Suggestion> { |
35 | | - |
36 | | - /** |
37 | | - * Initialize service variables |
38 | | - * @param {RequestService} requestService |
39 | | - * @param {RemoteDataBuildService} rdbService |
40 | | - * @param {Store<CoreState>} store |
41 | | - * @param {ObjectCacheService} objectCache |
42 | | - * @param {HALEndpointService} halService |
43 | | - * @param {NotificationsService} notificationsService |
44 | | - * @param {HttpClient} http |
45 | | - * @param {ChangeAnalyzer<Suggestion>} comparator |
46 | | - * @param responseMsToLive |
47 | | - */ |
48 | | - constructor( |
49 | | - protected requestService: RequestService, |
50 | | - protected rdbService: RemoteDataBuildService, |
51 | | - protected store: Store<CoreState>, |
52 | | - protected objectCache: ObjectCacheService, |
53 | | - protected halService: HALEndpointService, |
54 | | - protected notificationsService: NotificationsService, |
55 | | - protected http: HttpClient, |
56 | | - protected comparator: ChangeAnalyzer<Suggestion>, |
57 | | - protected responseMsToLive: number, |
58 | | - ) { |
59 | | - super('suggestions', requestService, rdbService, objectCache, halService, notificationsService, comparator ,responseMsToLive); |
60 | | - } |
61 | | -} |
62 | 23 |
|
63 | 24 | /** |
64 | 25 | * The service handling all Suggestion Target REST requests. |
65 | 26 | */ |
66 | 27 | @Injectable({ providedIn: 'root' }) |
67 | 28 | export class SuggestionsDataService extends IdentifiableDataService<Suggestion> { |
| 29 | + |
68 | 30 | protected searchFindBySourceMethod = 'findBySource'; |
69 | 31 | protected searchFindByTargetAndSourceMethod = 'findByTargetAndSource'; |
70 | 32 |
|
71 | | - /** |
72 | | - * A private UpdateDataServiceImpl implementation to delegate specific methods to. |
73 | | - */ |
74 | | - private suggestionsDataService: SuggestionDataServiceImpl; |
75 | | - |
76 | | - /** |
77 | | - * A private UpdateDataServiceImpl implementation to delegate specific methods to. |
78 | | - */ |
79 | | - private suggestionSourcesDataService: SuggestionSourceDataService; |
80 | | - |
81 | | - /** |
82 | | - * A private UpdateDataServiceImpl implementation to delegate specific methods to. |
83 | | - */ |
84 | | - private suggestionTargetsDataService: SuggestionTargetDataService; |
| 33 | + private deleteData: DeleteData<Suggestion>; |
| 34 | + private searchData: SearchDataImpl<Suggestion>; |
85 | 35 |
|
86 | 36 | /** |
87 | 37 | * Initialize service variables |
88 | 38 | * @param {RequestService} requestService |
89 | 39 | * @param {RemoteDataBuildService} rdbService |
90 | | - * @param {Store} store |
91 | 40 | * @param {ObjectCacheService} objectCache |
92 | 41 | * @param {HALEndpointService} halService |
93 | 42 | * @param {NotificationsService} notificationsService |
94 | 43 | * @param {HttpClient} http |
95 | | - * @param {DefaultChangeAnalyzer<Suggestion>} comparatorSuggestions |
96 | | - * @param {DefaultChangeAnalyzer<SuggestionSource>} comparatorSources |
97 | | - * @param {DefaultChangeAnalyzer<SuggestionTarget>} comparatorTargets |
98 | 44 | */ |
99 | 45 | constructor( |
100 | 46 | protected requestService: RequestService, |
101 | 47 | protected rdbService: RemoteDataBuildService, |
102 | | - protected store: Store<CoreState>, |
103 | 48 | protected objectCache: ObjectCacheService, |
104 | 49 | protected halService: HALEndpointService, |
105 | 50 | protected notificationsService: NotificationsService, |
106 | 51 | protected http: HttpClient, |
107 | | - protected comparatorSuggestions: DefaultChangeAnalyzer<Suggestion>, |
108 | | - protected comparatorSources: DefaultChangeAnalyzer<SuggestionSource>, |
109 | | - protected comparatorTargets: DefaultChangeAnalyzer<SuggestionTarget>, |
110 | 52 | ) { |
111 | 53 | super('suggestions', requestService, rdbService, objectCache, halService); |
112 | | - this.suggestionsDataService = new SuggestionDataServiceImpl(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparatorSuggestions, this.responseMsToLive); |
113 | | - this.suggestionSourcesDataService = new SuggestionSourceDataService(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparatorSources); |
114 | | - this.suggestionTargetsDataService = new SuggestionTargetDataService(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparatorTargets); |
115 | | - } |
116 | | - |
117 | | - /** |
118 | | - * Return the list of Suggestion Sources |
119 | | - * |
120 | | - * @param options |
121 | | - * Find list options object. |
122 | | - * @return Observable<RemoteData<PaginatedList<SuggestionSource>>> |
123 | | - * The list of Suggestion Sources. |
124 | | - */ |
125 | | - public getSources(options: FindListOptions = {}): Observable<RemoteData<PaginatedList<SuggestionSource>>> { |
126 | | - return this.suggestionSourcesDataService.getSources(options); |
127 | | - } |
128 | | - |
129 | | - /** |
130 | | - * Return the list of Suggestion Target for a given source |
131 | | - * |
132 | | - * @param source |
133 | | - * The source for which to find targets. |
134 | | - * @param options |
135 | | - * Find list options object. |
136 | | - * @param linksToFollow |
137 | | - * List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved. |
138 | | - * @return Observable<RemoteData<PaginatedList<SuggestionTarget>>> |
139 | | - * The list of Suggestion Target. |
140 | | - */ |
141 | | - public getTargets( |
142 | | - source: string, |
143 | | - options: FindListOptions = {}, |
144 | | - ...linksToFollow: FollowLinkConfig<SuggestionTarget>[] |
145 | | - ): Observable<RemoteData<PaginatedList<SuggestionTarget>>> { |
146 | | - options.searchParams = [new RequestParam('source', source)]; |
147 | | - |
148 | | - return this.suggestionTargetsDataService.getTargets(this.searchFindBySourceMethod, options, ...linksToFollow); |
149 | | - } |
150 | | - |
151 | | - /** |
152 | | - * Return the list of Suggestion Target for a given user |
153 | | - * |
154 | | - * @param userId |
155 | | - * The user Id for which to find targets. |
156 | | - * @param options |
157 | | - * Find list options object. |
158 | | - * @param linksToFollow |
159 | | - * List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved. |
160 | | - * @return Observable<RemoteData<PaginatedList<SuggestionTarget>>> |
161 | | - * The list of Suggestion Target. |
162 | | - */ |
163 | | - public getTargetsByUser( |
164 | | - userId: string, |
165 | | - options: FindListOptions = {}, |
166 | | - ...linksToFollow: FollowLinkConfig<SuggestionTarget>[] |
167 | | - ): Observable<RemoteData<PaginatedList<SuggestionTarget>>> { |
168 | | - options.searchParams = [new RequestParam('target', userId)]; |
169 | | - return this.suggestionTargetsDataService.getTargetsByUser(userId, options, ...linksToFollow); |
170 | | - } |
171 | | - |
172 | | - /** |
173 | | - * Return a Suggestion Target for a given id |
174 | | - * |
175 | | - * @param targetId |
176 | | - * The target id to retrieve. |
177 | | - * |
178 | | - * @return Observable<RemoteData<SuggestionTarget>> |
179 | | - * The list of Suggestion Target. |
180 | | - */ |
181 | | - public getTargetById(targetId: string): Observable<RemoteData<SuggestionTarget>> { |
182 | | - return this.suggestionTargetsDataService.findById(targetId); |
| 54 | + this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); |
| 55 | + this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); |
183 | 56 | } |
184 | 57 |
|
185 | 58 | /** |
186 | 59 | * Used to delete Suggestion |
187 | 60 | * @suggestionId |
188 | 61 | */ |
189 | 62 | public deleteSuggestion(suggestionId: string): Observable<RemoteData<NoContent>> { |
190 | | - return this.suggestionsDataService.delete(suggestionId); |
| 63 | + return this.deleteData.delete(suggestionId); |
191 | 64 | } |
192 | 65 |
|
193 | 66 | /** |
@@ -215,7 +88,7 @@ export class SuggestionsDataService extends IdentifiableDataService<Suggestion> |
215 | 88 | new RequestParam('source', source), |
216 | 89 | ]; |
217 | 90 |
|
218 | | - return this.suggestionsDataService.searchBy(this.searchFindByTargetAndSourceMethod, options, false, true, ...linksToFollow); |
| 91 | + return this.searchData.searchBy(this.searchFindByTargetAndSourceMethod, options, false, true, ...linksToFollow); |
219 | 92 | } |
220 | 93 |
|
221 | 94 | /** |
|
0 commit comments