You've already forked FrameTour-BE
feat(mobile): 添加移动端模板接口
- 实现了 AppTemplateController 控制器 - 添加了根据模板ID获取封面URL的接口 - 集成了 TemplateRepository 数据访问层 - 实现了模板ID参数校验逻辑 - 添加了模板不存在的错误处理 - 实现了封面URL为空的验证机制
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
package com.ycwl.basic.controller.mobile;
|
||||||
|
|
||||||
|
import com.ycwl.basic.mapper.TemplateMapper;
|
||||||
|
import com.ycwl.basic.model.pc.template.entity.TemplateEntity;
|
||||||
|
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
|
||||||
|
import com.ycwl.basic.repository.TemplateRepository;
|
||||||
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动端模板接口
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/mobile/template/v1")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AppTemplateController {
|
||||||
|
|
||||||
|
private final TemplateRepository templateRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模板ID获取封面URL
|
||||||
|
*
|
||||||
|
* @param templateId 模板ID
|
||||||
|
* @return 模板封面URL
|
||||||
|
*/
|
||||||
|
@GetMapping("/cover/{templateId}")
|
||||||
|
public ApiResponse<String> getTemplateCoverUrl(@PathVariable("templateId") Long templateId) {
|
||||||
|
if (templateId == null) {
|
||||||
|
return ApiResponse.fail("模板ID不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateRespVO template = templateRepository.getTemplate(templateId);
|
||||||
|
if (template == null) {
|
||||||
|
return ApiResponse.fail("未找到对应的模板");
|
||||||
|
}
|
||||||
|
|
||||||
|
String coverUrl = template.getCoverUrl();
|
||||||
|
if (coverUrl == null || coverUrl.isEmpty()) {
|
||||||
|
return ApiResponse.fail("该模板没有封面地址");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiResponse.success(coverUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user