Skip to content

Commit cf06d43

Browse files
author
JLRR2019
committed
Merge branch 'Carlos' of https://github.com/CodeURJC-DAW-2021-22/webapp9 into JuanFase3
2 parents 125e45a + 1facf2d commit cf06d43

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed
Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
1-
import { Service } from '@angular/core';
1+
import { Injectable } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
33

4-
import { News } from '../Model/News';
5-
import { NewRepository } from '../Repositories/NewRepository';
4+
import { News } from '../models/new.model';
5+
import { Observable } from 'rxjs';
66

7-
@Service
8-
export class NewsService {
7+
const URL = '/api/news/';
98

10-
constructor(private httpClient: HttpClient) {}
9+
@Injectable({ providedIn: 'root' })
10+
export class NewsService {
1111

12-
private repository: NewRepository;
12+
constructor(private httpClient: HttpClient) { }
1313

14+
/*
1415
findById(id: number) {
1516
return this.repository.findById(id);
1617
}
18+
*/
19+
getNewById(id: number): Observable<News> {
20+
return this.httpClient.get(URL + id) as Observable<News>;
21+
}
1722

1823
exist(id: number) {
1924
return this.repository.existById(id);
2025
}
2126

2227
findAll(pageable: Pageable) {
23-
return this.repository.findAll(pageable);
28+
return this.httpClient.findAll(pageable);
2429
}
2530

31+
/*
2632
findAll() {
2733
return this.repository.findAll();
2834
}
35+
*/
36+
getNews(): Observable<News> {
37+
return this.httpClient.get(URL) as Observable<News>;
38+
}
2939

30-
save(new: News) {
40+
/*save(new: News) {
3141
return this.httpClient.put(URL + new.id, new);
3242
}
43+
*/
44+
saveNew(news: News) {
45+
return this.httpClient.put(URL + news.id, news);
46+
}
3347

48+
/*
3449
delete(id: number) {
3550
this.repository.deleteById(id);
3651
}
52+
*/
53+
deleteNew(news: News) {
54+
return this.httpClient.delete(URL + news.id);
55+
}
3756

3857
findAll(of: PageRequest) {
3958
return this.repository.findAll(of);
@@ -42,4 +61,4 @@ export class NewsService {
4261
findByIds(notices) {
4362
return this.repository.findAllById(notices);
4463
}
45-
}
64+
}

0 commit comments

Comments
 (0)