package com.pcloud.book.applet.service.impl;

import com.pcloud.book.applet.biz.AppletNewsBiz;
import com.pcloud.book.applet.dto.AppletNewsVO;
import com.pcloud.book.applet.dto.PcloudGroupActivityDTO;
import com.pcloud.book.applet.service.AppletService;
import com.pcloud.book.skill.biz.PcloudGroupActivityBiz;
import com.pcloud.book.skill.entity.PcloudGroupActivity;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.utils.ResponseHandleUtil;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName com.pcloud.book.applet.service.impl.AppletServiceImpl
 * @Author zhuyajie
 * @Description 小程序内部服务
 * @Date 2020/4/26 20:04
 * @Version 1.0
 **/
@RestController("appletService")
@RequestMapping("appletService")
public class AppletServiceImpl implements AppletService {

    @Autowired
    private AppletNewsBiz appletNewsBiz;

    @Autowired
    private PcloudGroupActivityBiz pcloudGroupActivityBiz;


    @Override
    @GetMapping("getNewsById")
    public ResponseEntity<ResponseDto<AppletNewsVO>> getNewsById(Long newsId) {
        return ResponseHandleUtil.toResponse(appletNewsBiz.getNewsVOById(newsId));
    }

    @Override
    @GetMapping("getGroupActivityById")
    public ResponseEntity<ResponseDto<PcloudGroupActivityDTO>> getGroupActivityById(@RequestParam("id") Long id){
        PcloudGroupActivity pcloudGroupActivity = pcloudGroupActivityBiz.getById(id);
        PcloudGroupActivityDTO newData = new PcloudGroupActivityDTO();
        BeanUtils.copyProperties(pcloudGroupActivity,newData);
        return ResponseHandleUtil.toResponse(newData);
    }
}
