11package aggregator
22
33import (
4+ "net/http"
5+
46 "github.com/labstack/echo/v4"
57 "github.com/rss3-network/node/v2/docs"
68 "github.com/rss3-network/node/v2/internal/node/component/ai"
@@ -23,51 +25,103 @@ type Component struct {
2325
2426var _ docs.ServerInterface = (* Component )(nil )
2527
28+ // emptyResponse returns an empty response with a 200 status code
29+ func emptyResponse (ctx echo.Context ) error {
30+ return ctx .JSON (http .StatusOK , map [string ]interface {}{
31+ "data" : []interface {}{},
32+ "meta" : nil ,
33+ })
34+ }
35+
2636// Decentralized Interface
2737
2838func (c Component ) PostDecentralizedAccounts (ctx echo.Context ) error {
39+ if c .Decentralized == nil {
40+ return emptyResponse (ctx )
41+ }
42+
2943 return c .Decentralized .BatchGetAccountsActivities (ctx )
3044}
3145
3246func (c Component ) PostDecentralizedMetadata (ctx echo.Context ) error {
47+ if c .Decentralized == nil {
48+ return emptyResponse (ctx )
49+ }
50+
3351 return c .Decentralized .BatchGetMetadataActivities (ctx )
3452}
3553
3654func (c Component ) GetDecentralizedNetwork (ctx echo.Context , network network.Network , params docs.GetDecentralizedNetworkParams ) error {
55+ if c .Decentralized == nil {
56+ return emptyResponse (ctx )
57+ }
58+
3759 return c .Decentralized .GetNetworkActivities (ctx , network , params )
3860}
3961
4062func (c Component ) GetDecentralizedPlatform (ctx echo.Context , platform decentralizedx.Platform , params docs.GetDecentralizedPlatformParams ) error {
63+ if c .Decentralized == nil {
64+ return emptyResponse (ctx )
65+ }
66+
4167 return c .Decentralized .GetPlatformActivities (ctx , platform , params )
4268}
4369
4470func (c Component ) GetDecentralizedTxID (ctx echo.Context , id string , params docs.GetDecentralizedTxIDParams ) error {
71+ if c .Decentralized == nil {
72+ return emptyResponse (ctx )
73+ }
74+
4575 return c .Decentralized .GetActivity (ctx , id , params )
4676}
4777
4878func (c Component ) GetDecentralizedAccount (ctx echo.Context , account string , params docs.GetDecentralizedAccountParams ) error {
79+ if c .Decentralized == nil {
80+ return emptyResponse (ctx )
81+ }
82+
4983 return c .Decentralized .GetAccountActivities (ctx , account , params )
5084}
5185
5286// Federated Interface
5387
5488func (c Component ) PostFederatedAccounts (ctx echo.Context ) error {
89+ if c .Federated == nil {
90+ return emptyResponse (ctx )
91+ }
92+
5593 return c .Federated .BatchGetAccountsActivities (ctx )
5694}
5795
5896func (c Component ) GetFederatedNetwork (ctx echo.Context , network network.Network , params docs.GetFederatedNetworkParams ) error {
97+ if c .Federated == nil {
98+ return emptyResponse (ctx )
99+ }
100+
59101 return c .Federated .GetNetworkActivities (ctx , network , params )
60102}
61103
62104func (c Component ) GetFederatedPlatform (ctx echo.Context , platform federatedx.Platform , params docs.GetFederatedPlatformParams ) error {
105+ if c .Federated == nil {
106+ return emptyResponse (ctx )
107+ }
108+
63109 return c .Federated .GetPlatformActivities (ctx , platform , params )
64110}
65111
66112func (c Component ) GetFederatedTxID (ctx echo.Context , id string , params docs.GetFederatedTxIDParams ) error {
113+ if c .Federated == nil {
114+ return emptyResponse (ctx )
115+ }
116+
67117 return c .Federated .GetActivity (ctx , id , params )
68118}
69119
70120func (c Component ) GetFederatedAccount (ctx echo.Context , account string , params docs.GetFederatedAccountParams ) error {
121+ if c .Federated == nil {
122+ return emptyResponse (ctx )
123+ }
124+
71125 return c .Federated .GetAccountActivities (ctx , account , params )
72126}
73127
@@ -77,13 +131,21 @@ func (c Component) GetFederatedAccount(ctx echo.Context, account string, params
77131// manually create rss cause of wildcard routes are not part of the official open api specification
78132// https://github.com/oapi-codegen/oapi-codegen/issues/718
79133func (c Component ) GetRSS (ctx echo.Context , _ string ) error {
134+ if c .RSS == nil {
135+ return emptyResponse (ctx )
136+ }
137+
80138 return c .RSS .Handler (ctx )
81139}
82140
83141// AI Interface
84142
85143// GetAgentData ignore the second parameter
86144func (c Component ) GetAgentData (ctx echo.Context , _ string ) error {
145+ if c .AI == nil {
146+ return emptyResponse (ctx )
147+ }
148+
87149 return c .AI .Handler (ctx )
88150}
89151
0 commit comments