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