Skip to content

itisprasad/useraudit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Audit

This is a set of backend services consisting various endpoints to perform CRUD operations to a user table

Pre-requisites

docker installed and Running
docker-compose tool installed

Setting up the app

Pull the source code

$ git clone [email protected]:itisprasad/useraudit.git

Build the app

$ cd useraudit
$ docker-compose up --build

In case, you run into an error while startup, do the following

$ docker-compose down
$ docker-compose up -d
$ docker-compose up --build

Test the endpoints

Create user

$ curl -X POST http://localhost:8000/users/ \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "[email protected]"}'

Output

{"name":"John Doe","email":"[email protected]","is_deleted":false,"id":1}i

Query a specific user

$  curl -X GET http://localhost:8000/users/1

Output

[{"name":"John Doe","email":"[email protected]","id":1}]

List all users

$  curl -X GET http://localhost:8000/users/

Output

[{"name":"John Doe","email":"[email protected]","is_deleted":false,"id":1},{"name":"Jane Doe","email":"[email protected]","is_deleted":false,"id":2}]i

Update user

$ curl -X PUT http://localhost:8000/users/2 -H "Content-Type: application/json" -d '{"name": "Jane Doe", "email": "[email protected]"}'

Output

{"name":"Jane Doe","email":"[email protected]","is_deleted":false,"id":2}

Delete user

This is a soft delete operation where in the user will be marked as deleted by updating is_deleted attribute to True. This way, the user data is persisted.

$ curl -X DELETE http://localhost:8000/users/1

Output

{"detail":"User deleted"}

List audit logs

$ curl -X GET http://localhost:8000/audit/

Output

[{"id":1,"action":"CREATE","details":"User created: <app.models.User object at 0x7f9fbb1346d0>","timestamp":"2025-01-15T01:46:35.817502"},{"id":2,"action":"CREATE","details":"User created: <app.models.User object at 0x7f9fbb174b50>","timestamp":"2025-01-15T01:52:13.623000"},{"id":3,"action":"UPDATE","details":"User updated: <app.models.User object at 0x7f9fba905050>","timestamp":"2025-01-15T01:54:16.762529"},{"id":4,"action":"UPDATE","details":"User updated: <app.models.User object at 0x7f9fba906d10>","timestamp":"2025-01-15T01:54:51.029560"},{"id":5,"action":"DELETE","details":"User deleted: <app.models.User object at 0x7f9fba9068d0>","timestamp":"2025-01-15T01:56:21.506760"}]

Running test case

Ensure pytest module is installed. You may install pytest as follows

pip install pytest
$ cd app/tests
$ pytest
=================================================================== test session starts ====================================================================
platform linux -- Python 3.11.11, pytest-7.4.2, pluggy-1.5.0
rootdir: /app/app/tests
plugins: anyio-4.8.0
collected 3 items

test_main.py ...                                                                                                                                     [100%]

==================================================================== 3 passed in 0.86s =====================================================================

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published