- Added last entrance request
- Added EntranceController documentation annotations for swagger - Changed QR blocking functionality
This commit is contained in:
parent
336bb589e7
commit
06aae07afd
@ -2,4 +2,4 @@ FROM eclipse-temurin:21
|
||||
LABEL authors="indx"
|
||||
|
||||
COPY ./build/libs/NTO-Finals-0.0.1-SNAPSHOT.jar /opt/app/
|
||||
CMD ["java", "-jar", "/opt/app/NTO-Finals-0.0.1-SNAPSHOT.jar"]
|
||||
CMD ["java", "-jar", "/opt/app/NTO-Finals-0.0.1-SNAPSHOT.jar"]
|
@ -2,6 +2,9 @@ package com.indexzero.finals.controller;
|
||||
|
||||
import com.indexzero.finals.dto.EntranceDTO;
|
||||
import com.indexzero.finals.service.EntranceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@ -18,12 +21,32 @@ public class EntranceController {
|
||||
|
||||
|
||||
@GetMapping
|
||||
@Operation(description = "Get all entrances of a user with pagination. Username is taken from Authentication", summary = "Get all entrances of a user")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Request Successful."),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
})
|
||||
public ResponseEntity<Page<EntranceDTO>> getEntrances(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
|
||||
Pageable pageable = PageRequest.of(page, size);
|
||||
return entranceService.getEmployeeEntrances(pageable, SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
@GetMapping("/last")
|
||||
@Operation(description = "Get user's last entrance. Username is taken from Authentication", summary = "Get user's last entrance")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Request Successful."),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
})
|
||||
public ResponseEntity<EntranceDTO> getLastEntrance() {
|
||||
return entranceService.getLastEntrance(SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Request Successful."),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden"),
|
||||
})
|
||||
@Operation(description = "Get all entrances of all users (ADMIN only)", summary = "Get all entrances")
|
||||
public ResponseEntity<Page<EntranceDTO>> getAllEntrances(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
|
||||
Pageable pageable = PageRequest.of(page, size);
|
||||
return entranceService.getAllEntrances(pageable);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.indexzero.finals.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ -10,4 +11,6 @@ public class EmployeeDTO {
|
||||
private String authority;
|
||||
private String position;
|
||||
private String photoUrl;
|
||||
@JsonProperty("qrEnabled")
|
||||
private boolean isQREnabled;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class Employee implements UserDetails {
|
||||
private String photoUrl;
|
||||
|
||||
@Column(name = "is_enabled")
|
||||
Boolean isEmpEnabled;
|
||||
Boolean isQREnabled;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
Set<Authority> authorities;
|
||||
@ -50,8 +50,4 @@ public class Employee implements UserDetails {
|
||||
return this.login;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return isEmpEnabled;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import org.springframework.security.core.Authentication;
|
||||
|
||||
public interface EntranceService {
|
||||
ResponseEntity<Page<EntranceDTO>> getEmployeeEntrances(Pageable pageable, Authentication auth);
|
||||
ResponseEntity<EntranceDTO> getLastEntrance(Authentication auth);
|
||||
ResponseEntity<Page<EntranceDTO>> getAllEntrances(Pageable pageable);
|
||||
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
entranceRepository.save(entrance);
|
||||
|
||||
// employeeRepository.save(employee);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
@ -90,12 +89,12 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
else {
|
||||
if(state.equals("active")) {
|
||||
e.setIsEmpEnabled(true);
|
||||
e.setIsQREnabled(true);
|
||||
employeeRepository.save(e);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
else if(state.equals("blocked")) {
|
||||
e.setIsEmpEnabled(false);
|
||||
e.setIsQREnabled(false);
|
||||
employeeRepository.save(e);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
@ -37,6 +37,14 @@ public class EntranceServiceImpl implements EntranceService {
|
||||
return new ResponseEntity<>(page, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<EntranceDTO> getLastEntrance(Authentication auth) {
|
||||
Employee employee = employeeRepository.findByLogin(auth.getName());
|
||||
List<EntranceDTO> entrances = employee.getEntrances().stream().map(EntranceMapper::convertToDTO).collect(Collectors.toList());
|
||||
System.out.println(entrances.getLast());
|
||||
return new ResponseEntity<>(entrances.getLast(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Page<EntranceDTO>> getAllEntrances(Pageable pageable) {
|
||||
List<Entrance> entrances = entranceRepository.findAll();
|
||||
|
@ -14,6 +14,7 @@ public class EmployeeMapper {
|
||||
employeeDTO.setName(user.getName());
|
||||
employeeDTO.setPosition(user.getPosition());
|
||||
employeeDTO.setPhotoUrl(user.getPhotoUrl());
|
||||
employeeDTO.setQREnabled(user.getIsQREnabled());
|
||||
return employeeDTO;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user