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