ormushq / ormus

Ormus - Customer Data Platform
MIT License
28 stars 19 forks source link

feat(manager): add CRUD API for projects. #130

Closed mohsenHa closed 3 weeks ago

mohsenHa commented 1 month ago

This pull request contains below items:

Main changes

Add create API for project entity

Files added:

File updated:

Add list API for project entity

Files added:

Add delete API for project entity

Files added:

Add update API for project entity

Files added:

Other changes

Makefile

I updated this file and added a new command to drop all tables in ScyllaDB for the manager service.

Usage:

make drop-manager-db

I also updated the command for generating the Swagger file from swagger-generatorto swagger-gen.

cmd/manager/main.go

I updated this file and registered new services in it.

config.yml, config/default.go, manager/config.go

I added context_key, access_expiration_time_in_day, and refresh_expiration_time_in_day for use in the auth service. Additionally, I updated the auth config name from JwtConfig to Config and replaced it throughout the auth service.

Swagger service

I updated the local deployment for the Swagger service to serve it directly, without using Air. Now, when the make swagger-gen command runs, it restarts the service to build it with the new configurations.

logger/logger.go

I added a new function called LogError(err error) that logs the error if it's a rich error.

manager/delivery/httpserver/middleware/tokenextractor.go

I added a new method to extract the token from the header.

manager/delivery/httpserver/server.go

I updated this file by adding new handlers and incorporating a logger middleware to log all requests. Additionally, I included a code to log all registered routes in Echo.

Some updates in mocks, stubs, and tests

I updated some tests, mocks, and stubs to reflect the latest changes.

Add migration

I added this migration to:

  1. Introduce a new column deleted for use in the list API to filter out deleted items. Although we have a deleted_at column, ScyllaDB doesn't allow filtering on null values, or I haven't found a solution for this.
  2. Add two indexes on the projects table (user_id, deleted). In ScyllaDB, queries are optimized to allow filtering only over indexed columns for better performance. While it's possible to use ALLOW FILTERING to filter on non-indexed columns, I prefer to index these columns for better performance..

manager/repository/scyllarepo/scyllaproject/hasmore.go

I added this for use in the list. In ScyllaDB, we can't use offset for pagination, but there's a workaround. We can use token(id) for this purpose. The range for token(id) is -9223372036854775807 to 9223372036854775807. For the first page, we select items where token(id) > -9223372036854775808. In the response, we include a flag indicating whether there are more items, along with the token_id for each item. The client then sends the last item’s token_id back to the server, and we select items with a token(id) greater than that value.

manager/service/authservice/jwt.go

I updated the config by adding two items: AccessExpirationTTL and RefreshExpirationTTL. I also removed the base64 encoding of the user ID from the generated claim, as it’s unnecessary; we sign the claim with our secret key, making it invalid if someone manually changes the user ID in the token. For better security, we should change the signing method to RS256.