diff --git a/api/.sqlx/query-76aa80d3f0b1f22bbbc97a37a7b757b93a1abe7ea2a4f196c061d063d86de412.json b/api/.sqlx/query-76aa80d3f0b1f22bbbc97a37a7b757b93a1abe7ea2a4f196c061d063d86de412.json new file mode 100644 index 00000000..de59828a --- /dev/null +++ b/api/.sqlx/query-76aa80d3f0b1f22bbbc97a37a7b757b93a1abe7ea2a4f196c061d063d86de412.json @@ -0,0 +1,98 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT DISTINCT ON (packages.scope, packages.name)\n packages.scope as \"scope: ScopeName\",\n packages.name as \"name: PackageName\",\n packages.description,\n packages.github_repository_id,\n packages.runtime_compat as \"runtime_compat: RuntimeCompat\",\n packages.when_featured,\n packages.is_archived,\n packages.readme_source as \"readme_source: ReadmeSource\",\n packages.updated_at,\n packages.created_at,\n (\n SELECT COUNT(created_at)\n FROM package_versions\n WHERE scope = packages.scope AND name = packages.name\n ) as \"version_count!\",\n (\n SELECT version\n FROM package_versions\n WHERE scope = packages.scope\n AND name = packages.name\n AND version NOT LIKE '%-%'\n AND is_yanked = false\n ORDER BY version DESC LIMIT 1\n ) as \"latest_version\"\n FROM publishing_tasks\n JOIN packages\n ON packages.scope = publishing_tasks.package_scope\n AND packages.name = publishing_tasks.package_name\n WHERE publishing_tasks.user_id = $1\n AND publishing_tasks.status = 'success'\n ORDER BY packages.scope, packages.name, publishing_tasks.created_at DESC\n LIMIT 10;\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "scope: ScopeName", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "name: PackageName", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "github_repository_id", + "type_info": "Int8" + }, + { + "ordinal": 4, + "name": "runtime_compat: RuntimeCompat", + "type_info": "Jsonb" + }, + { + "ordinal": 5, + "name": "when_featured", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "is_archived", + "type_info": "Bool" + }, + { + "ordinal": 7, + "name": "readme_source: ReadmeSource", + "type_info": { + "Custom": { + "name": "package_readme_source", + "kind": { + "Enum": [ + "readme", + "jsdoc" + ] + } + } + } + }, + { + "ordinal": 8, + "name": "updated_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 9, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 10, + "name": "version_count!", + "type_info": "Int8" + }, + { + "ordinal": 11, + "name": "latest_version", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + null, + null + ] + }, + "hash": "76aa80d3f0b1f22bbbc97a37a7b757b93a1abe7ea2a4f196c061d063d86de412" +} diff --git a/api/src/api.yml b/api/src/api.yml index 1b51c638..96397b43 100644 --- a/api/src/api.yml +++ b/api/src/api.yml @@ -1299,6 +1299,34 @@ paths: schema: $ref: "#/components/schemas/Error" + /users/{id}/packages: + get: + summary: List recently published packages by user + description: Returns a list of packages that a user has recently published + operationId: listUserPackages + parameters: + - name: id + in: path + description: The ID of the user + required: true + schema: + $ref: "#/components/schemas/UserId" + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Package" + "404": + description: User not found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /authorizations: post: summary: Create authorization diff --git a/api/src/api/users.rs b/api/src/api/users.rs index 975cfb4a..3b394168 100644 --- a/api/src/api/users.rs +++ b/api/src/api/users.rs @@ -13,6 +13,7 @@ use crate::util::ApiResult; use crate::util::RequestIdExt; use super::ApiError; +use super::ApiPackage; use super::ApiScope; use super::ApiUser; @@ -20,6 +21,7 @@ pub fn users_router() -> Router
{ Router::builder() .get("/:id", util::json(get_handler)) .get("/:id/scopes", util::json(get_scopes_handler)) + .get("/:id/packages", util::json(get_packages_handler)) .build() .unwrap() } @@ -54,3 +56,25 @@ pub async fn get_scopes_handler( Ok(scopes.into_iter().map(ApiScope::from).collect()) } + +#[instrument(name = "GET /api/users/:id/packages", skip(req), err, fields(id))] +pub async fn get_packages_handler( + req: Request, +) -> ApiResult