80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"36wisdom/biz/model/dto"
|
|
"36wisdom/biz/service"
|
|
"36wisdom/common/auth"
|
|
)
|
|
|
|
type level struct{}
|
|
|
|
var Level = &level{}
|
|
|
|
func (c *level) Detail(ctx context.Context, req *dto.LevelDetailReq) (*dto.LevelDetailRes, error) {
|
|
detail, err := service.Level.Detail(ctx, auth.GetUid(ctx), req.ChildId, req.LevelId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.LevelDetailRes{
|
|
LevelId: detail.LevelId,
|
|
Title: detail.Title,
|
|
Scene: elementVO(detail.Scene),
|
|
SceneContent: detail.SceneContent,
|
|
SceneContentPinyin: detail.SceneContentPinyin,
|
|
SceneImage: detail.SceneImage,
|
|
SceneAudio: detail.SceneAudio,
|
|
Entry: nodeVO(detail.Entry),
|
|
TotalFinals: detail.TotalFinals,
|
|
Perfect: detail.Perfect,
|
|
Stars: detail.Stars,
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func elementVO(e *service.Element) *dto.ElementVO {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
return &dto.ElementVO{
|
|
Id: e.Id,
|
|
EType: e.EType,
|
|
Name: e.Name,
|
|
NamePinyin: e.NamePinyin,
|
|
Image: e.Image,
|
|
Audio: e.Audio,
|
|
Description: e.Description,
|
|
}
|
|
}
|
|
|
|
func nodeVO(n *service.Node) dto.NodeVO {
|
|
vo := dto.NodeVO{
|
|
NodeId: n.NodeId,
|
|
Title: n.Title,
|
|
Content: n.Content,
|
|
ContentPinyin: n.ContentPinyin,
|
|
Image: n.Image,
|
|
Audio: n.Audio,
|
|
Character: elementVO(n.Character),
|
|
InteractionType: n.InteractionType,
|
|
Config: n.Config,
|
|
Script: n.Script,
|
|
NodeType: n.NodeType,
|
|
ResultType: n.ResultType,
|
|
Options: make([]dto.OptionVO, 0, len(n.Options)),
|
|
}
|
|
for _, o := range n.Options {
|
|
vo.Options = append(vo.Options, dto.OptionVO{
|
|
OptionId: o.OptionId,
|
|
Text: o.Text,
|
|
TextPinyin: o.TextPinyin,
|
|
FeedbackPros: o.FeedbackPros,
|
|
FeedbackCons: o.FeedbackCons,
|
|
Audio: o.Audio,
|
|
Prop: elementVO(o.Prop),
|
|
})
|
|
}
|
|
return vo
|
|
}
|