Compare commits
No commits in common. "44df4b564d26bae18cc0c5cc3a2f18ff1849fe21" and "89335ea55bcfa6f2344d4f613417561a08b35b10" have entirely different histories.
44df4b564d
...
89335ea55b
@ -1,31 +0,0 @@
|
|||||||
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,7 +6,6 @@ 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;
|
||||||
@ -25,9 +24,7 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
|
||||||
return http
|
return http.csrf(AbstractHttpConfigurer::disable)
|
||||||
.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()
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
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,10 +22,9 @@ 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, name);
|
Page<DeviceUserVO> res = deviceService.getDeviceVO(pageRequest);
|
||||||
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, String name);
|
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest);
|
||||||
|
|
||||||
void addDevice(Device device);
|
void addDevice(Device device);
|
||||||
|
|
||||||
|
@ -38,14 +38,10 @@ public class DeviceServiceImpl implements DeviceService {
|
|||||||
private final ReservationService reservationService;
|
private final ReservationService reservationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name) {
|
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest) {
|
||||||
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<Device>()
|
Page<Device> devices = deviceMapper.selectPage(pageRequest, 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