Skip to content

Commit

Permalink
Merge pull request #143 from cvazquezlos/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cvazquezlos authored Apr 20, 2017
2 parents ec0365e + 5a14790 commit cb69834
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,16 @@ public interface LoanDetail extends Action.Basic, Action.ResoCopy, ResourceCopy.

@JsonView(LoanDetail.class)
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<Action> postAction(@RequestBody Action loan, Authentication authentication,
HttpSession session, HttpServletRequest request) {
public ResponseEntity<Action> postAction(@RequestBody Action loan) {

session.setMaxInactiveInterval(-1);
if ((authentication.getName().equals(userService.findOne(loan.getUser().getId()).getName()))
|| (request.isUserInRole("ADMIN"))) {
Date date = new Date();
Resource resource = resourceService.findOne(loan.getResource().getResource().getId());
ResourceCopy resourceCopy = resourceCopyService.findOne(loan.getResource().getID());
int status = logicService.reserveAResource(userService.findOne(loan.getUser().getId()), date, resource,
resourceCopy);
if (status == 0) {
return new ResponseEntity<>(logicService.getAction(), HttpStatus.CREATED);
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Date date = new Date();
Resource resource = resourceService.findOne(loan.getResource().getResource().getId());
ResourceCopy resourceCopy = resourceCopyService.findOne(loan.getResource().getID());
int status = logicService.reserveAResource(userService.findOne(loan.getUser().getId()), date, resource, resourceCopy);
if (status == 0) {
return new ResponseEntity<>(logicService.getAction(), HttpStatus.CREATED);
} else {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -54,11 +53,10 @@ public ResourceCopy postResourceCopy(@RequestBody ResourceCopy resourceCopy, Htt

@JsonView(ResourceCopyDetail.class)
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<Page<ResourceCopy>> getResourceCopies(HttpSession session, @RequestParam (required=false) Integer page) {
public ResponseEntity<List<ResourceCopy>> getResourceCopies(HttpSession session, @RequestParam (required=false) Integer page) {

session.setMaxInactiveInterval(-1);
if(page==null) page=0;
Page<ResourceCopy> resourceCopies = resourceCopyService.findAll(page);
List<ResourceCopy> resourceCopies = resourceCopyService.findAll();
return new ResponseEntity<>(resourceCopies, HttpStatus.OK);
}

Expand Down
12 changes: 6 additions & 6 deletions backend/src/main/java/appSpring/service/LogicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private boolean hasEnoughCopies(Resource resource) {
private boolean hasAnActiveAction(User user, Resource resource) {
List<Action> actions = user.getActions();
for (Action action : actions) {
if (action.getResource().getResource() == resource && action.getDateLoanReturn() == null) {
if (action.getResource().getResource() == resource && action.getDateLoanReturn() == new Date(0)) {
return true;
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public Action getAction() {
}

private boolean deleteLoanAvaible(Action loan) {
return (loan.getDateLoanReturn() == null);
return (loan.getDateLoanReturn() == new Date(0));
}

public int deleteALoan(Action loan) {
Expand Down Expand Up @@ -143,11 +143,11 @@ public int createAnUser(User user) {
}

private boolean itIsPossibleToReturn(Action action) {
return ((action.getDateLoanGiven() != null) && (action.getDateLoanReturn() == null));
return ((action.getDateLoanGiven() == new Date(0)) && (action.getDateLoanReturn() == new Date(0)));
}

private boolean itIsPossibleToGive(Action action) {
return ((action.getDateLoanGiven() == null) && (action.getDateLoanReturn() == null));
return ((action.getDateLoanGiven() == new Date(0)) && (action.getDateLoanReturn() == new Date(0)));
}

public int addGiveDate(Action action, Date date) {
Expand Down Expand Up @@ -184,10 +184,10 @@ public int addReturnDate(Action action, Date date) {
List<Action> currentActions = actionService.findByUser(action.getUser());
for (Action currentAction : currentActions) {
Date date1 = currentAction.getDateLoanGiven();
if (date1 == null)
if (date1 == new Date(0))
continue;
Date date3 = currentAction.getDateLoanReturn();
if (date3 != null)
if (date3 == new Date(0))
continue;
date1.setMinutes(date1.getMinutes() + 1);
Date date2 = new Date();
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.
Binary file modified backend/target/classes/appSpring/service/LogicService.class
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
<p>
manage-fines works!
</p>
<section class="content-header">
<h1>
Administración de multas
<small>Administra las multas de los usuarios</small>
</h1>
<ol class="breadcrumb">
<li><a href="/admin/"><i class="fa fa-dashboard"></i> Inicio</a></li>
<li class="active">Multas</li>
</ol>
</section>
<section class="content">
<table class="table table-bordered table-striped" style="background-color: white !important;">
<thead>
<tr>
<th width="10%">Identificador</th>
<th width="15%">Usuario</th>
<th width="20%">Recurso</th>
<th width="10%">Razón</th>
<th width="20%">Tiempo</th>
<th width="3%">Administrar</th>
</tr>
</thead>
<tbody>
<ng-template ngFor let-fine [ngForOf]="fines">
<tr>
<td>{{fine?.id}}</td>
<td>{{fine.user?.name}}</td>
<td>{{fine.resourceCopy?.title}}</td>
<td>Default</td>
<td>{{fine?.initDate}} - {{fine?.finishDate}}</td>
<td>
<button type="button" class="btn btn-warning" (click)="delete(fine.id)">
<span class="fa fa-trash"></span>
</button>
</td>
</tr>
</ng-template>
</tbody>
</table><div>
<div class="pull-right">
<button *ngIf="showPreviousPage" type="button" class="btn btn-primary" (click)="previousPage()">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
</button>
<button *ngIf="showNextPage" type="button" class="btn btn-primary" (click)="nextPage()">
<i class="fa fa-arrow-right" aria-hidden="true"></i>
</button>
</div>
</div>
</section>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,114 @@
import { Component, OnInit } from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';

import {FineService} from '../../../service/fine.service';
import {SessionService} from '../../../service/session.service';

import {Fine} from '../../../model/fine.model';

@Component({
selector: 'app-manage-fines',
templateUrl: './manage-fines.component.html',
styleUrls: ['./manage-fines.component.css']
templateUrl: 'manage-fines.component.html'
})
export class ManageFinesComponent implements OnInit {

constructor() { }
errorMessage: boolean;
message: String;
pageFines: number;
showNextPage: boolean;
showPreviousPage: boolean;
successMessage: boolean;
fines: Fine[];

constructor(private router: Router, private sessionService: SessionService, private fineService: FineService) {
this.successMessage = false;
this.errorMessage = false;
this.pageFines = 0;
this.showNextPage = false;
this.showPreviousPage = false;
}

ngOnInit() {
if (!this.sessionService.checkCredentials())
this.router.navigate(['/login']);
else {
this.getFines();
this.checkNextPage();
this.checkPreviousPage();
}
}

getFines() {
this.fineService.getAllFines(this.pageFines).subscribe(
fines => this.fines = fines,
error => console.log('Fail trying to get all fines.')
);
}

nextPage() {
this.showNextPage = false;
this.showPreviousPage = false;
this.pageFines++;
this.getFines();
this.checkNextPage();
this.showPreviousPage = true;
}

previousPage() {
this.showNextPage = false;
this.showPreviousPage = false;
this.pageFines--;
this.getFines();
this.checkPreviousPage();
this.showNextPage = true;
}

checkNextPage() {
this.fineService.getAllFines(this.pageFines + 1).subscribe(
fines => {
if (Object.keys(fines).length === 0) {
this.showNextPage = false;
} else {
this.showNextPage = true;
}
}
);
}

checkPreviousPage() {
if (this.pageFines > 0) {
this.fineService.getAllFines(this.pageFines - 1).subscribe(
fines => {
if (Object.keys(fines).length === 0) {
this.showPreviousPage = false;
} else {
this.showPreviousPage = true;
}
}
);
} else {
this.showPreviousPage = false;
}
}

delete(id: number) {
this.fineService.deleteFine(id).subscribe(
response => {
this.successMessage = true;
this.errorMessage = false;
this.message = 'Multa eliminada correctamente.';
this.pageFines = 0;
console.log('Fine successfully deleted.');
this.getFines();
this.checkNextPage();
this.checkPreviousPage();
},
error => {
this.successMessage = false;
this.errorMessage = true;
this.message = 'No se ha podido eliminar la multa. Está activa.';
console.log('Fail trying to delete selected fine.');
}
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ManageUsersComponent implements OnInit {
this.errorMessage = false;
this.users = [];
this.usersPage = 0;
this.showNextPage = true;
this.showNextPage = false;
this.showPreviousPage = false;
}

Expand All @@ -33,6 +33,8 @@ export class ManageUsersComponent implements OnInit {
this.router.navigate(["/login"]);
} else {
this.getUsers();
this.checkNextPage();
this.checkPreviousPage();
}
}

Expand Down Expand Up @@ -64,7 +66,6 @@ export class ManageUsersComponent implements OnInit {
checkNextPage() {
this.userService.getUsers(this.usersPage + 1).subscribe(
users => {
console.log(this.usersPage + 1 + users);
if (Object.keys(users).length === 0) {
this.showNextPage = false;
} else {
Expand All @@ -78,7 +79,6 @@ export class ManageUsersComponent implements OnInit {
if (this.usersPage > 0) {
this.userService.getUsers(this.usersPage - 1).subscribe(
users => {
console.log(this.usersPage + users);
if (Object.keys(users).length === 0) {
this.showPreviousPage = false;
} else {
Expand All @@ -99,12 +99,7 @@ export class ManageUsersComponent implements OnInit {
this.message = 'Usuario eliminado correctamente.';
this.usersPage = 0;
console.log('User successfully deleted.');
this.userService.getUsers(this.usersPage).subscribe(
users => {
this.users = users;
},
error => console.log("Fail trying to get all users.")
);
this.getUsers();
this.checkNextPage();
this.checkPreviousPage();
},
Expand Down
Loading

0 comments on commit cb69834

Please sign in to comment.