package sgc.portal.cw.cw0103.web;

import org.springframework.web.bind.annotation.*;

import sgc.portal.base.util.AddressUtils;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.cw.cw0103.dto.CW01030001USearch;
import sgc.portal.cw.cw0103.model.CW01030001U;
import sgc.portal.cw.cw0103.service.CW01030001UService;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/cw/cw0103")
public class CW01030001UController {
    private final CW01030001UService service;

    public CW01030001UController(CW01030001UService service) {
        this.service = service;
    }

    @PostMapping("/CW01030001U/list")
    public List<EasyHashMap<String, Object>> getList(@RequestBody CW01030001USearch search) {
        return service.getList(search);
    }

    @PostMapping("/CW01030001U/save")
    public Map<String, String> save(@RequestBody List<CW01030001U> CW01030001U, HttpServletRequest request) {
    	for (CW01030001U cW01030001U : CW01030001U) {
    		cW01030001U.setAgreeIp(AddressUtils.getIpAddress(request));
        }
    	return service.save(CW01030001U);
    }
}
