MCPcopy Create free account
hub / github.com/coderwhy/coderhub / MomentController

Class MomentController

src/controller/moment.controller.js:7–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5const { PICTURE_PATH } = require('../constants/file-path');
6
7class MomentController {
8 async create(ctx, next) {
9 // 1.获取数据(user_id, content)
10 const userId = ctx.user.id;
11 const content = ctx.request.body.content;
12
13 // 2.将数据插入到数据库
14 const result = await momentService.create(userId, content);
15 ctx.body = result;
16 }
17
18 async detail(ctx, next) {
19 // 1.获取数据(momentId)
20 const momentId = ctx.params.momentId;
21
22 // 2.根据id去查询这条数据
23 const result = await momentService.getMomentById(momentId);
24 ctx.body = result;
25 }
26
27 async list(ctx, next) {
28 // 1.获取数据(offset/size)
29 const { offset, size } = ctx.query;
30
31 // 2.查询列表
32 const result = await momentService.getMomentList(offset, size);
33 ctx.body = result;
34 }
35
36 async update(ctx, next) {
37 // 1.获取参数
38 const { momentId } = ctx.params;
39 const { content } = ctx.request.body;
40
41 // 2.修改内容
42 const result = await momentService.update(content, momentId);
43 ctx.body = result;
44 }
45
46 async remove(ctx, next) {
47 // 1.获取momentId
48 const { momentId } = ctx.params;
49
50 // 2.删除内容
51 const result = await momentService.remove(momentId);
52 ctx.body = result;
53 }
54
55 async addLabels(ctx, next) {
56 // 1.获取标签和动态id
57 const { labels } = ctx;
58 const { momentId } = ctx.params;
59
60 // 2.添加所有的标签
61 for (let label of labels) {
62 // 2.1.判断标签是否已经和动态有关系
63 const isExist = await momentService.hasLabel(momentId, label.id);
64 if (!isExist) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected