Skip to content

Commit f0673f3

Browse files
authored
Merge pull request #145 from cvazquezlos/dev
Pre-release changes.
2 parents cfa7bd9 + a2ad403 commit f0673f3

43 files changed

Lines changed: 1243 additions & 435 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,14 @@ All Request URLs can be send by typing http://localhost:8443 followed by the req
3535
"title": newTitle,
3636
"author": newAuthor,
3737
"editorial": newEditorial,
38+
"resourceCopiesNumber": numberOfCopies,
3839
"description": newDescription,
3940
"resourceType": {
4041
"id": typeId
4142
},
4243
"genre": {
4344
"id": genreId
44-
},
45-
"copies": [
46-
{
47-
"id": newAndUniqueCopyId,
48-
"locationCode": newLocationCode
49-
}
50-
]
45+
}
5146
}
5247
```
5348
#### DELETE method

backend/src/main/java/appSpring/model/Resource.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public interface ResoCopy {}
4040
private ArrayList<String> noReservedCopies;
4141
@JsonView(Basic.class)
4242
private Boolean avaiblereserve;
43+
private Integer resourceCopiesNumber;
4344

4445
@Column(length = 1024)
4546
@JsonView(Basic.class)
@@ -177,4 +178,12 @@ public void setHasPhoto(boolean hasPhoto) {
177178
this.hasPhoto = hasPhoto;
178179
}
179180

181+
public int getResourceCopiesNumber() {
182+
return this.resourceCopiesNumber;
183+
}
184+
185+
public void setResourceCopiesNumber(int resourceCopiesNumber) {
186+
this.resourceCopiesNumber = resourceCopiesNumber;
187+
}
188+
180189
}

backend/src/main/java/appSpring/restController/FileRestController.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,18 @@
1414
import org.springframework.web.bind.annotation.RequestMethod;
1515
import org.springframework.web.bind.annotation.RestController;
1616

17-
import com.fasterxml.jackson.annotation.JsonView;
18-
19-
import appSpring.model.Fine;
20-
import appSpring.model.ResourceCopy;
21-
import appSpring.model.User;
22-
2317
import appSpring.service.UserService;
2418
import appSpring.service.ResourceService;
2519

2620
@RestController
2721
@RequestMapping("/api/files")
2822
public class FileRestController {
29-
30-
public interface FineDetail extends Fine.Basic, Fine.ResoCopy, Fine.Usr, ResourceCopy.Basic, User.Basic {
31-
}
3223

3324
@Autowired
3425
private UserService userService;
3526
@Autowired
3627
private ResourceService resourceService;
3728

38-
@JsonView(FineDetail.class)
3929
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
4030
public ResponseEntity<String> getUserfile(@PathVariable int id, Authentication authentication, HttpSession session,
4131
HttpServletRequest request) throws IOException {
@@ -48,7 +38,6 @@ public ResponseEntity<String> getUserfile(@PathVariable int id, Authentication a
4838
}
4939
}
5040

51-
@JsonView(FineDetail.class)
5241
@RequestMapping(value = "/resource/{id}", method = RequestMethod.GET)
5342
public ResponseEntity<String> getResourceFile(@PathVariable int id, Authentication authentication, HttpSession session,
5443
HttpServletRequest request) throws IOException {

backend/src/main/java/appSpring/restController/ResourceRestController.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ public ResponseEntity<Resource> postResource(@RequestBody Resource resource, Htt
5151
newResource.setGenre(resource.getGenre());
5252
newResource.setProductType(resource.getProductType());
5353
resourceService.save(newResource);
54-
for (ResourceCopy resourceCopy : resource.getResourceCopies()) {
55-
if (resourceCopyService.findOne(resourceCopy.getID()) == null) {
56-
resourceCopy.setResource(newResource);
57-
resourceCopyService.save(resourceCopy);
58-
newResource.getNoReservedCopies().add(resourceCopy.getLocationCode());
59-
} else {
60-
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
61-
}
54+
ResourceCopy copy;
55+
for (int i = 0; i < resource.getResourceCopiesNumber(); i++) {
56+
copy = new ResourceCopy();
57+
copy.setResource(newResource);
58+
copy.generatorCode();
59+
resourceCopyService.save(copy);
60+
copy.setLocationCode(copy.getLocationCode() + copy.getID());
61+
resourceCopyService.save(copy);
62+
newResource.getNoReservedCopies().add(copy.getLocationCode());
63+
newResource.getResourceCopies().add(copy);
6264
}
6365
resourceService.save(newResource);
64-
return new ResponseEntity<>(resource, HttpStatus.OK);
66+
return new ResponseEntity<>(newResource, HttpStatus.OK);
6567
}
6668

6769
@JsonView(ResourceDetail.class)
@@ -151,5 +153,15 @@ public ResponseEntity<Resource> putUserImage(@PathVariable Integer id,
151153
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
152154
}
153155
}
156+
157+
@JsonView(ResourceDetail.class)
158+
@RequestMapping(value = "/all", method = RequestMethod.GET)
159+
public ResponseEntity<List<Resource>> getAllResources(HttpSession session) {
160+
161+
session.setMaxInactiveInterval(-1);
162+
163+
List<Resource> resources = resourceService.findAll();
164+
return new ResponseEntity<>(resources, HttpStatus.OK);
165+
}
154166

155167
}

backend/src/main/java/appSpring/security/RestSecurityConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected void configure(HttpSecurity http) throws Exception {
2727
"/api/genres/{id}", "/api/resourcetypes", "/api/resourcetypes/{id}").permitAll();
2828
http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/users/{id}", "/api/loans", "/api/loans/{id}",
2929
"/api/fines", "/api/fines/{id}", "/api/resourcecopies", "/api/resourcecopies/{id}").hasAnyRole("USER");
30-
http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/users").hasAnyRole("ADMIN");
30+
http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/users", "/api/resources/all").hasAnyRole("ADMIN");
3131
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/users").hasAnyRole("ADMIN");
3232
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/loans").hasAnyRole("USER", "ADMIN");
3333
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/resources", "/api/genres", "/api/resourcetypes",

backend/target/appSpring-0.0.1.jar

-219 Bytes
Binary file not shown.
-183 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Manifest-Version: 1.0
2+
Implementation-Title: appSpring
3+
Implementation-Version: 0.0.1
4+
Built-By: c.vazquezlos
5+
Implementation-Vendor-Id: es.urjc.daw
6+
Build-Jdk: 1.8.0_121
7+
Implementation-URL: http://projects.spring.io/spring-boot/appSpring/
8+
Created-By: Maven Integration for Eclipse
9+
Implementation-Vendor: Pivotal Software, Inc.
10+
Main-Class: appSpring.Application
11+
342 Bytes
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
server.port = 8443
2+
server.ssl.key-store = classpath:keystore.jks
3+
server.ssl.key-store-password = password
4+
server.ssl.key-password = secret
5+
spring.h2.console.enabled=true
6+
7+
spring.datasource.url = jdbc:mysql://localhost/brems?verifyServerCertificate=false&useSSL=true
8+
spring.datasource.username = root
9+
spring.datasource.password = 1234
10+
spring.datasource.driverClassName = com.mysql.jdbc.Driver
11+
spring.jpa.hibernate.ddl-auto = create-drop
12+
13+
spring.mail.host = smtp.gmail.com
14+
spring.mail.port = 587
15+
spring.mail.username = bremslibrerias@gmail.com
16+
spring.mail.password = BrEmSbReMs7102
17+
18+
spring.mail.properties.mail.smtp.auth = true
19+
spring.mail.properties.mail.smtp.socketFactory.port = 465
20+
spring.mail.properties.mail.smtp.starttls.required = false
21+
spring.mail.properties.mail.smtp.starttls.enable = true
22+
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
23+
spring.mail.properties.mail.smtp.socketFactory.fallback = false

0 commit comments

Comments
 (0)