Compare commits
2 Commits
89335ea55b
...
44df4b564d
Author | SHA1 | Date | |
---|---|---|---|
44df4b564d | |||
d443a493d2 |
@ -0,0 +1,31 @@
|
|||||||
|
package github.benjamin.equipreservebackend.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.CorsConfigurationSource;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig {
|
||||||
|
|
||||||
|
@Value("${equip-reserve.allowed-origins}")
|
||||||
|
private String allowedOrigins;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
config.setAllowedOriginPatterns(List.of(allowedOrigins));
|
||||||
|
config.setAllowCredentials(true);
|
||||||
|
config.addAllowedHeader("*");
|
||||||
|
config.addAllowedMethod("*");
|
||||||
|
config.setMaxAge(3600L);
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", config);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import github.benjamin.equipreservebackend.utils.JwtUtil;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.Customizer;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
@ -24,7 +25,9 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
|
||||||
return http.csrf(AbstractHttpConfigurer::disable)
|
return http
|
||||||
|
.cors(Customizer.withDefaults())
|
||||||
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/login").permitAll()
|
.requestMatchers("/login").permitAll()
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package github.benjamin.equipreservebackend.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class WebConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
registry.addResourceHandler("/device_image/**")
|
|
||||||
.addResourceLocations("file:" + System.getProperty("user.dir") + "/device_image/");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
registry.addMapping("/**")
|
|
||||||
.allowedOriginPatterns("*")
|
|
||||||
.allowedMethods("*")
|
|
||||||
.allowedHeaders("*")
|
|
||||||
.allowCredentials(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum DeviceReservationState {
|
public enum DeviceReservationState {
|
||||||
|
|
||||||
FREE("可预约"),
|
FREE("空闲"),
|
||||||
RESERVED("有预约");
|
RESERVED("有预约");
|
||||||
|
|
||||||
private final String label;
|
private final String label;
|
||||||
|
@ -22,9 +22,10 @@ public class DeviceController {
|
|||||||
@PreAuthorize("hasRole('USER')")
|
@PreAuthorize("hasRole('USER')")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseResult<Page<DeviceUserVO>> getDevices(@RequestParam(defaultValue = "1") Integer page,
|
public ResponseResult<Page<DeviceUserVO>> getDevices(@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size) {
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
|
@RequestParam(required = false) String name) {
|
||||||
Page<Device> pageRequest = new Page<>(page, size);
|
Page<Device> pageRequest = new Page<>(page, size);
|
||||||
Page<DeviceUserVO> res = deviceService.getDeviceVO(pageRequest);
|
Page<DeviceUserVO> res = deviceService.getDeviceVO(pageRequest, name);
|
||||||
return ResponseResult.success(res);
|
return ResponseResult.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public interface DeviceService {
|
public interface DeviceService {
|
||||||
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest);
|
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name);
|
||||||
|
|
||||||
void addDevice(Device device);
|
void addDevice(Device device);
|
||||||
|
|
||||||
|
@ -38,10 +38,14 @@ public class DeviceServiceImpl implements DeviceService {
|
|||||||
private final ReservationService reservationService;
|
private final ReservationService reservationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest) {
|
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name) {
|
||||||
Page<Device> devices = deviceMapper.selectPage(pageRequest, new LambdaQueryWrapper<Device>()
|
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<Device>()
|
||||||
.eq(Device::getStatus, DeviceStatus.AVAILABLE)
|
.eq(Device::getStatus, DeviceStatus.AVAILABLE)
|
||||||
.orderByAsc(Device::getName));
|
.orderByAsc(Device::getName);
|
||||||
|
if (StringUtils.hasText(name)) {
|
||||||
|
queryWrapper.like(Device::getName, name);
|
||||||
|
}
|
||||||
|
Page<Device> devices = deviceMapper.selectPage(pageRequest,queryWrapper);
|
||||||
List<Long> deviceIds = devices.getRecords().stream()
|
List<Long> deviceIds = devices.getRecords().stream()
|
||||||
.map(Device::getId)
|
.map(Device::getId)
|
||||||
.toList();
|
.toList();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user