Skip to content

Commit da6baa0

Browse files
committed
Add code of the default example to response
1 parent e413153 commit da6baa0

14 files changed

Lines changed: 655 additions & 484 deletions

File tree

playground/api/v1/api.proto

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ message PrecompiledObject{
168168
bool default_example = 9;
169169
}
170170

171+
// DefaultExample represents the default PrecompiledObject and his code
172+
message DefaultExample{
173+
PrecompiledObject precompiled_object = 1;
174+
string code = 2;
175+
}
176+
171177
// Categories represent the array of messages with sdk and categories at this sdk
172178
message Categories{
173179
message Category{
@@ -204,8 +210,8 @@ message GetPrecompiledObjectGraphRequest{
204210
string cloud_path = 1;
205211
}
206212

207-
// GetDefaultPrecompiledObjectRequest contains information of the needed PrecompiledObject sdk.
208-
message GetDefaultPrecompiledObjectRequest {
213+
// GetDefaultExampleRequest contains information of the needed PrecompiledObject sdk.
214+
message GetDefaultExampleRequest {
209215
Sdk sdk = 1;
210216
}
211217

@@ -234,9 +240,9 @@ message GetPrecompiledObjectGraphResponse {
234240
string graph = 1;
235241
}
236242

237-
// GetDefaultPrecompiledObjectResponse represents the default PrecompiledObject and his category for the sdk.
238-
message GetDefaultPrecompiledObjectResponse {
239-
PrecompiledObject precompiled_object = 1;
243+
// GetDefaultExampleResponse represents the default PrecompiledObject and his code for the sdk.
244+
message GetDefaultExampleResponse {
245+
DefaultExample default_example = 1;
240246
}
241247

242248
service PlaygroundService {
@@ -286,6 +292,6 @@ service PlaygroundService {
286292
// Get the graph of an PrecompiledObject.
287293
rpc GetPrecompiledObjectGraph(GetPrecompiledObjectGraphRequest) returns (GetPrecompiledObjectGraphResponse);
288294

289-
// Get the default precompile object for the sdk.
290-
rpc GetDefaultPrecompiledObject(GetDefaultPrecompiledObjectRequest) returns (GetDefaultPrecompiledObjectResponse);
295+
// Get the default example for the sdk.
296+
rpc GetDefaultExample(GetDefaultExampleRequest) returns (GetDefaultExampleResponse);
291297
}

playground/backend/cmd/server/controller.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,26 +318,18 @@ func (controller *playgroundController) GetPrecompiledObjectGraph(ctx context.Co
318318
return &response, nil
319319
}
320320

321-
// GetDefaultPrecompiledObject returns the default precompile object for sdk.
322-
func (controller *playgroundController) GetDefaultPrecompiledObject(ctx context.Context, info *pb.GetDefaultPrecompiledObjectRequest) (*pb.GetDefaultPrecompiledObjectResponse, error) {
321+
// GetDefaultExample returns the default precompile object for sdk.
322+
func (controller *playgroundController) GetDefaultExample(ctx context.Context, info *pb.GetDefaultExampleRequest) (*pb.GetDefaultExampleResponse, error) {
323323
switch info.Sdk {
324324
case pb.Sdk_SDK_UNSPECIFIED:
325-
logger.Errorf("GetDefaultPrecompiledObject(): unimplemented sdk: %s\n", info.Sdk)
325+
logger.Errorf("GetDefaultExample(): unimplemented sdk: %s\n", info.Sdk)
326326
return nil, errors.InvalidArgumentError("Error during preparing", "Sdk is not implemented yet: %s", info.Sdk.String())
327327
}
328-
precompiledObject, err := utils.GetDefaultPrecompiledObject(ctx, info.Sdk, controller.cacheService)
328+
defaultExample, err := utils.GetDefaultExample(ctx, info.Sdk, controller.cacheService)
329329
if err != nil {
330-
logger.Errorf("GetDefaultPrecompiledObject(): error during getting catalog: %s", err.Error())
331-
return nil, errors.InternalError("Error during getting Precompiled Objects", "Error with cloud connection")
330+
logger.Errorf("GetDefaultExample(): error during getting default example: %s", err.Error())
331+
return nil, errors.InternalError("Error during getting Default Examples", "Error with cloud connection")
332332
}
333-
response := pb.GetDefaultPrecompiledObjectResponse{PrecompiledObject: &pb.PrecompiledObject{
334-
CloudPath: precompiledObject.CloudPath,
335-
Name: precompiledObject.Name,
336-
Description: precompiledObject.Description,
337-
Type: precompiledObject.Type,
338-
PipelineOptions: precompiledObject.PipelineOptions,
339-
Link: precompiledObject.Link,
340-
DefaultExample: precompiledObject.DefaultExample,
341-
}}
333+
response := pb.GetDefaultExampleResponse{DefaultExample: defaultExample}
342334
return &response, nil
343335
}

playground/backend/cmd/server/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func setupCache(ctx context.Context, appEnv environment.ApplicationEnvs) (cache.
119119
}
120120
}
121121

122-
// setupExamplesCatalog saves precompiled objects catalog from storage to cache
122+
// setupExamplesCatalog saves precompiled objects catalog and default example from storage to cache
123123
func setupExamplesCatalog(ctx context.Context, cacheService cache.Cache) error {
124124
catalog, err := utils.GetCatalogFromStorage(ctx)
125125
if err != nil {
@@ -130,12 +130,12 @@ func setupExamplesCatalog(ctx context.Context, cacheService cache.Cache) error {
130130
}
131131

132132
bucket := cloud_bucket.New()
133-
defaultPrecompiledObjects, err := bucket.GetDefaultPrecompiledObjects(ctx)
133+
defaultExamples, err := bucket.GetDefaultExamples(ctx)
134134
if err != nil {
135135
return err
136136
}
137-
for sdk, precompiledObject := range defaultPrecompiledObjects {
138-
if err := cacheService.SetDefaultPrecompiledObject(ctx, sdk, precompiledObject); err != nil {
137+
for sdk, defaultExample := range defaultExamples {
138+
if err := cacheService.SetDefaultExample(ctx, sdk, defaultExample); err != nil {
139139
logger.Errorf("GetPrecompiledObjects(): cache error: %s", err.Error())
140140
return err
141141
}

0 commit comments

Comments
 (0)