Skip to content

Commit 1facf2d

Browse files
committed
2ºparte newsService
1 parent b8fba0d commit 1facf2d

File tree

2 files changed

+65
-45
lines changed

2 files changed

+65
-45
lines changed

frontend/src/app/Service/NewsService.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)