User update; Gate update; Ban system; Create visin on gate open; Bugfix
This commit is contained in:
parent
ad063b3eab
commit
29a9d1dfaa
@ -1,10 +1,11 @@
|
|||||||
package com.displaynone.acss.components.acs;
|
package com.displaynone.acss.components.acs;
|
||||||
|
|
||||||
import com.displaynone.acss.components.acs.gate.GateModel;
|
import com.displaynone.acss.components.acs.models.gate.GateModel;
|
||||||
import com.displaynone.acss.components.acs.gate.service.GateService;
|
import com.displaynone.acss.components.acs.models.gate.service.GateService;
|
||||||
import com.displaynone.acss.components.acs.visit.VisitModel;
|
import com.displaynone.acss.components.acs.models.visit.VisitModel;
|
||||||
import com.displaynone.acss.components.acs.visit.service.VisitService;
|
import com.displaynone.acss.components.acs.models.visit.service.VisitService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ACSComponent {
|
public class ACSComponent {
|
||||||
@ -57,4 +59,19 @@ public class ACSComponent {
|
|||||||
public Page<VisitModel> getVisitsByUserIdPaginated(Long userId, Pageable pageable) {
|
public Page<VisitModel> getVisitsByUserIdPaginated(Long userId, Pageable pageable) {
|
||||||
return visitService.getVisitsByUserIdPaginated(userId, pageable);
|
return visitService.getVisitsByUserIdPaginated(userId, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateGate(Long gateId, GateModel gate) {
|
||||||
|
gateService.updateGate(gateId, gate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createVisit(VisitModel visit) {
|
||||||
|
visitService.createVisit(visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createVisit(Long userId, Long gateId) {
|
||||||
|
VisitModel visit = new VisitModel();
|
||||||
|
visit.setUserId(userId);
|
||||||
|
visit.setGateId(gateId);
|
||||||
|
createVisit(visit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package com.displaynone.acss.components.acs.gate;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class GateDTO {
|
|
||||||
private Long id;
|
|
||||||
private Long code;
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.displaynone.acss.components.acs.models.gate;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GateDTO {
|
||||||
|
private Long id;
|
||||||
|
private Long code;
|
||||||
|
private boolean isACSBlocked;
|
||||||
|
private boolean isActive;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.displaynone.acss.components.acs.gate;
|
package com.displaynone.acss.components.acs.models.gate;
|
||||||
|
|
||||||
import com.displaynone.acss.utils.GlobalUtils;
|
import com.displaynone.acss.utils.GlobalUtils;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
@ -13,6 +13,8 @@ public class GateMapper {
|
|||||||
|
|
||||||
dto.setId(model.getId());
|
dto.setId(model.getId());
|
||||||
dto.setCode(model.getCode());
|
dto.setCode(model.getCode());
|
||||||
|
dto.setACSBlocked(model.isACSBlocked());
|
||||||
|
dto.setActive(model.isActive());
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package com.displaynone.acss.components.acs.gate;
|
package com.displaynone.acss.components.acs.models.gate;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@ -15,8 +16,14 @@ import lombok.NoArgsConstructor;
|
|||||||
public class GateModel {
|
public class GateModel {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private long code;
|
private Long code;
|
||||||
|
|
||||||
|
@Column(nullable = false) // For soft deletion
|
||||||
|
private boolean isActive;
|
||||||
|
|
||||||
|
@Column(nullable = false) // For blocking in ACS
|
||||||
|
private boolean isACSBlocked;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.displaynone.acss.components.acs.gate;
|
package com.displaynone.acss.components.acs.models.gate;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package com.displaynone.acss.components.acs.gate.service;
|
package com.displaynone.acss.components.acs.models.gate.service;
|
||||||
|
|
||||||
import com.displaynone.acss.components.acs.gate.GateModel;
|
import com.displaynone.acss.components.acs.models.gate.GateModel;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -16,4 +16,6 @@ public interface GateService {
|
|||||||
boolean isGateExists(Long gateId);
|
boolean isGateExists(Long gateId);
|
||||||
|
|
||||||
boolean isGateCodeValid(Long code);
|
boolean isGateCodeValid(Long code);
|
||||||
|
|
||||||
|
void updateGate(Long gateId, GateModel gate);
|
||||||
}
|
}
|
@ -1,8 +1,9 @@
|
|||||||
package com.displaynone.acss.components.acs.gate.service;
|
package com.displaynone.acss.components.acs.models.gate.service;
|
||||||
|
|
||||||
import com.displaynone.acss.components.acs.gate.GateModel;
|
import com.displaynone.acss.components.acs.models.gate.GateModel;
|
||||||
import com.displaynone.acss.components.acs.gate.GateRepository;
|
import com.displaynone.acss.components.acs.models.gate.GateRepository;
|
||||||
import com.displaynone.acss.exception.generics.NotFoundHTTPException;
|
import com.displaynone.acss.exception.generics.NotFoundHTTPException;
|
||||||
|
import com.displaynone.acss.utils.GlobalUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -14,6 +15,10 @@ import java.util.Optional;
|
|||||||
public class GateServiceImpl implements GateService {
|
public class GateServiceImpl implements GateService {
|
||||||
private final GateRepository gateRepository;
|
private final GateRepository gateRepository;
|
||||||
|
|
||||||
|
private void saveGate(GateModel gate) {
|
||||||
|
gateRepository.save(gate);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<GateModel> getGateById(Long gateId) {
|
public Optional<GateModel> getGateById(Long gateId) {
|
||||||
return gateRepository.findById(gateId);
|
return gateRepository.findById(gateId);
|
||||||
@ -47,4 +52,14 @@ public class GateServiceImpl implements GateService {
|
|||||||
public boolean isGateCodeValid(Long code) {
|
public boolean isGateCodeValid(Long code) {
|
||||||
return getGateByCode(code).isPresent();
|
return getGateByCode(code).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateGate(Long gateId, GateModel gateUpdate) {
|
||||||
|
GateModel existingGate = getGateByIdStrict(gateId);
|
||||||
|
|
||||||
|
GlobalUtils.updateIfNotNull(gateUpdate.getCode(), existingGate::setCode);
|
||||||
|
GlobalUtils.updateIfNotNull(gateUpdate.isActive(), existingGate::setActive);
|
||||||
|
GlobalUtils.updateIfNotNull(gateUpdate.isACSBlocked(), existingGate::setACSBlocked);
|
||||||
|
|
||||||
|
saveGate(existingGate);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.displaynone.acss.components.acs.visit;
|
package com.displaynone.acss.components.acs.models.visit;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.displaynone.acss.components.acs.visit;
|
package com.displaynone.acss.components.acs.models.visit;
|
||||||
|
|
||||||
import com.displaynone.acss.utils.GlobalUtils;
|
import com.displaynone.acss.utils.GlobalUtils;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
@ -1,10 +1,11 @@
|
|||||||
package com.displaynone.acss.components.acs.visit;
|
package com.displaynone.acss.components.acs.models.visit;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ public class VisitModel {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Long gateId;
|
private Long gateId;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.displaynone.acss.components.acs.visit;
|
package com.displaynone.acss.components.acs.models.visit;
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
@ -1,6 +1,6 @@
|
|||||||
package com.displaynone.acss.components.acs.visit.service;
|
package com.displaynone.acss.components.acs.models.visit.service;
|
||||||
|
|
||||||
import com.displaynone.acss.components.acs.visit.VisitModel;
|
import com.displaynone.acss.components.acs.models.visit.VisitModel;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
@ -14,4 +14,6 @@ public interface VisitService {
|
|||||||
Page<VisitModel> getVisitsByGateIdPaginated(Long gateId, Pageable pageable);
|
Page<VisitModel> getVisitsByGateIdPaginated(Long gateId, Pageable pageable);
|
||||||
|
|
||||||
Page<VisitModel> getVisitsByUserIdPaginated(Long userId, Pageable pageable);
|
Page<VisitModel> getVisitsByUserIdPaginated(Long userId, Pageable pageable);
|
||||||
|
|
||||||
|
void createVisit(VisitModel visit);
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.displaynone.acss.components.acs.visit.service;
|
package com.displaynone.acss.components.acs.models.visit.service;
|
||||||
|
|
||||||
import com.displaynone.acss.components.acs.visit.VisitModel;
|
import com.displaynone.acss.components.acs.models.visit.VisitModel;
|
||||||
import com.displaynone.acss.components.acs.visit.VisitRepository;
|
import com.displaynone.acss.components.acs.models.visit.VisitRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
@ -14,6 +14,10 @@ import java.util.List;
|
|||||||
public class VisitServiceImpl implements VisitService {
|
public class VisitServiceImpl implements VisitService {
|
||||||
private final VisitRepository visitRepository;
|
private final VisitRepository visitRepository;
|
||||||
|
|
||||||
|
private void saveVisit(VisitModel visit) {
|
||||||
|
visitRepository.save(visit);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VisitModel> getByGateId(Long gateId) {
|
public List<VisitModel> getByGateId(Long gateId) {
|
||||||
return visitRepository.findByGateId(gateId);
|
return visitRepository.findByGateId(gateId);
|
||||||
@ -33,4 +37,9 @@ public class VisitServiceImpl implements VisitService {
|
|||||||
public Page<VisitModel> getVisitsByUserIdPaginated(Long userId, Pageable pageable) {
|
public Page<VisitModel> getVisitsByUserIdPaginated(Long userId, Pageable pageable) {
|
||||||
return visitRepository.findByUserId(userId, pageable);
|
return visitRepository.findByUserId(userId, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createVisit(VisitModel visit) {
|
||||||
|
saveVisit(visit);
|
||||||
|
}
|
||||||
}
|
}
|
@ -78,4 +78,8 @@ public class AuthComponent implements UserDetailsService {
|
|||||||
public UserDetails loadUserByUsername(@NonNull String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(@NonNull String username) throws UsernameNotFoundException {
|
||||||
return getUserByLoginStrict(username);
|
return getUserByLoginStrict(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateUserByLogin(String login, UserModel userUpdated) {
|
||||||
|
userService.updateUserByLogin(login, userUpdated);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,6 @@ public class UserDTO {
|
|||||||
private String position;
|
private String position;
|
||||||
private LocalDateTime lastVisit;
|
private LocalDateTime lastVisit;
|
||||||
private Set<RoleModel> roles;
|
private Set<RoleModel> roles;
|
||||||
|
private boolean isActive;
|
||||||
|
private boolean isACSBlocked;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ public class UserMapper {
|
|||||||
dto.setPhoto(model.getPhoto());
|
dto.setPhoto(model.getPhoto());
|
||||||
dto.setPosition(model.getPosition());
|
dto.setPosition(model.getPosition());
|
||||||
dto.setRoles(model.getRoles());
|
dto.setRoles(model.getRoles());
|
||||||
|
dto.setActive(model.isActive());
|
||||||
|
dto.setACSBlocked(model.isACSBlocked());
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.displaynone.acss.components.auth.models.user;
|
|||||||
import com.displaynone.acss.components.auth.models.role.RoleModel;
|
import com.displaynone.acss.components.auth.models.role.RoleModel;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
@ -37,6 +38,12 @@ public class UserModel implements UserDetails {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String position;
|
private String position;
|
||||||
|
|
||||||
|
@Column(nullable = false) // For soft deletion
|
||||||
|
private boolean isActive;
|
||||||
|
|
||||||
|
@Column(nullable = false) // For blocking in ACS
|
||||||
|
private boolean isACSBlocked;
|
||||||
|
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
@ -75,6 +82,6 @@ public class UserModel implements UserDetails {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return true;
|
return isActive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,4 +10,5 @@ public interface UserService {
|
|||||||
Optional<UserModel> findByLogin(String login);
|
Optional<UserModel> findByLogin(String login);
|
||||||
|
|
||||||
UserModel findByLoginStrict(String login);
|
UserModel findByLoginStrict(String login);
|
||||||
|
void updateUserByLogin(String login, UserModel userUpdated);
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package com.displaynone.acss.components.auth.models.user.service;
|
|||||||
import com.displaynone.acss.components.auth.models.user.UserModel;
|
import com.displaynone.acss.components.auth.models.user.UserModel;
|
||||||
import com.displaynone.acss.components.auth.models.user.UserRepository;
|
import com.displaynone.acss.components.auth.models.user.UserRepository;
|
||||||
import com.displaynone.acss.exception.generics.NotFoundHTTPException;
|
import com.displaynone.acss.exception.generics.NotFoundHTTPException;
|
||||||
|
import com.displaynone.acss.utils.GlobalUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -14,6 +14,10 @@ import java.util.Optional;
|
|||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
private void saveUser(UserModel userUpdated) {
|
||||||
|
userRepository.save(userUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UserModel> findByLogin(String login) {
|
public Optional<UserModel> findByLogin(String login) {
|
||||||
return userRepository.findByLogin(login);
|
return userRepository.findByLogin(login);
|
||||||
@ -25,4 +29,18 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (user.isEmpty()) throw new NotFoundHTTPException("User not found");
|
if (user.isEmpty()) throw new NotFoundHTTPException("User not found");
|
||||||
return user.get();
|
return user.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateUserByLogin(String login, UserModel userUpdated) {
|
||||||
|
UserModel existingUser = findByLoginStrict(login);
|
||||||
|
|
||||||
|
GlobalUtils.updateIfNotNull(userUpdated.getName(), existingUser::setName);
|
||||||
|
GlobalUtils.updateIfNotNull(userUpdated.getPhoto(), existingUser::setPhoto);
|
||||||
|
GlobalUtils.updateIfNotNull(userUpdated.getPosition(), existingUser::setPosition);
|
||||||
|
GlobalUtils.updateIfNotNull(userUpdated.getPassword(), existingUser::setPassword);
|
||||||
|
GlobalUtils.updateIfNotNull(userUpdated.isActive(), existingUser::setActive);
|
||||||
|
GlobalUtils.updateIfNotNull(userUpdated.isACSBlocked(), existingUser::setACSBlocked);
|
||||||
|
|
||||||
|
saveUser(existingUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package com.displaynone.acss.controllers.acs;
|
package com.displaynone.acss.controllers.acs;
|
||||||
|
|
||||||
import com.displaynone.acss.components.acs.ACSComponent;
|
import com.displaynone.acss.components.acs.ACSComponent;
|
||||||
import com.displaynone.acss.components.acs.visit.VisitDTO;
|
import com.displaynone.acss.components.acs.models.gate.GateDTO;
|
||||||
import com.displaynone.acss.components.acs.visit.VisitMapper;
|
import com.displaynone.acss.components.acs.models.gate.GateMapper;
|
||||||
|
import com.displaynone.acss.components.acs.models.gate.GateModel;
|
||||||
|
import com.displaynone.acss.components.acs.models.visit.VisitDTO;
|
||||||
|
import com.displaynone.acss.components.acs.models.visit.VisitMapper;
|
||||||
import com.displaynone.acss.components.auth.AuthComponent;
|
import com.displaynone.acss.components.auth.AuthComponent;
|
||||||
import com.displaynone.acss.components.auth.models.user.UserModel;
|
import com.displaynone.acss.components.auth.models.user.UserModel;
|
||||||
import com.displaynone.acss.exception.generics.ForbiddenHTTPException;
|
import com.displaynone.acss.exception.generics.ForbiddenHTTPException;
|
||||||
import com.displaynone.acss.exception.generics.NotFoundHTTPException;
|
import com.displaynone.acss.exception.generics.NotFoundHTTPException;
|
||||||
|
import com.displaynone.acss.utils.GlobalUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
@ -26,7 +30,14 @@ public class ACSController {
|
|||||||
@PostMapping("/open")
|
@PostMapping("/open")
|
||||||
public ResponseEntity<Void> open(@RequestBody OpenRQB body) {
|
public ResponseEntity<Void> open(@RequestBody OpenRQB body) {
|
||||||
Long code = body.getCode();
|
Long code = body.getCode();
|
||||||
if (!acsComponent.isGateCodeValid(code)) throw new ForbiddenHTTPException("Invalid gate code");
|
GateModel gate = acsComponent.getGateByCodeStrict(code);
|
||||||
|
if (gate.isACSBlocked()) throw new ForbiddenHTTPException("Specified gate is blocked");
|
||||||
|
|
||||||
|
UserModel user = (UserModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
if (user.isACSBlocked()) throw new ForbiddenHTTPException("User is blocked");
|
||||||
|
|
||||||
|
acsComponent.createVisit(user.getId(), gate.getId());
|
||||||
|
|
||||||
return ResponseEntity.ok(null);
|
return ResponseEntity.ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,13 +63,30 @@ public class ACSController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("visits/gate/{gateId}")
|
@GetMapping("visits/gate/{gateId}")
|
||||||
public ResponseEntity<Page<VisitDTO>> getGateVisitsPaginated(
|
public ResponseEntity<Page<VisitDTO>> getUserVisitsPaginated(
|
||||||
@RequestParam(defaultValue = "0") int page,
|
@RequestParam(defaultValue = "0") int page,
|
||||||
@RequestParam(defaultValue = "10") int size,
|
@RequestParam(defaultValue = "10") int size,
|
||||||
@PathVariable Long gateId
|
@PathVariable Long gateId
|
||||||
) {
|
) {
|
||||||
Pageable pageable = PageRequest.of(page, size);
|
Pageable pageable = PageRequest.of(page, size);
|
||||||
if (!acsComponent.isGateExists(gateId)) throw new NotFoundHTTPException("Invalid gate id");
|
if (!acsComponent.isGateExists(gateId)) throw new NotFoundHTTPException("Gate not found");
|
||||||
return ResponseEntity.ok(acsComponent.getVisitsByGateIdPaginated(gateId, pageable).map(VisitMapper::convertToDTO));
|
return ResponseEntity.ok(acsComponent.getVisitsByGateIdPaginated(gateId, pageable).map(VisitMapper::convertToDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("gates/gate/{gateId}")
|
||||||
|
public ResponseEntity<GateDTO> getGateById(@PathVariable Long gateId) {
|
||||||
|
return ResponseEntity.ok(GateMapper.convertToDTO(acsComponent.getGateByIdStrict(gateId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("gates/gate/{gateId}")
|
||||||
|
public ResponseEntity<Void> updateGateById(@PathVariable Long gateId, @RequestBody GateUpdateRQB body) {
|
||||||
|
GateModel gateUpdate = new GateModel();
|
||||||
|
|
||||||
|
GlobalUtils.updateIfNotNull(body.getCode(), gateUpdate::setCode);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getActive(), gateUpdate::setActive);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getBlocked(), gateUpdate::setACSBlocked);
|
||||||
|
acsComponent.updateGate(gateId, gateUpdate);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.displaynone.acss.controllers.acs;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GateUpdateRQB {
|
||||||
|
private Long code;
|
||||||
|
private Boolean active;
|
||||||
|
private Boolean blocked;
|
||||||
|
}
|
@ -4,13 +4,11 @@ import com.displaynone.acss.components.auth.AuthComponent;
|
|||||||
import com.displaynone.acss.components.auth.models.user.UserDTO;
|
import com.displaynone.acss.components.auth.models.user.UserDTO;
|
||||||
import com.displaynone.acss.components.auth.models.user.UserMapper;
|
import com.displaynone.acss.components.auth.models.user.UserMapper;
|
||||||
import com.displaynone.acss.components.auth.models.user.UserModel;
|
import com.displaynone.acss.components.auth.models.user.UserModel;
|
||||||
|
import com.displaynone.acss.utils.GlobalUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/users")
|
@RequestMapping("/api/users")
|
||||||
@ -29,4 +27,19 @@ public class UserController {
|
|||||||
UserModel user = authComponent.getUserByLoginStrict(login);
|
UserModel user = authComponent.getUserByLoginStrict(login);
|
||||||
return ResponseEntity.ok(UserMapper.convertToDTO(user));
|
return ResponseEntity.ok(UserMapper.convertToDTO(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/login/{login}")
|
||||||
|
public ResponseEntity<Void> updateUserByLogin(@PathVariable String login, @RequestBody UserUpdateRQB body) {
|
||||||
|
UserModel userUpdated = new UserModel();
|
||||||
|
|
||||||
|
GlobalUtils.updateIfNotNull(body.getName(), userUpdated::setName);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getPhoto(), userUpdated::setPhoto);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getPosition(), userUpdated::setPosition);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getPassword(), userUpdated::setPassword);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getIsActive(), userUpdated::setActive);
|
||||||
|
GlobalUtils.updateIfNotNull(body.getIsACSBlocked(), userUpdated::setACSBlocked);
|
||||||
|
|
||||||
|
authComponent.updateUserByLogin(login, userUpdated);
|
||||||
|
return ResponseEntity.ok(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.displaynone.acss.controllers.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserUpdateRQB {
|
||||||
|
private String password;
|
||||||
|
private String name;
|
||||||
|
private String photo;
|
||||||
|
private String position;
|
||||||
|
private Boolean isActive = true;
|
||||||
|
private Boolean isACSBlocked = false;
|
||||||
|
}
|
@ -47,6 +47,9 @@ public class WebSecurityConfig {
|
|||||||
authorizeRequests
|
authorizeRequests
|
||||||
.requestMatchers("/api/auth/**").permitAll()
|
.requestMatchers("/api/auth/**").permitAll()
|
||||||
.requestMatchers("/api/users/login/**").hasAuthority("ROLE_ADMIN")
|
.requestMatchers("/api/users/login/**").hasAuthority("ROLE_ADMIN")
|
||||||
|
.requestMatchers("/api/acs/visits/login/**").hasAuthority("ROLE_ADMIN")
|
||||||
|
.requestMatchers("/api/acs/visits/gate/**").hasAuthority("ROLE_ADMIN")
|
||||||
|
.requestMatchers("/api/acs/gates/**").hasAuthority("ROLE_ADMIN")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
<column name="name" type="VARCHAR(100)"/>
|
<column name="name" type="VARCHAR(100)"/>
|
||||||
<column name="photo" type="VARCHAR(200)"/>
|
<column name="photo" type="VARCHAR(200)"/>
|
||||||
<column name="position" type="VARCHAR(100)"/>
|
<column name="position" type="VARCHAR(100)"/>
|
||||||
|
<column name="is_active" type="BOOLEAN" defaultValue="true"/>
|
||||||
|
<column name="isacsblocked" type="BOOLEAN" defaultValue="false"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
<column name="code" type="BIGINT">
|
<column name="code" type="BIGINT">
|
||||||
<constraints unique="true" nullable="false"/>
|
<constraints unique="true" nullable="false"/>
|
||||||
</column>
|
</column>
|
||||||
|
<column name="is_active" type="BOOLEAN" defaultValue="true"/>
|
||||||
|
<column name="isacsblocked" type="BOOLEAN" defaultValue="true"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
<column name="gate_id" type="INTEGER">
|
<column name="gate_id" type="INTEGER">
|
||||||
<constraints nullable="false"/>
|
<constraints nullable="false"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="created_at" type="DATETIME"/>
|
<column name="created_at" type="DATETIME" defaultValueDate="${now}">
|
||||||
|
<constraints nullable="false" />
|
||||||
|
</column>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
<addForeignKeyConstraint baseTableName="visits"
|
<addForeignKeyConstraint baseTableName="visits"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
id;login;name;photo;position;password
|
login;name;photo;position;password;is_active;isacsblocked
|
||||||
1;user;Default User;https://dummyimage.com/600x400/ff0/000;Software Engineer;$2a$12$CUo06gR1qTWC9JB2o1HnXuTK2U5yLIdCPprVWgY8jdB9l.xhbAoQK
|
user;Default User;https://dummyimage.com/600x400/ff0/000;Software Engineer;$2a$12$CUo06gR1qTWC9JB2o1HnXuTK2U5yLIdCPprVWgY8jdB9l.xhbAoQK;1;0
|
||||||
2;admin;Admin User;https://dummyimage.com/600x400/ff0/000;Product Manager;$2a$12$e0djVwP9MBeFd9aZia33W.u1Yiq3gDpVNECXn7I.KgvjPr0eoeWwS
|
admin;Admin User;https://dummyimage.com/600x400/ff0/000;Product Manager;$2a$12$e0djVwP9MBeFd9aZia33W.u1Yiq3gDpVNECXn7I.KgvjPr0eoeWwS;1;0
|
||||||
3;bob_jones;Bob Jones;https://dummyimage.com/600x400/ff0/000;QA Engineer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
bob_jones;Bob Jones;https://dummyimage.com/600x400/ff0/000;QA Engineer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
4;alice_johnson;Alice Johnson;https://dummyimage.com/600x400/ff0/000;UX Designer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
alice_johnson;Alice Johnson;https://dummyimage.com/600x400/ff0/000;UX Designer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
5;charlie_brown;Charlie Brown;https://dummyimage.com/600x400/ff0/000;DevOps Engineer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
charlie_brown;Charlie Brown;https://dummyimage.com/600x400/ff0/000;DevOps Engineer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
6;diana_ross;Diana Ross;https://dummyimage.com/600x400/ff0/000;HR Manager;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
diana_ross;Diana Ross;https://dummyimage.com/600x400/ff0/000;HR Manager;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
7;edward_norton;Edward Norton;https://dummyimage.com/600x400/ff0/000;Backend Developer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
edward_norton;Edward Norton;https://dummyimage.com/600x400/ff0/000;Backend Developer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
8;fiona_green;Fiona Green;https://dummyimage.com/600x400/ff0/000;Frontend Developer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
fiona_green;Fiona Green;https://dummyimage.com/600x400/ff0/000;Frontend Developer;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
9;george_hill;George Hill;https://dummyimage.com/600x400/ff0/000;Data Scientist;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
george_hill;George Hill;https://dummyimage.com/600x400/ff0/000;Data Scientist;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
10;helen_white;Helen White;https://dummyimage.com/600x400/ff0/000;Project Manager;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.
|
helen_white;Helen White;https://dummyimage.com/600x400/ff0/000;Project Manager;$2a$12$b//P422i15PDoij6g4SOluIUol7X3E0eFttGMGlGCJuBmZFE6nMw.;1;0
|
||||||
|
|
@ -1,3 +1,3 @@
|
|||||||
id;name
|
name
|
||||||
1;ROLE_ADMIN
|
ROLE_ADMIN
|
||||||
2;ROLE_USER
|
ROLE_USER
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
id;code
|
code;is_active;isacsblocked
|
||||||
1;1234567890123456789
|
1234567890123456789;1;0
|
||||||
2;9223372036854775807
|
9223372036854775807;1;0
|
||||||
3;1122334455667788990
|
1122334455667788990;1;0
|
||||||
4;998877665544332211
|
998877665544332211;1;0
|
||||||
5;5566778899001122334
|
5566778899001122334;1;0
|
|
@ -1,51 +1,51 @@
|
|||||||
id;user_id;gate_id;created_at
|
user_id;gate_id;created_at
|
||||||
1;1;1;2023-10-01 08:00:00
|
1;1;2023-10-01 08:00:00
|
||||||
2;2;2;2023-10-01 09:15:00
|
2;2;2023-10-01 09:15:00
|
||||||
3;3;3;2023-10-01 10:30:00
|
3;3;2023-10-01 10:30:00
|
||||||
4;4;4;2023-10-01 11:45:00
|
4;4;2023-10-01 11:45:00
|
||||||
5;5;5;2023-10-01 12:00:00
|
5;5;2023-10-01 12:00:00
|
||||||
6;1;2;2023-10-01 13:15:00
|
1;2;2023-10-01 13:15:00
|
||||||
7;2;3;2023-10-01 14:30:00
|
2;3;2023-10-01 14:30:00
|
||||||
8;3;4;2023-10-01 15:45:00
|
3;4;2023-10-01 15:45:00
|
||||||
9;4;5;2023-10-01 16:00:00
|
4;5;2023-10-01 16:00:00
|
||||||
10;5;1;2023-10-01 17:15:00
|
5;1;2023-10-01 17:15:00
|
||||||
11;1;3;2023-10-02 08:30:00
|
1;3;2023-10-02 08:30:00
|
||||||
12;2;4;2023-10-02 09:45:00
|
2;4;2023-10-02 09:45:00
|
||||||
13;3;5;2023-10-02 10:00:00
|
3;5;2023-10-02 10:00:00
|
||||||
14;4;1;2023-10-02 11:15:00
|
4;1;2023-10-02 11:15:00
|
||||||
15;5;2;2023-10-02 12:30:00
|
5;2;2023-10-02 12:30:00
|
||||||
16;1;4;2023-10-02 13:45:00
|
1;4;2023-10-02 13:45:00
|
||||||
17;2;5;2023-10-02 14:00:00
|
2;5;2023-10-02 14:00:00
|
||||||
18;3;1;2023-10-02 15:15:00
|
3;1;2023-10-02 15:15:00
|
||||||
19;4;2;2023-10-02 16:30:00
|
4;2;2023-10-02 16:30:00
|
||||||
20;5;3;2023-10-02 17:45:00
|
5;3;2023-10-02 17:45:00
|
||||||
21;1;5;2023-10-03 08:00:00
|
1;5;2023-10-03 08:00:00
|
||||||
22;2;1;2023-10-03 09:15:00
|
2;1;2023-10-03 09:15:00
|
||||||
23;3;2;2023-10-03 10:30:00
|
3;2;2023-10-03 10:30:00
|
||||||
24;4;3;2023-10-03 11:45:00
|
4;3;2023-10-03 11:45:00
|
||||||
25;5;4;2023-10-03 12:00:00
|
5;4;2023-10-03 12:00:00
|
||||||
26;1;1;2023-10-03 13:15:00
|
1;1;2023-10-03 13:15:00
|
||||||
27;2;2;2023-10-03 14:30:00
|
2;2;2023-10-03 14:30:00
|
||||||
28;3;3;2023-10-03 15:45:00
|
3;3;2023-10-03 15:45:00
|
||||||
29;4;4;2023-10-03 16:00:00
|
4;4;2023-10-03 16:00:00
|
||||||
30;5;5;2023-10-03 17:15:00
|
5;5;2023-10-03 17:15:00
|
||||||
31;1;2;2023-10-04 08:30:00
|
1;2;2023-10-04 08:30:00
|
||||||
32;2;3;2023-10-04 09:45:00
|
2;3;2023-10-04 09:45:00
|
||||||
33;3;4;2023-10-04 10:00:00
|
3;4;2023-10-04 10:00:00
|
||||||
34;4;5;2023-10-04 11:15:00
|
4;5;2023-10-04 11:15:00
|
||||||
35;5;1;2023-10-04 12:30:00
|
5;1;2023-10-04 12:30:00
|
||||||
36;1;3;2023-10-04 13:45:00
|
1;3;2023-10-04 13:45:00
|
||||||
37;2;4;2023-10-04 14:00:00
|
2;4;2023-10-04 14:00:00
|
||||||
38;3;5;2023-10-04 15:15:00
|
3;5;2023-10-04 15:15:00
|
||||||
39;4;1;2023-10-04 16:30:00
|
4;1;2023-10-04 16:30:00
|
||||||
40;5;2;2023-10-04 17:45:00
|
5;2;2023-10-04 17:45:00
|
||||||
41;1;4;2023-10-05 08:00:00
|
1;4;2023-10-05 08:00:00
|
||||||
42;2;5;2023-10-05 09:15:00
|
2;5;2023-10-05 09:15:00
|
||||||
43;3;1;2023-10-05 10:30:00
|
3;1;2023-10-05 10:30:00
|
||||||
44;4;2;2023-10-05 11:45:00
|
4;2;2023-10-05 11:45:00
|
||||||
45;5;3;2023-10-05 12:00:00
|
5;3;2023-10-05 12:00:00
|
||||||
46;1;5;2023-10-05 13:15:00
|
1;5;2023-10-05 13:15:00
|
||||||
47;2;1;2023-10-05 14:30:00
|
2;1;2023-10-05 14:30:00
|
||||||
48;3;2;2023-10-05 15:45:00
|
3;2;2023-10-05 15:45:00
|
||||||
49;4;3;2023-10-05 16:00:00
|
4;3;2023-10-05 16:00:00
|
||||||
50;5;4;2023-10-05 17:15:00
|
5;4;2023-10-05 17:15:00
|
|
@ -4,6 +4,10 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
|
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
|
||||||
|
<property name="now" value="now()" dbms="mysql,h2"/>
|
||||||
|
<property name="now" value="current_timestamp" dbms="postgresql"/>
|
||||||
|
<property name="now" value="sysdate" dbms="oracle"/>
|
||||||
|
<property name="now" value="getdate()" dbms="mssql"/>
|
||||||
|
|
||||||
<include file="db/changelog/01/0002-roles.xml"/>
|
<include file="db/changelog/01/0002-roles.xml"/>
|
||||||
<include file="db/changelog/01/0001-users.xml"/>
|
<include file="db/changelog/01/0001-users.xml"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user