-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from dataswap/feat/add-api-of-datasetchallenge
feat: 🎸 add api of datasetchallenge
- Loading branch information
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* (c) 2023 dataswap | ||
* | ||
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 | ||
* (the "Apache License"). You may not use this file except in compliance with one of these | ||
* licenses. You may obtain a copy of the MIT License at | ||
* | ||
* https://opensource.org/licenses/MIT | ||
* | ||
* Or the Apache License, Version 2.0 at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the MIT License or the Apache License for the specific language governing permissions and | ||
* limitations under the respective licenses. | ||
********************************************************************************/ | ||
|
||
import { Controller, Post, Body, UseInterceptors } from "@nestjs/common" | ||
import { DatasetChallengeService } from "./datasetChallenge.service" | ||
import { DatasetChallenge } from "@dataswapjs/dataswapjs" | ||
import { ValueFields, Result } from "@unipackage/utils" | ||
import { BigIntToStringInterceptor } from "../shared/bigIntToStringInterceptor" | ||
import { QueryParam } from "src/shared/queryParams" | ||
|
||
/** | ||
* Controller responsible for handling root-level requests. | ||
*/ | ||
@UseInterceptors(BigIntToStringInterceptor) | ||
@Controller("datasetchallenge") | ||
export class DatasetChallengeController { | ||
/** | ||
* Creates an instance of RootController. | ||
* @param rootService - The RootService instance. | ||
*/ | ||
constructor( | ||
private readonly datasetChallengeService: DatasetChallengeService | ||
) {} | ||
|
||
/** | ||
* Handles GET requests for root-level resources with an identifier. | ||
* @param queryFilter - Request parameters. | ||
* @returns A string representing the response. | ||
* @example | ||
* { | ||
* "conditions": [ | ||
* { | ||
* "datasetId": { "$gt": 0, "$lt": 3} | ||
* } | ||
* ] | ||
* } | ||
*/ | ||
@Post("query") | ||
async find( | ||
@Body() queryParam: QueryParam<DatasetChallenge> | ||
): Promise<Result<ValueFields<DatasetChallenge>[]>> { | ||
return await this.datasetChallengeService.find(queryParam) | ||
} | ||
|
||
/** | ||
* Gets a total count. | ||
* @returns A number representing a total count by query param. | ||
*/ | ||
@Post("total") | ||
async total( | ||
@Body() queryParam: QueryParam<DatasetChallenge> | ||
): Promise<Result<number>> { | ||
return await this.datasetChallengeService.total(queryParam) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* (c) 2023 dataswap | ||
* | ||
* Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 | ||
* (the "Apache License"). You may not use this file except in compliance with one of these | ||
* licenses. You may obtain a copy of the MIT License at | ||
* | ||
* https://opensource.org/licenses/MIT | ||
* | ||
* Or the Apache License, Version 2.0 at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the MIT License or the Apache License for the specific language governing permissions and | ||
* limitations under the respective licenses. | ||
********************************************************************************/ | ||
|
||
import { Injectable } from "@nestjs/common" | ||
import { DatasetChallenge } from "@dataswapjs/dataswapjs" | ||
import { ValueFields, Result } from "@unipackage/utils" | ||
import { calibrationBgTask, mainBgTask } from "../config/backgroundTask" | ||
import { BackgroundTask } from "src/backgroundTask" | ||
import { QueryParam } from "src/shared/queryParams" | ||
|
||
/** | ||
* Service responsible for providing root-level functionality. | ||
*/ | ||
@Injectable() | ||
export class DatasetChallengeService { | ||
/** | ||
* Gets a greeting message. | ||
* @returns A string representing a greeting message. | ||
*/ | ||
async find( | ||
queryParam: QueryParam<DatasetChallenge> | ||
): Promise<Result<ValueFields<DatasetChallenge>[]>> { | ||
let bgTask: BackgroundTask | ||
if (queryParam.network === "calibration") { | ||
bgTask = calibrationBgTask | ||
} else { | ||
bgTask = mainBgTask | ||
} | ||
return await bgTask.context.datastore.datasetChallenge.find( | ||
queryParam.queryFilter | ||
) | ||
} | ||
|
||
/** | ||
* Gets a total count. | ||
* @returns A number representing a total count by query param. | ||
*/ | ||
async total( | ||
queryParam: QueryParam<DatasetChallenge> | ||
): Promise<Result<number>> { | ||
let bgTask: BackgroundTask | ||
if (queryParam.network === "calibration") { | ||
bgTask = calibrationBgTask | ||
} else { | ||
bgTask = mainBgTask | ||
} | ||
return await bgTask.context.datastore.datasetChallenge.total( | ||
queryParam.queryFilter | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters