mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "lunar-tear/server/gen/proto"
|
||||
"lunar-tear/server/internal/model"
|
||||
"lunar-tear/server/internal/store"
|
||||
"lunar-tear/server/internal/userdata"
|
||||
)
|
||||
|
||||
type BannerServiceServer struct {
|
||||
pb.UnimplementedBannerServiceServer
|
||||
gacha store.GachaRepository
|
||||
}
|
||||
|
||||
func NewBannerServiceServer(gacha store.GachaRepository) *BannerServiceServer {
|
||||
return &BannerServiceServer{gacha: gacha}
|
||||
}
|
||||
|
||||
func (s *BannerServiceServer) GetMamaBanner(ctx context.Context, req *pb.GetMamaBannerRequest) (*pb.GetMamaBannerResponse, error) {
|
||||
catalog, _ := s.gacha.SnapshotCatalog()
|
||||
var termLimited []*pb.GachaBanner
|
||||
var latestChapter *pb.GachaBanner
|
||||
for _, entry := range catalog {
|
||||
if entry.GachaLabelType == model.GachaLabelPortalCage || entry.GachaLabelType == model.GachaLabelRecycle {
|
||||
continue
|
||||
}
|
||||
b := &pb.GachaBanner{
|
||||
GachaLabelType: entry.GachaLabelType,
|
||||
GachaAssetName: entry.BannerAssetName,
|
||||
GachaId: entry.GachaId,
|
||||
}
|
||||
switch entry.GachaLabelType {
|
||||
case model.GachaLabelEvent, model.GachaLabelPremium:
|
||||
termLimited = append(termLimited, b)
|
||||
case model.GachaLabelChapter:
|
||||
if latestChapter == nil || entry.GachaId > latestChapter.GachaId {
|
||||
latestChapter = b
|
||||
}
|
||||
}
|
||||
}
|
||||
return &pb.GetMamaBannerResponse{
|
||||
TermLimitedGacha: termLimited,
|
||||
LatestChapterGacha: latestChapter,
|
||||
IsExistUnreadPop: false,
|
||||
DiffUserData: userdata.EmptyDiff(),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user