Skip to content

Commit 2ffe13e

Browse files
committed
Merge branch 'JuanFase4' into mani
2 parents 4c4c24c + 7803980 commit 2ffe13e

18 files changed

+338
-51
lines changed

backend/gamelink/src/main/java/urjc/gamelink/Controllers/UserRestController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.web.bind.annotation.PathVariable;
2323
import org.springframework.web.bind.annotation.PostMapping;
2424
import org.springframework.web.bind.annotation.PutMapping;
25+
import org.springframework.web.bind.annotation.RequestBody;
2526
import org.springframework.web.bind.annotation.RequestMapping;
2627
import org.springframework.web.bind.annotation.RequestParam;
2728
import org.springframework.web.bind.annotation.ResponseStatus;
@@ -86,7 +87,7 @@ public ResponseEntity<Usero> createUser(Usero user, @RequestParam String passwor
8687

8788
// Modifies a user
8889
@PutMapping("/{id}")
89-
public ResponseEntity<Usero> updateUser(@PathVariable long id, @RequestParam Usero updatedUser)
90+
public ResponseEntity<Usero> updateUser(@PathVariable long id, @RequestBody Usero updatedUser)
9091
throws SQLException {
9192

9293
if (us.exist(id)) {

frontend/package-lock.json

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

frontend/src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ import { CommonModule } from '@angular/common';
2929

3030
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
3131
import { CarouselComponent } from './components/carousel/carousel.component';
32+
import { EditNewComponent } from './components/Admin/editNew.component';
33+
import { EditNewFormComponent } from './components/Admin/editNewForm.component'
34+
3235
import { AboutComponent } from './components/about/about.component';
36+
import { VideogameRecommendedComponent } from './components/videogame-recommended/videogame-recommended.component';
3337

3438

3539

frontend/src/app/app.routing.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import { HomeComponent } from './components/home/home.component';
88
import { NewsComponent } from './components/news/news.component';
99
import { ShowNewsComponent } from './components/news/showNews.component';
1010
import { UserProfile } from './components/user/userProfile.component';
11+
import { EditNewComponent } from './components/Admin/editNew.component';
1112
import { AboutComponent } from './components/about/about.component';
1213
import { LoginComponent } from './components/login/login.component';
1314
import { SignUpComponent } from './components/login/signUp.component';
14-
import { EditNewComponent } from './components/news/editNew.component';
15+
import { VideogameRecommendedComponent } from './components/videogame-recommended/videogame-recommended.component';
1516

1617
//aquí tenemos que completar todo lo que queremos que se vaya cargando en el router-outlet
1718
//ojo, el template no debe llamar al servicio, hay que hacerlo a través del componente
@@ -29,7 +30,9 @@ const appRoutes = [
2930
{ path: 'about', component: AboutComponent },
3031
{ path: 'login', component: LoginComponent },
3132
{ path: 'signUp', component: SignUpComponent },
32-
{ path: '**', redirectTo: 'home', pathMatch: 'full' }
33+
{ path: 'videogameRecommended', component: VideogameRecommendedComponent },
34+
{ path: '', redirectTo: 'home', pathMatch: 'full' },
35+
{ path: '**', redirectTo: 'home' }
3336

3437
]
3538

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<main class="flex-shrink-0">
2+
3+
<editNewForm [news]="news"></editNewForm> <!--[news es el de la clase hija]="news es el de la clase padre"-->
4+
5+
6+
</main>
7+
8+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Component, Input } from '@angular/core';
2+
import { Router, ActivatedRoute } from '@angular/router';
3+
4+
import { News } from 'src/app/models/news.model';
5+
import { NewsService } from 'src/app/services/news.service';
6+
7+
8+
@Component({
9+
selector: 'editNew',
10+
templateUrl: './editNew.component.html'
11+
})
12+
13+
14+
export class EditNewComponent{
15+
16+
news!: News;
17+
18+
constructor(public newsService: NewsService, activatedRoute: ActivatedRoute, private router: Router){
19+
20+
const id = activatedRoute.snapshot.params['id'];
21+
this.newsService.getNew(id).subscribe(
22+
(news) => this.news = news as News,
23+
(error: any) => console.error(error)
24+
)
25+
26+
27+
}
28+
29+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
<section style="margin-bottom: 4%;">
3+
4+
<form action="/editNew/{{news.id}}" method="post" enctype="multipart/form-data">
5+
6+
<div class="container" style="background-color:#f5f5f5; margin-top: 2%; padding-bottom: 1%; ">
7+
8+
<div class="row">
9+
<div class="col-12" style="padding-bottom: 5%;">
10+
<h2 style="text-align: center; padding-top: 2%;">Edit New Form</h2>
11+
</div>
12+
</div>
13+
14+
<div class="row mt-2 d-flex justify-content-center">
15+
<div class="col-md-4 " >
16+
<div>
17+
<label>Title: </label>
18+
<p><textarea name="title" placeholder="title" style="width: 100%;" [(ngModel)]="news.title"></textarea></p>
19+
</div>
20+
</div>
21+
<div class="col-md-4 " >
22+
<div>
23+
<label>Date: </label>
24+
<p><textarea name="date" placeholder="date" style="width: 100%;" [(ngModel)]="news.date"></textarea></p>
25+
</div>
26+
</div>
27+
</div>
28+
29+
<div class="row mt-2 d-flex justify-content-center">
30+
<div class="col-md-4 " >
31+
<div>
32+
<label>Read Time: </label>
33+
<p><textarea name="readTime" placeholder="readTime" style="width: 100%;" [(ngModel)]="news.readTime"></textarea></p>
34+
</div>
35+
</div>
36+
<div class="col-md-4 " >
37+
<div>
38+
<label>Badge: </label>
39+
<p><textarea name="badge" placeholder="badge" style="width: 100%;" [(ngModel)]="news.badge"></textarea></p>
40+
</div>
41+
</div>
42+
</div>
43+
44+
<div class="row mt-3 d-flex justify-content-center" >
45+
<div class="col-md-8">
46+
<div>
47+
<label style="text-align: left !important;">New Content: </label>
48+
<p><textarea name="description" placeholder="description" rows="10"
49+
style="width: 100%;"[(ngModel)]="news.description"></textarea></p>
50+
</div>
51+
</div>
52+
</div>
53+
54+
<div class="row mt-3 d-flex justify-content-center" >
55+
<div class="col-md-8">
56+
<div>
57+
<label style="text-align: left !important;">New short header: </label>
58+
<p><textarea name="argument" placeholder="argument" rows="10"
59+
style="width: 100%;" [(ngModel)]="news.argument"></textarea></p>
60+
</div>
61+
</div>
62+
</div>
63+
64+
65+
66+
67+
<div class="row mt-3 d-flex justify-content-center">
68+
<div class="col-8 ">
69+
<p>Image: </p>
70+
<p>
71+
<input #file type='file' name='imageField' accept=".jpg, .jpeg, .png, .svg"/>
72+
</p>
73+
</div>
74+
</div>
75+
76+
<!--<input type="hidden" name="_csrf" value="{{token}}" />-->
77+
78+
<p style="text-align: center;" >
79+
80+
<button #file class="btn btn-primary" (click)="save()">Save</button>
81+
<button class="btn btn-outline-light" style="color: black; border-color: black;" (click)="cancel()">Cancel</button>
82+
83+
84+
<!--<input #file class="btn btn-primary" type="submit" value="Save"/>-->
85+
<!--Boton que ejecutara la función ajax-->
86+
<!--<button class="btn btn-outline-light" style="color: black; border-color: black;"
87+
onclick="location.href='/'; return false;">Cancel</button>-->
88+
89+
<!--Boton para cancelar la acción-->
90+
</p>
91+
</div>
92+
</form>
93+
</section>
94+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Component, Input, ViewChild } from '@angular/core';
2+
import { Router, ActivatedRoute } from '@angular/router';
3+
4+
import { News } from 'src/app/models/news.model';
5+
import { NewsService } from 'src/app/services/news.service';
6+
7+
8+
@Component({
9+
selector: 'editNewForm',
10+
templateUrl: './editNewForm.component.html'
11+
})
12+
13+
14+
export class EditNewFormComponent {
15+
16+
17+
@Input() news!: News;
18+
@ViewChild("file")
19+
file!: any;
20+
21+
constructor(public router: Router, public newsService: NewsService, activatedRoute: ActivatedRoute){
22+
23+
/*const id = activatedRoute.snapshot.params['id'];
24+
this.newsService.getNew(id).subscribe(
25+
(news) => this.news = news as News,
26+
(error: any) => console.error(error)
27+
28+
);*/
29+
30+
}
31+
32+
uploadImage(news: News): void {
33+
34+
const image = this.file.nativeElement.files[0];
35+
if (image) {
36+
let formData = new FormData();
37+
formData.append("imageFile", image);
38+
this.newsService.uploadNewImage(news, formData).subscribe(
39+
_ => this.afterUploadImage(news),
40+
error => alert('Error uploading book image: ' + error)
41+
);
42+
} else {
43+
this.afterUploadImage(news);
44+
}
45+
}
46+
47+
48+
49+
private afterUploadImage(news: News){
50+
this.router.navigate(['/showNews/', news.id]);
51+
}
52+
53+
54+
deleteNew(news: News){
55+
this.newsService.deleteNew(news);
56+
}
57+
58+
save(){
59+
this.newsService.updateNew(this.news).subscribe(
60+
(news) => this.uploadImage(news as News),
61+
(error: string) => alert('Error al guardar los datos: ' + error)
62+
);
63+
64+
}
65+
66+
//(news) => {this.uploadImage(news as News); this.router.navigate(['/showNews/', this.news.id]);},
67+
68+
cancel() {
69+
window.history.back();
70+
}
71+
72+
}

frontend/src/app/components/home/home.component.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ <h1 class="display-5 fw-bolder text-white mb-2">Tienda y noticiero de videojuego
5151
<div id="moreImages" class="row gx-5 justify-content-center">
5252
<newsTemplate class="col-lg-4 mb-5" *ngFor="let ng of news" [news]="ng"></newsTemplate>
5353
</div>
54+
<div class="text-end mb-5 mb-xl-0">
55+
<a class="text-decoration-none">
56+
<button class="btn btn-secondary button" (click)="nextpage()" >
57+
<i class="fa fa-eye"></i> Pagina siguiente
58+
</button>
59+
<div id="loader"></div>
60+
</a>
61+
</div>
62+
<div *ngIf="page > 0" class="text-end mb-5 mb-xl-0">
63+
<a class="text-decoration-none">
64+
<button class="btn btn-secondary button" (click)="prevpage()" >
65+
<i class="fa fa-eye"></i> Pagina anterior
66+
</button>
67+
<div id="loader"></div>
68+
</a>
69+
</div>
5470

5571
</div>
5672
</section>

0 commit comments

Comments
 (0)