同城顺风车预约系统:Java实现同城顺风车预约系统源码解析

   日期:2024-12-30    作者:4aw9d 移动:http://3jjewl.riyuangf.com/mobile/quote/81468.html

UserController.java(处理用户注册与登录

JAVA代码复制

@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@PostMapping("/register")
public ResponseEntity<String> register(@RequestBody UserDto userDto) {
userService.register(userDto);
return ResponseEntity.ok("User registered successfully");
}
@PostMapping("/login")
public ResponseEntity<UserDto> login(@RequestBody LoginDto loginDto) {
UserDto userDto = userService.login(loginDto);
return ResponseEntity.ok(userDto);
}
}


RideRequestController.java(处理顺风车需求发布与查看

java复制代码

@RestController
@RequestMapping("/ride")
public class RideRequestController {
@Autowired
private RideRequestService rideRequestService;
@PostMapping("/request")
public ResponseEntity<String> createRideRequest(@RequestBody RideRequestDto rideRequestDto) {
rideRequestService.createRideRequest(rideRequestDto);
return ResponseEntity.ok("Ride request created successfully");
}
@GetMapping("/requests")
public ResponseEntity<List<RideRequestDto>> getNearbyRideRequests(@RequestParam double latitude, @RequestParam double longitude) {
List<RideRequestDto> rideRequests = rideRequestService.getNearbyRideRequests(latitude, longitude);
return ResponseEntity.ok(rideRequests);
}
}
RideRequestService.java(业务逻辑层

java复制代码

@Service
public class RideRequestService {
@Autowired
private RideRequestRepository rideRequestRepository;
@Autowired
private UserService userService;
public void createRideRequest(RideRequestDto rideRequestDto) {
User user = userService.findById(rideRequestDto.getUserId());
RideRequest rideRequest = new RideRequest();
rideRequest.setUser(user);
rideRequest.setPickupLocation(rideRequestDto.getPickupLocation());
rideRequest.setDestination(rideRequestDto.getDestination());
rideRequest.setDepartureTime(rideRequestDto.getDepartureTime());
rideRequestRepository.save(rideRequest);
}
public List<RideRequestDto> getNearbyRideRequests(double latitude, double longitude) {
List<RideRequest> rideRequests = rideRequestRepository.findByLocationNear(latitude, longitude);
// Convert RideRequest to RideRequestDto and return
}
}


特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


举报收藏 0评论 0
0相关评论
相关最新动态
推荐最新动态
点击排行
{
网站首页  |  关于我们  |  联系方式  |  使用协议  |  隐私政策  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号