Skip to content

Commit 358e725

Browse files
committed
Test
1 parent a96cd1c commit 358e725

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

angular/wallypop/.idea/workspace.xml

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular/wallypop/src/app/components/articles/commercial.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {ArticleService} from '../../services/article.service';
44
import {Article} from '../../models/article.model';
55
import {Category} from '../../models/category.model';
66
import {CategoryService} from '../../services/category.service';
7+
import {User} from '../../models/user.model';
78

89
@Component({
910
selector: 'commercial',
@@ -32,5 +33,12 @@ export class CommercialComponent implements OnInit {
3233
article => this.articles = article,
3334
error => console.log(error)
3435
);
36+
this.articles.forEach(value => {
37+
value.user = this.getUser(value.userID);
38+
});
39+
}
40+
41+
getUser(id: bigint): User {
42+
return this.loginService.getUser(id);
3543
}
3644
}

angular/wallypop/src/app/models/article.model.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {User} from './user.model';
2+
13
export interface Article {
24
id_ARTICLE?: number;
35
city: string;
@@ -11,6 +13,7 @@ export interface Article {
1113
sold: boolean;
1214

1315
// photo: Blob;
14-
// user: User;
16+
userID: bigint;
17+
user: User;
1518
// categories: Category[];
16-
}
19+
}

angular/wallypop/src/app/services/login.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
33
import { User } from '../models/user.model';
44
import {Subscription} from 'rxjs';
5+
import {retry} from 'rxjs/operators';
56

67
const BASE_URL = '/api/auth';
78

@@ -65,4 +66,15 @@ export class LoginService {
6566
currentUser(): User {
6667
return this.user;
6768
}
69+
70+
getUser(id: bigint): User {
71+
// tslint:disable-next-line:variable-name
72+
let user_: User;
73+
this.http.post('/api/users/', { id }, { withCredentials: true })
74+
.subscribe(
75+
(response) => user_ = response as User,
76+
(error) => alert('Usuario y/o contraseña no válidos')
77+
);
78+
return user_;
79+
}
6880
}

backend/src/main/java/es/codeurjc/wallypop/controller/api/UserRestController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.servlet.http.HttpServletRequest;
1313
import java.security.Principal;
1414
import java.sql.SQLException;
15+
import java.util.Optional;
1516

1617
@RestController
1718
@RequestMapping("/api/users")
@@ -70,4 +71,16 @@ public ResponseEntity<User> deleteUser(HttpServletRequest request) {
7071
}
7172
}
7273

74+
@GetMapping("/{id}")
75+
public ResponseEntity<User> getUser(@PathVariable long id) {
76+
77+
Optional<User> op = userService.findById(id);
78+
if (op.isPresent()) {
79+
User user = op.get();
80+
return new ResponseEntity<>(user, HttpStatus.OK);
81+
} else {
82+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
83+
}
84+
}
85+
7386
}

0 commit comments

Comments
 (0)