110 lines
2.8 KiB
Go
110 lines
2.8 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.ElementVO) *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
|
|
}
|
|
|
|
func (c *level) Choose(ctx context.Context, req *dto.ChooseReq) (*dto.ChooseRes, error) {
|
|
node, settle, err := service.Level.Choose(ctx, auth.GetUid(ctx), req.ChildId, req.LevelId, req.NodeId, req.OptionId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.ChooseRes{}
|
|
if node != nil {
|
|
vo := nodeVO(node)
|
|
res.Next = &vo
|
|
}
|
|
if settle != nil {
|
|
res.Final = &dto.FinalSettle{
|
|
ResultType: settle.ResultType,
|
|
Stars: settle.Stars,
|
|
ScoreDelta: settle.ScoreDelta,
|
|
Cleared: settle.Cleared,
|
|
Perfect: settle.Perfect,
|
|
UnlockNext: settle.UnlockNext,
|
|
CollectionUnlocked: settle.CollectionUnlocked,
|
|
NewLevel: settle.NewLevel,
|
|
BalanceAfter: settle.BalanceAfter,
|
|
}
|
|
if settle.FinalNode != nil {
|
|
vo := nodeVO(settle.FinalNode)
|
|
res.Final.FinalNode = &vo
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|