Skip to content

Commit

Permalink
feat: impl SearchNewAppInfos
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Mar 6, 2024
1 parent 2b8d9f1 commit 7c28bbe
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/sephirah/cmd/sephirah/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions app/sephirah/internal/biz/bizgebura/app_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"strconv"

"github.com/tuihub/librarian/app/sephirah/internal/biz/bizutils"
"github.com/tuihub/librarian/app/sephirah/internal/model/converter"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelangela"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelgebura"
"github.com/tuihub/librarian/internal/lib/libauth"
"github.com/tuihub/librarian/internal/model"
porter "github.com/tuihub/protos/pkg/librarian/porter/v1"
searcherpb "github.com/tuihub/protos/pkg/librarian/searcher/v1"
pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"

Expand Down Expand Up @@ -147,6 +149,34 @@ func (g *Gebura) SearchAppInfos(ctx context.Context, paging model.Paging, query
return res, 0, nil
}

func (g *Gebura) SearchNewAppInfos(
ctx context.Context,
paging model.Paging,
name string,
sourceFilter []string,
) ([]*modelgebura.AppInfo, int, *errors.Error) {
if libauth.FromContextAssertUserType(ctx) == nil {
return nil, 0, bizutils.NoPermissionError()
}
if len(sourceFilter) == 0 {
sourceFilter = g.supv.GetFeatureSummary().SupportedAppInfoSources
}
if len(sourceFilter) == 0 {
return nil, 0, pb.ErrorErrorReasonBadRequest("no available info source")
}
var infos []*modelgebura.AppInfo
for _, source := range sourceFilter {
info, err := g.porter.SearchAppInfo(g.supv.CallAppInfoSource(ctx, source), &porter.SearchAppInfoRequest{
Name: name,
})
if err != nil {
continue
}
infos = append(infos, converter.ToBizAppInfoList(info.GetAppInfos())...)
}
return infos, 0, nil
}

func (g *Gebura) GetAppInfo(ctx context.Context, id model.InternalID) (*modelgebura.AppInfo, *errors.Error) {
if libauth.FromContextAssertUserType(ctx) == nil {
return nil, bizutils.NoPermissionError()
Expand Down
8 changes: 8 additions & 0 deletions app/sephirah/internal/biz/bizgebura/gebura.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/tuihub/librarian/app/sephirah/internal/client"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelangela"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelgebura"
"github.com/tuihub/librarian/app/sephirah/internal/supervisor"
"github.com/tuihub/librarian/internal/lib/libauth"
"github.com/tuihub/librarian/internal/lib/libcache"
"github.com/tuihub/librarian/internal/lib/libmq"
"github.com/tuihub/librarian/internal/model"
porter "github.com/tuihub/protos/pkg/librarian/porter/v1"

"github.com/go-kratos/kratos/v2/errors"
)
Expand Down Expand Up @@ -53,6 +55,8 @@ type Gebura struct {
repo GeburaRepo
// mapper mapper.LibrarianMapperServiceClient
searcher *client.Searcher
porter porter.LibrarianPorterServiceClient
supv *supervisor.Supervisor
updateAppInfoIndex *libmq.Topic[modelangela.UpdateAppInfoIndex]
pullAppInfo *libmq.Topic[modelangela.PullAppInfo]
appInfoCache *libcache.Map[modelgebura.AppInfoID, modelgebura.AppInfo]
Expand All @@ -63,6 +67,8 @@ func NewGebura(
auth *libauth.Auth,
// mClient mapper.LibrarianMapperServiceClient,
sClient *client.Searcher,
pClient porter.LibrarianPorterServiceClient,
supv *supervisor.Supervisor,
updateAppIndex *libmq.Topic[modelangela.UpdateAppInfoIndex],
pullAppInfo *libmq.Topic[modelangela.PullAppInfo],
appInfoCache *libcache.Map[modelgebura.AppInfoID, modelgebura.AppInfo],
Expand All @@ -72,6 +78,8 @@ func NewGebura(
repo: repo,
//mapper: mClient,
searcher: sClient,
porter: pClient,
supv: supv,
updateAppInfoIndex: updateAppIndex,
pullAppInfo: pullAppInfo,
appInfoCache: appInfoCache,
Expand Down
3 changes: 3 additions & 0 deletions app/sephirah/internal/model/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func ToBizDeviceInfo(a *pb.DeviceInfo) *modeltiphereth.DeviceInfo {
func ToBizAppInfo(a *librarian.AppInfo) *modelgebura.AppInfo {
return toBiz.ToBizAppInfo(a)
}
func ToBizAppInfoList(a []*librarian.AppInfo) []*modelgebura.AppInfo {
return toBiz.ToBizAppInfoList(a)
}
func ToBizAppInfoID(a *librarian.AppInfoID) *modelgebura.AppInfoID {
return toBiz.ToBizAppInfoID(a)
}
Expand Down
10 changes: 10 additions & 0 deletions app/sephirah/internal/model/converter/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/sephirah/internal/model/converter/pb_to_biz.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type toBizConverter interface { //nolint:unused // used by generator
// goverter:ignore BoundInternal
// goverter:ignore LatestUpdateTime
ToBizAppInfo(*librarian.AppInfo) *modelgebura.AppInfo
ToBizAppInfoList([]*librarian.AppInfo) []*modelgebura.AppInfo
// goverter:matchIgnoreCase
ToBizAppInfoDetail(*librarian.AppInfoDetails) *modelgebura.AppInfoDetails
ToBizAppTypeList([]librarian.AppType) []modelgebura.AppType
Expand Down
16 changes: 16 additions & 0 deletions app/sephirah/internal/service/gebura.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ func (s *LibrarianSephirahServiceService) SearchAppInfos(ctx context.Context, re
AppInfos: converter.ToPBAppInfoMixedList(infos),
}, nil
}
func (s *LibrarianSephirahServiceService) SearchNewAppInfos(ctx context.Context, req *pb.SearchNewAppInfosRequest) (
*pb.SearchNewAppInfosResponse, error,
) {
infos, total, err := s.g.SearchNewAppInfos(ctx,
model.ToBizPaging(req.GetPaging()),
req.GetName(),
req.GetSourceFilter(),
)
if err != nil {
return nil, err
}
return &pb.SearchNewAppInfosResponse{
Paging: &librarian.PagingResponse{TotalSize: int64(total)},
AppInfos: converter.ToPBAppInfoList(infos),
}, nil
}
func (s *LibrarianSephirahServiceService) GetAppInfo(ctx context.Context, req *pb.GetAppInfoRequest) (
*pb.GetAppInfoResponse, error,
) {
Expand Down
2 changes: 1 addition & 1 deletion app/sephirah/pkg/service/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c28bbe

Please sign in to comment.