package com.cloudroam.controller.v1; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.cloudroam.bo.ContactInfoBO; import com.cloudroam.bo.EmailSmtpSettingBO; import com.cloudroam.common.util.PageUtil; import com.cloudroam.dto.contact.QueryContactDTO; import com.cloudroam.dto.emailSmtp.CreateOrUpdateEmailSmtpDTO; import com.cloudroam.dto.emailSmtp.QueryEmailSmtpDTO; import com.cloudroam.model.ContactInfoDO; import com.cloudroam.service.EmailSmtpSettingService; import io.github.talelin.autoconfigure.exception.NotFoundException; import io.github.talelin.core.annotation.Logger; import io.github.talelin.core.annotation.LoginRequired; import io.github.talelin.core.annotation.PermissionMeta; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import com.cloudroam.model.EmailSmtpSettingDO; import com.cloudroam.vo.CreatedVO; import com.cloudroam.vo.DeletedVO; import com.cloudroam.vo.PageResponseVO; import com.cloudroam.vo.UpdatedVO; import javax.validation.constraints.Min; import javax.validation.constraints.Max; import javax.validation.constraints.Positive; /** * 邮箱配置表前端控制器 * * @author generator@TaoJie * @since 2023-08-15 */ @RestController @RequestMapping("/v1/email-smtp-setting") public class EmailSmtpSettingController { @Autowired private EmailSmtpSettingService emailSmtpSettingService; @PostMapping("") @LoginRequired @PermissionMeta(value = "邮箱创建", module = "邮箱配置",mount = false) @Logger(template = "{user.nickname} 创建了邮箱 ") public CreatedVO create(@RequestBody @Validated CreateOrUpdateEmailSmtpDTO validator) { emailSmtpSettingService.createEmailSmtp(validator); return new CreatedVO(); } @PutMapping("/{id}") @LoginRequired @PermissionMeta(value = "邮箱配置编辑", module = "邮箱配置",mount = false) @Logger(template = "{user.nickname} 编辑了邮箱配置 ") public UpdatedVO update(@PathVariable String id,@RequestBody @Validated CreateOrUpdateEmailSmtpDTO validator) { if(StrUtil.isBlank(id)){ throw new NotFoundException("传入的Id不能为空"); } EmailSmtpSettingDO emailSmtpSettingDO = emailSmtpSettingService.getById(id); if(emailSmtpSettingDO == null){ throw new NotFoundException("记录不存在"); } emailSmtpSettingService.updateEmailSmtpSetting(validator); return new UpdatedVO(); } @DeleteMapping("/{id}") @LoginRequired @PermissionMeta(value = "邮箱配置删除", module = "邮箱配置",mount = false) @Logger(template = "{user.nickname} 删除了邮箱配置 ") public DeletedVO delete(@PathVariable String id) { if(StrUtil.isBlank(id)){ throw new NotFoundException("id不能为空"); } EmailSmtpSettingDO emailSmtpSettingDO = emailSmtpSettingService.getById(id); if (emailSmtpSettingDO == null) { throw new NotFoundException("记录不存在"); } emailSmtpSettingService.removeByIdLogic(id); return new DeletedVO(); } @GetMapping("/{id}") public EmailSmtpSettingDO get(@PathVariable(value = "id") String id) { if(StrUtil.isBlank(id)){ throw new NotFoundException("id不能为空"); } EmailSmtpSettingDO emailSmtpSettingDO = emailSmtpSettingService.getById(id); if (emailSmtpSettingDO == null) { throw new NotFoundException("记录不存在"); } return emailSmtpSettingDO; } @GetMapping("/page") @LoginRequired @PermissionMeta(value = "邮箱配置列表", module = "邮箱配置",mount = true) @Logger(template = "{user.nickname} 查看邮箱配置列表 ") public PageResponseVO page( @Validated QueryEmailSmtpDTO dto ) { IPage iPage=emailSmtpSettingService.getEmailSmtpSettingPage(dto); return PageUtil.build(iPage); } }