package com.antsoft.yecai.controller;

import com.antsoft.yecai.service.UserService;
import com.antsoft.yecai.service.UserVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by ant on 2015/9/14.
 */
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    private UserVehicleService userVehicleService;

    @RequestMapping(value = "/gift", method = RequestMethod.POST)
    public void gift(@RequestParam(value = "userId") String userId) {
        userVehicleService.gift(userId);
    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public void create(@RequestParam(value = "userId") String userId,
                       @RequestParam(value = "num", required = false, defaultValue = "-1") int num) {
        String vehicle;
        if (num == -1) {
            vehicle = userVehicleService.randomVehicle();
        } else {
            vehicle = userVehicleService.toVehicle(num);
        }
        userVehicleService.create(userId, vehicle);
    }
}

@@ -1136,12 +1136,221 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    @RequestMapping(value = %22/getVehicles%22, method = RequestMethod.GET)%0D%0A    public void getVehicles(@RequestParam(value = %22userId%22) String userId) %7B%0D%0A        userVehicleService.getVehicles(userId);%0D%0A    %7D%0D
 %0A%7D%0D%0A

support query user vehicles