package com.kxs.user.biz.controller.kxsapp;

import com.kxs.common.core.util.R;
import com.kxs.user.api.dto.kxsapp.userAddress.UserAddressDTO;
import com.kxs.user.api.model.KxsUserAddress;
import com.kxs.user.biz.service.KxsUserAddressService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户相关(UserAddress)控制层
 *
 * @author 系统
 * @since 2024-01-03 09:39:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("userAddress")
public class UserAddressController {

    /**
     * 服务对象
     */
    private final KxsUserAddressService kxsUserAddressService;



    /**
     * 设置-收货地址-列表
     *
     * @return 设置-收货地址-列表
     */
    @GetMapping("/list")
    public R list() {
        return R.ok(kxsUserAddressService.userAddressList());
    }


    /**
     * 设置-收货地址-删除
     *
     * @param address 主键ID
     * @return 设置-收货地址-删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody KxsUserAddress address) {

        return R.ok(kxsUserAddressService.removeById(address.getId()));
    }


    /**
     * 设置-收货地址-新增/修改
     *
     * @param param 实体对象
     * @return 设置-收货地址-新增/修改
     */
    @PostMapping("/save")
    public R save(@Valid @RequestBody UserAddressDTO param) {
        return kxsUserAddressService.userAddressSave(param);
    }


    /**
     * 设置-收货地址-详情
     *
     * @param id 主键ID
     * @return 设置-收货地址-详情
     */
    @GetMapping("/detail")
    public R detail(@RequestParam("id") Integer id) {

        return R.ok(kxsUserAddressService.getById(id));
    }


}

