Compare commits

..

No commits in common. "44df4b564d26bae18cc0c5cc3a2f18ff1849fe21" and "89335ea55bcfa6f2344d4f613417561a08b35b10" have entirely different histories.

7 changed files with 33 additions and 47 deletions

View File

@ -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;
}
}

View File

@ -6,7 +6,6 @@ import github.benjamin.equipreservebackend.utils.JwtUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
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.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
@ -25,9 +24,7 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
return http
.cors(Customizer.withDefaults())
.csrf(AbstractHttpConfigurer::disable)
return http.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/login").permitAll()

View File

@ -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);
}
}

View File

@ -5,7 +5,7 @@ import lombok.Getter;
@Getter
public enum DeviceReservationState {
FREE("空闲"),
FREE("可预约"),
RESERVED("有预约");
private final String label;

View File

@ -22,10 +22,9 @@ public class DeviceController {
@PreAuthorize("hasRole('USER')")
@GetMapping
public ResponseResult<Page<DeviceUserVO>> getDevices(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String name) {
@RequestParam(defaultValue = "10") Integer 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);
}

View File

@ -8,7 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
public interface DeviceService {
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name);
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest);
void addDevice(Device device);

View File

@ -38,14 +38,10 @@ public class DeviceServiceImpl implements DeviceService {
private final ReservationService reservationService;
@Override
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name) {
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<Device>()
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest) {
Page<Device> devices = deviceMapper.selectPage(pageRequest, new LambdaQueryWrapper<Device>()
.eq(Device::getStatus, DeviceStatus.AVAILABLE)
.orderByAsc(Device::getName);
if (StringUtils.hasText(name)) {
queryWrapper.like(Device::getName, name);
}
Page<Device> devices = deviceMapper.selectPage(pageRequest,queryWrapper);
.orderByAsc(Device::getName));
List<Long> deviceIds = devices.getRecords().stream()
.map(Device::getId)
.toList();