Skip to content

Commit

Permalink
Merge pull request #144 from cvazquezlos/carlos
Browse files Browse the repository at this point in the history
Carlos
  • Loading branch information
cvazquezlos authored Apr 23, 2017
2 parents b72fd21 + 67a8563 commit a2ad403
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 85 deletions.
9 changes: 2 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,14 @@ All Request URLs can be send by typing http://localhost:8443 followed by the req
"title": newTitle,
"author": newAuthor,
"editorial": newEditorial,
"resourceCopiesNumber": numberOfCopies,
"description": newDescription,
"resourceType": {
"id": typeId
},
"genre": {
"id": genreId
},
"copies": [
{
"id": newAndUniqueCopyId,
"locationCode": newLocationCode
}
]
}
}
```
#### DELETE method
Expand Down
9 changes: 9 additions & 0 deletions backend/src/main/java/appSpring/model/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public interface ResoCopy {}
private ArrayList<String> noReservedCopies;
@JsonView(Basic.class)
private Boolean avaiblereserve;
private Integer resourceCopiesNumber;

@Column(length = 1024)
@JsonView(Basic.class)
Expand Down Expand Up @@ -177,4 +178,12 @@ public void setHasPhoto(boolean hasPhoto) {
this.hasPhoto = hasPhoto;
}

public int getResourceCopiesNumber() {
return this.resourceCopiesNumber;
}

public void setResourceCopiesNumber(int resourceCopiesNumber) {
this.resourceCopiesNumber = resourceCopiesNumber;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ public ResponseEntity<Resource> postResource(@RequestBody Resource resource, Htt
newResource.setGenre(resource.getGenre());
newResource.setProductType(resource.getProductType());
resourceService.save(newResource);
for (ResourceCopy resourceCopy : resource.getResourceCopies()) {
if (resourceCopyService.findOne(resourceCopy.getID()) == null) {
resourceCopy.setResource(newResource);
resourceCopyService.save(resourceCopy);
newResource.getNoReservedCopies().add(resourceCopy.getLocationCode());
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
ResourceCopy copy;
for (int i = 0; i < resource.getResourceCopiesNumber(); i++) {
copy = new ResourceCopy();
copy.setResource(newResource);
copy.generatorCode();
resourceCopyService.save(copy);
copy.setLocationCode(copy.getLocationCode() + copy.getID());
resourceCopyService.save(copy);
newResource.getNoReservedCopies().add(copy.getLocationCode());
newResource.getResourceCopies().add(copy);
}
resourceService.save(newResource);
return new ResponseEntity<>(resource, HttpStatus.OK);
return new ResponseEntity<>(newResource, HttpStatus.OK);
}

@JsonView(ResourceDetail.class)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring.h2.console.enabled=true

spring.datasource.url = jdbc:mysql://localhost/brems?verifyServerCertificate=false&useSSL=true
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.password = 1234
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto = create-drop

Expand Down
Binary file modified backend/target/appSpring-0.0.1.jar
Binary file not shown.
Binary file modified backend/target/appSpring-0.0.1.jar.original
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/target/classes/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Implementation-Title: appSpring
Implementation-Version: 0.0.1
Built-By: jherel
Built-By: c.vazquezlos
Implementation-Vendor-Id: es.urjc.daw
Build-Jdk: 1.8.0_121
Implementation-URL: http://projects.spring.io/spring-boot/appSpring/
Expand Down
Binary file modified backend/target/classes/appSpring/model/Resource.class
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/target/classes/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring.h2.console.enabled=true

spring.datasource.url = jdbc:mysql://localhost/brems?verifyServerCertificate=false&useSSL=true
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.password = 1234
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto = create-drop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h3 class="box-title">Nuevo libro</h3>
</div>
<div class="form-group">
<label>Número de copias</label>
<input type="number" class="form-control" name="copiesNumber" placeholder="Número de copias" required>
<input type="number" class="form-control" placeholder="Número de copias" required [(ngModel)]="newResource.resourceCopiesNumber">
</div>
<div class="pull-right">
<input type="button" class="btn btn-success" value="Guardar" (click)="createResource()">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,80 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';

import { Resource } from 'app/model/resource.model';
import { Genre } from 'app/model/genre.model';
import { ResourceType } from 'app/model/resource-type.model';
import {Resource} from 'app/model/resource.model';
import {Genre} from 'app/model/genre.model';
import {ResourceType} from 'app/model/resource-type.model';

import { SessionService } from 'app/service/session.service';
import { ResourceService } from 'app/service/resource.service';
import { GenreService } from 'app/service/genre.service';
import {SessionService} from 'app/service/session.service';
import {ResourceService} from 'app/service/resource.service';
import {GenreService} from 'app/service/genre.service';

@Component({
templateUrl: './create.component.html',
styleUrls: ['./create.component.css']
templateUrl: './create.component.html',
styleUrls: ['./create.component.css']
})
export class CreateResourceComponent implements OnInit {

resource: Resource;
genres: Genre[];
types: ResourceType[];
resource: Resource;
genres: Genre[];
types: ResourceType[];

newResource: any = {};
resourceImage: any;
newResource: any = {};
resourceImage: any;

errorMessage: boolean;
message: string;
errorMessage: boolean;
message: string;

constructor(
private router: Router,
private sessionService: SessionService,
private resourceService: ResourceService,
private genreService: GenreService
) {
this.newResource = {
title: '',
author: '',
editorial: '',
description: '',
genre: null,
resourceType: null
}
constructor(private router: Router,
private sessionService: SessionService,
private resourceService: ResourceService,
private genreService: GenreService) {
this.newResource = {
title: '',
author: '',
editorial: '',
description: '',
genre: null,
resourceType: null,
resourceCopiesNumber: 1
}
}

ngOnInit() {
if (!this.sessionService.checkCredentials()) {
this.router.navigate(["/login"]);
} else {
this.genreService.getAllGenres().subscribe(
genres => this.genres = genres,
error => console.log(error)
);
this.resourceService.getResourcesTypes().subscribe(
types => this.types = types,
error => console.log(error)
)
}
ngOnInit() {
if (!this.sessionService.checkCredentials()) {
this.router.navigate(["/login"]);
} else {
this.genreService.getAllGenres().subscribe(
genres => this.genres = genres,
error => console.log(error)
);
this.resourceService.getResourcesTypes().subscribe(
types => this.types = types,
error => console.log(error)
)
}
}

createResource() {
this.resource = this.newResource;
createResource() {
this.resource = this.newResource;

this.resourceService.createResource(this.resource).subscribe(
response => {
if (this.resourceImage !== undefined) {
let formData = new FormData();
formData.append('file', this.resourceImage, this.resourceImage.name);
this.resourceService.updateFile(formData, response.id).subscribe();
}
this.router.navigate(['/admin/resources']);
},
error => {
this.errorMessage = true;
this.message = 'No se ha podido crear el recurso.'
}
);
}
this.resourceService.createResource(this.resource).subscribe(
response => {
if (this.resourceImage !== undefined) {
let formData = new FormData();
formData.append('file', this.resourceImage, this.resourceImage.name);
this.resourceService.updateFile(formData, response.id).subscribe();
}
this.router.navigate(['/admin/resources']);
},
error => {
this.errorMessage = true;
this.message = 'No se ha podido crear el recurso.'
}
);
}

selectFile($event) {
this.resourceImage = $event.target.files[0];
}
selectFile($event) {
this.resourceImage = $event.target.files[0];
}
}
1 change: 0 additions & 1 deletion frontend/src/app/component/public/public.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {User} from "../../model/user.model";
export class PublicComponent {

constructor() {
localStorage.clear();
}

@ViewChild(ModalLogin)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/model/resource.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface Resource {
hasPhoto: boolean;
noReservedCopies: string[];
genre?: Genre;
resourceCopiesNumber?: number;
}

0 comments on commit a2ad403

Please sign in to comment.