Browse Source

新建作业接口完成

majun
majun 5 months ago
parent
commit
bf09c9569f
  1. 15
      link_homework/api/v1/homework/homework.go
  2. 1
      link_homework/internal/cmd/cmd.go
  3. 21
      link_homework/internal/controller/homework/homework.go
  4. 47
      link_homework/internal/logic/homework/homework.go
  5. 2
      link_homework/internal/model/entity/activity_interactive_group.go
  6. 2
      link_homework/internal/service/homework.go

15
link_homework/api/v1/homework/homework.go

@ -1,6 +1,21 @@
package homework package homework
import (
"github.com/gogf/gf/v2/os/gtime"
"link_homework/internal/model/entity"
)
type GetHomeworkListReq struct { type GetHomeworkListReq struct {
PageNo int `v:"required#页码不能为空" dc:"页码"` PageNo int `v:"required#页码不能为空" dc:"页码"`
PageSize int `v:"required#页面大小不能为空" dc:"页面大小"` PageSize int `v:"required#页面大小不能为空" dc:"页面大小"`
} }
type AddHomeworkReq struct {
Name string `v:"required#作业名称不能为空" dc:"作业名称"`
ClubType int `v:"required|min:1|max:9#作业所属不能为空|作业所属不存在|作业所属不存在" dc:"作业所属"`
ArticleId int `v:"required-without:LiveId|min:1#请选择关联的文章或直播|关联文章不存在" dc:"关联文章id"`
LiveId int `v:"required-without:ArticleId|min:1#请选择关联的文章或直播|关联直播不存在" dc:"关联直播id"`
StartDate *gtime.Time `v:"required#作业开始时间不能为空" dc:"作业开始时间"`
EndDate *gtime.Time `v:"required#作业结束时间不能为空" dc:"作业结束时间"`
Questions []*entity.ActivityInteractiveForm `v:"required#题目集不能为空" dc:"题目集"`
}

1
link_homework/internal/cmd/cmd.go

@ -44,6 +44,7 @@ var (
group.POST("/get-homework-list", homework.Homework().GetHomeworkList) group.POST("/get-homework-list", homework.Homework().GetHomeworkList)
group.ALL("/get-article-list", article.Article().GetArticleList) group.ALL("/get-article-list", article.Article().GetArticleList)
group.ALL("/get-live-list", live.Live().GetLiveList) group.ALL("/get-live-list", live.Live().GetLiveList)
group.POST("/add-homework", homework.Homework().AddHomework)
}) })
//客户端 //客户端
s.Group("/api/homework_client", func(group *ghttp.RouterGroup) { s.Group("/api/homework_client", func(group *ghttp.RouterGroup) {

21
link_homework/internal/controller/homework/homework.go

@ -34,3 +34,24 @@ func (c cHomework) GetHomeworkList(r *ghttp.Request) {
Data: res, Data: res,
}) })
} }
func (c cHomework) AddHomework(r *ghttp.Request) {
var req *homework.AddHomeworkReq
if err := r.Parse(&req); err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
err := service.Homework().AddHomework(r.Context(), req)
if err != nil {
r.Response.WriteJsonExit(dto.Result{
Code: 400,
Message: err.Error(),
})
}
r.Response.WriteJsonExit(dto.Result{
Code: 200,
Message: "success",
})
}

47
link_homework/internal/logic/homework/homework.go

@ -2,8 +2,11 @@ package homework
import ( import (
"context" "context"
"fmt"
"github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/os/gtime"
"link_homework/api/v1/homework"
"link_homework/internal/dao" "link_homework/internal/dao"
"link_homework/internal/model/do"
"link_homework/internal/model/entity" "link_homework/internal/model/entity"
"link_homework/internal/service" "link_homework/internal/service"
) )
@ -34,3 +37,47 @@ func (s *sHomework) GetHomeworkList(ctx context.Context, pageNo int, pageSize in
} }
return return
} }
func (s *sHomework) AddHomework(ctx context.Context, req *homework.AddHomeworkReq) (err error) {
status := 0
if req.StartDate.Before(gtime.Now()) {
if req.EndDate.Before(gtime.Now()) {
status = 2
} else {
status = 1
}
}
var Id int64
if req.ArticleId == 0 {
Id, err = dao.ActivityInteractiveGroup.Ctx(ctx).Data(do.ActivityInteractiveGroup{
Name: req.Name,
Status: status,
ClubType: req.ClubType,
LiveId: req.LiveId,
StartDate: req.StartDate,
EndDate: req.EndDate,
}).InsertAndGetId()
} else if req.LiveId == 0 {
Id, err = dao.ActivityInteractiveGroup.Ctx(ctx).Data(do.ActivityInteractiveGroup{
Name: req.Name,
Status: status,
ClubType: req.ClubType,
ArticleId: req.ArticleId,
StartDate: req.StartDate,
EndDate: req.EndDate,
}).InsertAndGetId()
} else {
return fmt.Errorf("不能同时关联文章和直播!")
}
for _, v := range req.Questions {
_, err = dao.ActivityInteractiveForm.Ctx(ctx).Data(do.ActivityInteractiveForm{
Name: req.Name,
Description: v.Description,
Content: v.Content,
Status: status,
Type: v.Type,
GroupId: Id,
}).Insert()
}
return
}

2
link_homework/internal/model/entity/activity_interactive_group.go

@ -20,7 +20,7 @@ type ActivityInteractiveGroup struct {
LiveId int `json:"liveId" orm:"live_id" description:"关联直播id"` // 关联直播id LiveId int `json:"liveId" orm:"live_id" description:"关联直播id"` // 关联直播id
StartDate *gtime.Time `json:"startDate" orm:"start_date" description:"作业开始时间"` // 作业开始时间 StartDate *gtime.Time `json:"startDate" orm:"start_date" description:"作业开始时间"` // 作业开始时间
EndDate *gtime.Time `json:"endDate" orm:"end_date" description:"作业结束时间"` // 作业结束时间 EndDate *gtime.Time `json:"endDate" orm:"end_date" description:"作业结束时间"` // 作业结束时间
Article *FxArticle `json:"article" orm:"with:id=article_id" description:"关联文章"` // 关联文章
Article *FxArticle `json:"article" description:"关联文章"` // 关联文章
Live *Live `json:"live" orm:"with:id=live_id" description:"关联直播"` // 关联直播 Live *Live `json:"live" orm:"with:id=live_id" description:"关联直播"` // 关联直播
Count int `json:"count" description:"作业提交次数"` // 作业结束时间 Count int `json:"count" description:"作业提交次数"` // 作业结束时间
} }

2
link_homework/internal/service/homework.go

@ -7,12 +7,14 @@ package service
import ( import (
"context" "context"
"link_homework/api/v1/homework"
"link_homework/internal/model/entity" "link_homework/internal/model/entity"
) )
type ( type (
IHomework interface { IHomework interface {
GetHomeworkList(ctx context.Context, pageNo int, pageSize int) (homeworkList []*entity.ActivityInteractiveGroup, err error) GetHomeworkList(ctx context.Context, pageNo int, pageSize int) (homeworkList []*entity.ActivityInteractiveGroup, err error)
AddHomework(ctx context.Context, req *homework.AddHomeworkReq) (err error)
} }
) )

Loading…
Cancel
Save