package com.remy.goods.controller;

import com.remy.goods.entity.Goods;
import com.remy.goods.service.GoodsService;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("goods")
public class GoodsServiceController {

    @Autowired
    private GoodsService goodsService;

    @RequestMapping()
    public List<Goods> findAll() {
        return goodsService.findAll();
    }

    @RequestMapping("{serialNo}")
    public Goods findBySerialNo(@PathVariable("serialNo") String serialNo) {
        return goodsService.findBySerialNo(serialNo);
    }

    @PostMapping()
    public Goods save(@RequestBody Goods goods) {
        goods.setSerialNo(RandomStringUtils.randomAlphanumeric(8));
        return goodsService.save(goods);
    }
}
