package com.playlet.web.controller.app;

import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PlayletPublicUser;
import com.playlet.web.service.app.PlayletPublicUserAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "公众号*用户接口")
@RestController
@RequestMapping(value = "/app/public/user")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletPublicUserAppController {

    private final PlayletPublicUserAppService publicUserAppService;

    /**
     * 新增公众号用户信息
     */
    @ResponseBody
    @PostMapping("/add")
    @ApiOperation(value = "新增公众号用户信息")
    public Result<PlayletPublicUser> addSave(@RequestBody PlayletPublicUser publicUser) {
        return Result.success(publicUserAppService.addPublicUser(publicUser));
    }

    @ResponseBody
    @ApiOperation(value = "查询公众号用户信息")
    @PostMapping("/findByUnionIdAndPublicId")
    public Result<PlayletPublicUser> findByUnionIdAndPublicId(@RequestBody PlayletPublicUser publicUser) {
        PlayletPublicUser user = publicUserAppService.findByUnionIdAndPublicId(publicUser);
        return Result.success(user);
    }

}
