/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.user.platform.controller;

import com.yami.shop.bean.model.UserExtension;
import com.yami.shop.common.annotation.SysLog;

import javax.validation.Valid;

import com.yami.shop.service.UserExtensionService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 * 用户扩展信息管理实现
 *
 * @author LGH
 * @version 1.0.0
 * @since 2020-02-26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userExtension" )
public class UserExtensionController {

    private final UserExtensionService userExtensionService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userExtension 用户扩展信息
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserExtension>> getUserExtensionPage(PageParam<UserExtension> page, UserExtension userExtension) {
        return ResponseEntity.ok(userExtensionService.getPage(page,userExtension));
    }


    /**
     * 通过id查询用户扩展信息
     * @param userExtensionId id
     * @return 单个数据
     */
    @GetMapping("/info/{userExtensionId}" )
    public ResponseEntity<UserExtension> getById(@PathVariable("userExtensionId") Long userExtensionId) {
        return ResponseEntity.ok(userExtensionService.getById(userExtensionId));
    }

    /**
     * 新增用户扩展信息
     * @param userExtension 用户扩展信息
     * @return 是否新增成功
     */
    @SysLog("新增用户扩展信息" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userExtension:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserExtension userExtension) {
        return ResponseEntity.ok(userExtensionService.save(userExtension));
    }

    /**
     * 修改用户扩展信息
     * @param userExtension 用户扩展信息
     * @return 是否修改成功
     */
    @SysLog("修改用户扩展信息" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userExtension:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserExtension userExtension) {
        return ResponseEntity.ok(userExtensionService.updateById(userExtension));
    }

    /**
     * 通过id删除用户扩展信息
     * @param userExtensionId id
     * @return 是否删除成功
     */
    @SysLog("删除用户扩展信息" )
    @DeleteMapping("/{userExtensionId}" )
    @PreAuthorize("@pms.hasPermission('user:userExtension:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long userExtensionId) {
        return ResponseEntity.ok(userExtensionService.removeById(userExtensionId));
    }

}
