package com.red.circle.console.adapter.app.team;

import com.red.circle.console.app.dto.clienobject.team.TeamNoticeCO;
import com.red.circle.console.app.service.app.team.TeamNoticeBackService;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.team.TeamNoticeCmd;
import com.red.circle.tool.core.date.TimestampUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 团队通知.
 *
 * @author pengshigang on 2022/12/15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/team/notice")
public class TeamNoticeRestController extends BaseController {

  private final TeamNoticeBackService teamNoticeBackService;

  /**
   * 列表查询.
   */
  @GetMapping("/list/{teamId}")
  public List<TeamNoticeCO> listByTeamId(@PathVariable("teamId") Long teamId) {
    return teamNoticeBackService.listByTeamId(teamId);
  }

  /**
   * 发送团队通知.
   */
  @PostMapping("/send")
  public void send(@RequestBody @Validated TeamNoticeCmd param) {
    param.setCreateUser(param.getReqUserId());
    param.setCreateTime(TimestampUtils.now());
    teamNoticeBackService.send(param);
  }

  /**
   * 删除团队通知.
   */
  @GetMapping("/delete/{id}")
  public void deleteById(@PathVariable("id") Long id) {
    teamNoticeBackService.deleteById(id);
  }

}
