我是靠谱客的博主 悦耳音响,这篇文章主要介绍15-在线学习接口-服务端开发-学习服务接口开发-16-认证接口开发-Api接口定义,现在分享给大家,希望可以做个参考。

3.4.3 搜索服务客户端

在学习服务创建搜索服务的客户端接口,此接口会生成代理对象,调用搜索服务:

复制代码
1
2
3
4
5
6
7
8
9
10
package com.xuecheng.learning.client; import com.xuecheng.api.search.EsCourseControllerApi; import com.xuecheng.framework.client.XcServiceList; import org.springframework.cloud.netflix.feign.FeignClient; @FeignClient(value = "xc‐service‐search") public interface CourseSearchClient { @GetMapping(value="/getmedia/{teachplanId}") public TeachplanMediaPub getmedia(@PathVariable("teachplanId") String teachplanId); }

在这里插入图片描述
在这里插入图片描述

3.4.4 Service
在学习服务中定义service方法,此方法远程请求课程管理服务、媒资管理服务获取课程学习地址。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Service public class LearningService { @Autowired CourseSearchClient courseSearchClient; //获取课程 public GetMediaResult getMedia(String courseId, String teachplanId) { //校验学生的学习权限。。是否资费等 //调用搜索服务查询 TeachplanMediaPub teachplanMediaPub = courseSearchClient.getmedia(teachplanId); if(teachplanMediaPub == null || StringUtils.isEmpty(teachplanMediaPub.getMediaUrl())){ //获取视频播放地址出错 ExceptionCast.cast(LearningCode.LEARNING_GETMEDIA_ERROR); } return new GetMediaResult(CommonCode.SUCCESS,teachplanMediaPub.getMediaUrl()); } }

在这里插入图片描述
在这里插入图片描述

3.4.5 Controller
调用service根据课程计划id查询视频播放地址:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@RestController @RequestMapping("/learning/course") public class CourseLearningController implements CourseLearningControllerApi { @Autowired LearningService learningService; @Override @GetMapping("/getmedia/{courseId}/{teachplanId}") public GetMediaResult getmedia(@PathVariable String courseId, @PathVariable String teachplanId) { //获取课程学习地址 return learningService.getMedia(courseId, teachplanId); } }

在这里插入图片描述
启动mysql
启动elasticsearch
启动
在这里插入图片描述

启动LearningApplication服务
启动SearchApplication服务
在这里插入图片描述

在这里插入图片描述

3.4.6 测试
使用swagger-ui或postman测试学习服务查询课程视频地址接口。
在这里插入图片描述
这个我测试多次终于成功
在这里插入图片描述

在这里插入图片描述
测试过程中出现的问题
在这里插入图片描述

最后

以上就是悦耳音响最近收集整理的关于15-在线学习接口-服务端开发-学习服务接口开发-16-认证接口开发-Api接口定义的全部内容,更多相关15-在线学习接口-服务端开发-学习服务接口开发-16-认证接口开发-Api接口定义内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部