fix lastvisit not found
This commit is contained in:
parent
96cf747f8b
commit
379c9e75a8
@ -26,7 +26,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.csrf().disable()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/h2-console/**").permitAll()
|
||||
.antMatchers("api/**").hasAuthority("ROLE_ADMIN")
|
||||
.antMatchers("api/passing").hasAuthority("ROLE_ADMIN")
|
||||
.antMatchers("api/{username}/**").hasAnyAuthority("ROLE_USER", "ROLE_ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
|
@ -59,8 +59,8 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/passing")
|
||||
public List<PassingDTO> getAllPassing() {
|
||||
return passingService.getAllPassing();
|
||||
public List<PassingDTO> getAllPassing(String authority) {
|
||||
return passingService.getAllPassing(authority);
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
|
@ -4,6 +4,6 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CodeDTO {
|
||||
private Long Id;
|
||||
private Long code;
|
||||
private Integer Id;
|
||||
private String code;
|
||||
}
|
||||
|
@ -5,9 +5,10 @@ import org.hibernate.mapping.Set;
|
||||
|
||||
@Data
|
||||
public class PassingDTO {
|
||||
private Long id;
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String type;
|
||||
private String time;
|
||||
private Long code;
|
||||
private String code;
|
||||
private String authority;
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserDTO {
|
||||
private Long id;
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String name;
|
||||
private String photo;
|
||||
private String position;
|
||||
private String authority;
|
||||
// private String lastVisit;
|
||||
private String lastvisit;
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import javax.persistence.*;
|
||||
public class Code {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "code")
|
||||
private Long code;
|
||||
private String code;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import javax.persistence.*;
|
||||
public class Passing {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@JoinColumn(name = "username")
|
||||
private String username;
|
||||
@ -22,5 +22,8 @@ public class Passing {
|
||||
private String type;
|
||||
|
||||
@Column(name = "code")
|
||||
private Long code;
|
||||
private String code;
|
||||
|
||||
@Column(name = "authorities")
|
||||
private String authority;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
||||
public class User implements UserDetails{
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
@ -36,8 +36,8 @@ public class User implements UserDetails{
|
||||
@Column(name = "authorities")
|
||||
private String authority;
|
||||
|
||||
// @Column(name = "lastVisit")
|
||||
// private String lastVisit;
|
||||
@Column(name = "lastvisit")
|
||||
private String lastvisit;
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
|
@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CodeRepository extends JpaRepository<Code, Long> {
|
||||
Optional<Code> findByCode(Long code);
|
||||
public interface CodeRepository extends JpaRepository<Code, Integer> {
|
||||
Optional<Code> findByCode(Integer code);
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PassingRepository extends JpaRepository<Passing, Long> {
|
||||
public interface PassingRepository extends JpaRepository<Passing, Integer> {
|
||||
Optional<Passing> findByAuthority(String authority);
|
||||
|
||||
List<Passing> findByUsername(String login);
|
||||
|
||||
@Override
|
||||
|
@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
public interface UserRepository extends JpaRepository<User, Integer> {
|
||||
Optional<User> findByAuthority(String authority);
|
||||
|
||||
Optional<User> findByUsername(String username);
|
||||
|
@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import java.util.List;
|
||||
|
||||
public interface PassingService {
|
||||
List<PassingDTO> getAllPassing();
|
||||
List<PassingDTO> getAllPassing(String authority);
|
||||
|
||||
List<PassingDTO> getPassingByUsername(String username);
|
||||
|
||||
|
@ -25,10 +25,10 @@ public class PassingServiceImpl implements PassingService {
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public List<PassingDTO> getAllPassing() {
|
||||
Optional<User> userOptional = userRepository.findByAuthority("ROLE_ADMIN");
|
||||
if (userOptional.isEmpty()) {
|
||||
throw new AuthorityNotFoundException("Нет прав");
|
||||
public List<PassingDTO> getAllPassing(String authority) {
|
||||
Optional<Passing> passingOptional = passingRepository.findByAuthority("ROLE_ADMIN");
|
||||
if (passingOptional.isEmpty()) {
|
||||
throw new AuthorityNotFoundException("Ошибка доступа");
|
||||
}
|
||||
|
||||
return passingRepository.findAll().stream().map(PassingMapper::convertToDto).collect(Collectors.toList());
|
||||
|
@ -13,6 +13,7 @@ public class PassingMapper {
|
||||
dto.setType(passing.getType());
|
||||
dto.setTime(passing.getTime());
|
||||
dto.setCode(passing.getCode());
|
||||
dto.setAuthority(passing.getAuthority());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class UserMapper {
|
||||
dto.setPhoto(user.getPhoto());
|
||||
dto.setPosition(user.getPosition());
|
||||
dto.setAuthority(user.getAuthority());
|
||||
// dto.setLastVisit(user.getLastVisit());
|
||||
dto.setLastvisit(user.getLastvisit());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
<column name="authorities" type="VARCHAR(20)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="lastVisit" type="VARCHAR(100)"/>
|
||||
<column name="lastvisit" type="VARCHAR(100)"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
|
@ -27,6 +27,9 @@
|
||||
<column name="code" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="authorities" type="VARCHAR(20)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
username;type;time;code
|
||||
pivanov;Карта;12:00;1234567890123456789
|
||||
ipetrov;Вход со смартфона;13:00;9223372036854775807
|
||||
asemenov;Карта;10:00;1234567890123456789
|
||||
pivanov;Вход со смартфона;15:00;1234567890123456789
|
||||
username;type;time;code;authorities
|
||||
pivanov;Карта;12:00;1234567890123456789;ROLE_ADMIN
|
||||
ipetrov;Вход со смартфона;13:00;9223372036854775807;ROLE_USER
|
||||
asemenov;Карта;10:00;1234567890123456789;ROLE_USER
|
||||
pivanov;Вход со смартфона;15:00;1234567890123456789;ROLE_USER
|
||||
|
|
Loading…
x
Reference in New Issue
Block a user