
package com.tmerclub.cloud.product.controller.multishop;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.product.dto.SpuCommDTO;
import com.tmerclub.cloud.product.service.SpuCommService;
import com.tmerclub.cloud.product.vo.SpuCommVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品评论
 *
 * @author YXF
 * @date 2021-01-11 13:47:33
 */
@RestController("multishopSpuCommController")
@RequestMapping("/m/spu_comm")
@Tag(name = "multishop-商品评论")
public class SpuCommController {

    @Autowired
    private SpuCommService spuCommService;


    @GetMapping("/page")
    @Operation(summary = "获取商品评论列表", description = "分页获取商品评论列表")
    public ServerResponseEntity<PageVO<SpuCommVO>> page(@Valid PageDTO pageDTO, SpuCommDTO spuCommDTO) {
        spuCommDTO.setShopId(AuthUserContext.get().getTenantId());
        PageVO<SpuCommVO> spuCommPage = spuCommService.page(pageDTO, spuCommDTO);
        return ServerResponseEntity.success(spuCommPage);
    }

    @GetMapping
    @Operation(summary = "获取商品评论", description = "根据spuCommId获取商品评论")
    public ServerResponseEntity<SpuCommVO> getBySpuCommId(@RequestParam Long spuCommId) {
        return ServerResponseEntity.success(spuCommService.getBySpuCommId(spuCommId));
    }

    @PutMapping
    @Operation(summary = "更新商品评论", description = "更新商品评论")
    public ServerResponseEntity<Void> update(@Valid @RequestBody SpuCommDTO spuComm) {
        spuCommService.update(spuComm);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除商品评论", description = "删除商品评论")
    public ServerResponseEntity<Void> deledte(@RequestParam Long spuCommId) {
        spuCommService.deleteById(spuCommId);
        return ServerResponseEntity.success();
    }
}
