1
- import { Service } from '@angular/core' ;
1
+ import { Injectable } from '@angular/core' ;
2
2
import { HttpClient } from '@angular/common/http' ;
3
3
4
- import { News } from '../Model/News ' ;
5
- import { NewRepository } from '../Repositories/NewRepository ' ;
4
+ import { News } from '../models/new.model ' ;
5
+ import { Observable } from 'rxjs ' ;
6
6
7
- @Service
8
- export class NewsService {
7
+ const URL = '/api/news/' ;
9
8
10
- constructor ( private httpClient : HttpClient ) { }
9
+ @Injectable ( { providedIn : 'root' } )
10
+ export class NewsService {
11
11
12
- private repository : NewRepository ;
12
+ constructor ( private httpClient : HttpClient ) { }
13
13
14
+ /*
14
15
findById(id: number) {
15
16
return this.repository.findById(id);
16
17
}
18
+ */
19
+ getNewById ( id : number ) : Observable < News > {
20
+ return this . httpClient . get ( URL + id ) as Observable < News > ;
21
+ }
17
22
18
23
exist ( id : number ) {
19
24
return this . repository . existById ( id ) ;
20
25
}
21
26
22
27
findAll ( pageable : Pageable ) {
23
- return this . repository . findAll ( pageable ) ;
28
+ return this . httpClient . findAll ( pageable ) ;
24
29
}
25
30
31
+ /*
26
32
findAll() {
27
33
return this.repository.findAll();
28
34
}
35
+ */
36
+ getNews ( ) : Observable < News > {
37
+ return this . httpClient . get ( URL ) as Observable < News > ;
38
+ }
29
39
30
- save ( new : News ) {
40
+ /* save(new: News) {
31
41
return this.httpClient.put(URL + new.id, new);
32
42
}
43
+ */
44
+ saveNew ( news : News ) {
45
+ return this . httpClient . put ( URL + news . id , news ) ;
46
+ }
33
47
48
+ /*
34
49
delete(id: number) {
35
50
this.repository.deleteById(id);
36
51
}
52
+ */
53
+ deleteNew ( news : News ) {
54
+ return this . httpClient . delete ( URL + news . id ) ;
55
+ }
37
56
38
57
findAll ( of : PageRequest ) {
39
58
return this . repository . findAll ( of ) ;
@@ -42,4 +61,4 @@ export class NewsService {
42
61
findByIds ( notices ) {
43
62
return this . repository . findAllById ( notices ) ;
44
63
}
45
- }
64
+ }
0 commit comments