Parcourir la source

fix:培训考试添加移动端资料列表接口

liuyaqi il y a 3 ans
Parent
commit
7953a2e0b6

+ 20 - 0
handler/learning/material.go

@@ -35,6 +35,26 @@ func (c *LearningMaterial) List(ctx context.Context, req *learning.LearningMater
 	return nil
 }
 
+func (c *LearningMaterial) ListMy(ctx context.Context, req *learning.LearningMaterialListMyReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningMaterial.ListMy request %#v ", *req)
+	s, err := learningSrv.NewLearningMaterialService(ctx)
+	if err != nil {
+		return err
+	}
+	ent, err := s.ListMy(ctx, req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*learning.LearningMaterialListMy{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = ent
+	return nil
+}
+
 func (c *LearningMaterial) Get(ctx context.Context, req *learning.LearningMaterialGetReq, rsp *comm_def.CommonMsg) error {
 	g.Log().Infof("LearningMaterial.Get request %#v ", *req)
 	s, err := learningSrv.NewLearningMaterialService(ctx)

+ 9 - 0
model/learning/learning_material.go

@@ -20,6 +20,15 @@ type LearningMaterialListReq struct {
 	Name    string         `json:"name"`
 }
 
+type LearningMaterialListMyReq struct {
+	SkillId int `json:"skillId" v:"required#请输入技能Id"` // 技能 Id
+}
+
+type LearningMaterialListMy struct {
+	LearningMaterial
+	Learnt bool `json:"learnt"` // 是否已学习
+}
+
 type LearningMaterialGetReq struct {
 	Id   int    `json:"id"`   // 资料Id
 	Name string `json:"name"` // 资料名称

+ 28 - 0
service/learning/material.go

@@ -113,6 +113,34 @@ func (s LearningMaterialService) List(ctx context.Context, req *learning.Learnin
 	return total, ent, err
 }
 
+func (s LearningMaterialService) ListMy(ctx context.Context, req *learning.LearningMaterialListMyReq) ([]*learning.LearningMaterialListMy, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return nil, myerrors.NewMsgError(nil, validErr.Current().Error())
+	}
+
+	ent, err := s.Dao.Where("SkillId = ?", req.SkillId).All()
+	if err != nil {
+		return nil, err
+	}
+	list := []*learning.LearningMaterialListMy{}
+	for _, m := range ent {
+		lr, err := s.LearningRecordDao.Where("MaterialId = ?", m.Id).One()
+		if err != nil {
+			return nil, err
+		}
+		learnt := true
+		if lr == nil {
+			learnt = false
+		}
+		list = append(list, &learning.LearningMaterialListMy{
+			LearningMaterial: *m,
+			Learnt:           learnt,
+		})
+	}
+	return list, nil
+}
+
 func (s LearningMaterialService) Add(ctx context.Context, req *learning.LearningMaterialAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {

+ 36 - 0
swaggerui/swagger.yml

@@ -205,6 +205,31 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningMaterial.ListMy:
+      post:
+        tags:
+          - 考试培训-资料
+        operationId: LearningMaterialListMy
+        summary: 我的资料
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningMaterialListMy'
+              examples:
+                LearningMaterialListMy:
+                  $ref: '#/components/examples/LearningMaterialListMy'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
     /LearningMaterial.Get:
       post:
         tags:
@@ -901,6 +926,14 @@ components:
         name:
           type: string
           description: 按资料名称模糊查询
+    LearningMaterialListMy:
+      type: object
+      required:
+        - skillId
+      properties:
+        skillId:
+          type: integer
+          description: 按技能 Id 查询
     LearningMaterialGet:
       type: object
       properties:
@@ -1421,6 +1454,9 @@ components:
           value: id
         skillId: 2
         name: "测试"
+    LearningMaterialListMy:
+      value:
+        skillId: 2
     LearningMaterialGet:
       value:
         id: 1