-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scaffolding for PRC-1 achievements API #358
Merged
Merged
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6184c11
Tweak tsoa imports per todo comment
SpaceManiac 12fa90f
Add AchievementsController
SpaceManiac 8f4f478
Include time in getValidity
SpaceManiac b5bde8c
Log API errors to make debugging actually possible
SpaceManiac f95430f
Move AchievementService to utils-backend so it can be imported
SpaceManiac fdea349
Support games that export 'AchievementService' classes
SpaceManiac 334a103
Fix eslint errors
SpaceManiac ba52254
Interfaces too
SpaceManiac f22c8ed
Run pgtyped against a temporary Postgres instance
SpaceManiac a3f4301
Add achievement tables and queries
SpaceManiac 20cb2bc
Use new SQL queries in AchievementsController, remove AchievementService
SpaceManiac 369619a
Update for PRC-1 changes
SpaceManiac 4609d3e
Add table defs for new tables, clarify TODOs, fix issues
SpaceManiac ff0c267
Update paima-db README to describe Docker
SpaceManiac 7692a6c
Use getMainAddress in /wallet/X
SpaceManiac 1a0cf85
Add achievement_language table to back Accept-Language
SpaceManiac 6c3221d
TODO -> Future in AchievementsController
SpaceManiac 68103ad
Improve import.ts documentation
SpaceManiac 5fc34b0
Move checkedForPackedGameCode, rename importTsoa -> importEndpoints
SpaceManiac 7d001f4
Use import instead of DB for constant achievement definitions
SpaceManiac 03dfff7
Fix bugs and linter errors
SpaceManiac 4513c71
Fix table definition mismatch
SpaceManiac 0fa78af
Merge branch 'master' into patch/standard-achievements-api
SpaceManiac 21afec7
Add setAchievementProgress query
SpaceManiac b546a1c
Use wallet ID instead of address to handle delegation
SpaceManiac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
70 changes: 70 additions & 0 deletions
70
packages/engine/paima-rest/src/controllers/AchievementsController.ts
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,70 @@ | ||
import { Controller, Get, Path, Query, Route } from 'tsoa'; | ||
import { EngineService } from '../EngineService.js'; | ||
import { ENV } from '@paima/utils'; | ||
import type { | ||
AchievementService, | ||
AchievementPublicList, | ||
PlayerAchievements, | ||
Validity, | ||
} from '@paima/utils-backend'; | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Controller and routes per PRC-1 | ||
|
||
function service(): AchievementService { | ||
return EngineService.INSTANCE.achievementService; | ||
} | ||
|
||
@Route('achievements') | ||
export class AchievementsController extends Controller { | ||
private async defaultValidity(): Promise<Validity> { | ||
return { | ||
chainId: ENV.CHAIN_ID, | ||
block: await EngineService.INSTANCE.getSM().latestProcessedBlockHeight(), | ||
time: new Date().toISOString(), | ||
}; | ||
} | ||
|
||
@Get('public/list') | ||
public async public_list( | ||
@Query() category?: string, | ||
@Query() isActive?: boolean | ||
): Promise<AchievementPublicList> { | ||
return { | ||
...(await service().getGame()), | ||
...(await this.defaultValidity()), | ||
...(await service().getValidity()), | ||
achievements: (await service().getAllAchievements()) | ||
.filter(ach => !category || category === ach.category) | ||
.filter(ach => !isActive || isActive === ach.isActive), | ||
SpaceManiac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} | ||
|
||
@Get('wallet/{wallet}') | ||
public async wallet( | ||
@Path() wallet: string, | ||
/** Comma-separated list. */ | ||
@Query() name?: string | ||
): Promise<PlayerAchievements> { | ||
const player = await service().getPlayer(wallet); | ||
const achievements = await service().getPlayerAchievements(wallet); | ||
const nameSet = name ? new Set(name.split(',')) : null; | ||
return { | ||
...(await this.defaultValidity()), | ||
...(await service().getValidity()), | ||
...player, | ||
completed: achievements.reduce((n, ach) => n + (ach.completed ? 1 : 0), 0), | ||
achievements: nameSet ? achievements.filter(ach => nameSet.has(ach.name)) : achievements, | ||
}; | ||
} | ||
|
||
@Get('nft/{nft_address}') | ||
public async nft( | ||
@Path() nft_address: string, | ||
/** Comma-separated list. */ | ||
@Query() name?: string | ||
): Promise<PlayerAchievements> { | ||
const wallet = await service().getNftOwner(nft_address); | ||
return await this.wallet(wallet, name); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import { RegisterRoutes } from './tsoa/routes.js'; | ||
import * as basicControllerJson from './tsoa/swagger.json'; | ||
// replace the above import with the one below once this is merged and released: https://github.com/prettier/prettier/issues/15699 | ||
// import { default as basicControllerJson } from './tsoa/swagger.json' with { type: "json" }; | ||
import { default as basicControllerJson } from './tsoa/swagger.json' with { type: 'json' }; | ||
export default RegisterRoutes; | ||
export { basicControllerJson }; | ||
export { EngineService } from './EngineService.js'; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to move this out of the prebuild?
I don't remember exactly why it was here, but I think it may have to be with the fact that putting it in the prebuild ensures that it gets run before the build step of any package in paima-engine (so any package can access the generated types). I don't think this is used in practice though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I ran into is that if this stays in prebuild, tsoa can't import the PRC-1 types from
utils-backend
on clean builds, or otherwise sees the old definitions, because they're produced on that package's build.Maybe can somehow be improved by teaching NX to build utils-backend before prebuilding paima-rest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NX should be able to figure out dependencies based on the
references
inside the tsconfig IIRCThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to not work. It doesn't infer that rest:prebuild depends on utils-backend:build