Move api endpoints to /api/ e.g. /api/packages/:package_id
Replace println usages with log.info() or log.error() for consistent logging format
Move logic to usecases
Create repositories that handle database level transactions
Use repository interfaces for testing in the future
Clean up main.v
Rearrange structure
Adds an endpoint incr_downloads which increments the download count for a module
New project structure:
src
├── cmd # Command line tools
│ └── migrate
├── config
│ └── config.v
├── entity # Entity type definitions e.g. Package
│ ├── category.v
│ ├── package.v
│ └── user.v
├── repo # Repositories that handle database interaction. Database dependent and end with '_<database name>.v'
│ ├── package_postgres.v
│ └── users_postgres.v
├── templates
│ ├── assets
│ ├── components
│ ├── index.html
│ ├── ...
│ └── search.html
├── usecase # Use cases that handle business logic for the API + website endpoints. Usecases use repository interfaces to interact with stored data. They shouldn't need to, or otherwise, depend on each other.
│ ├── package
│ └── user
├── app.v # Contains the 'endpoints' i.e. pages for rendering the VPM webpage e.g. index()
├── auth.v
├── category.v
├── main.v
├── package.v # The rest of the V files in src are handlers for the API. Each endpoint should be a subpath of '/api' as to not interfere with webpage endpoints
└── search.v
Refactor codebase
What:
/api/
e.g./api/packages/:package_id
incr_downloads
which increments the download count for a moduleNew project structure:
Demo to test everything works:
https://github.com/vlang/vpm/assets/32339757/b2555285-adad-47a3-842a-95253bbe44d4
Todo:
[x] Replace
jsmod
endpoint in V with the new endpoint/api/packages/:name/incr_downloads
: https://github.com/vlang/v/blob/ee7d34e650253c88be952e73863966eff4abcaae/cmd/tools/vpm.v#L743 Completed here, awaiting this PR to be merged: https://github.com/vlang/v/pull/18202[ ] Test migration command @medvednikov I think you will need to test it, or someone who has access to the server as I don't.