Skip to content
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

Update Python service skel #557

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions skel/django-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ conda create -n hello-manager python=3.12
conda activate hello-manager
```

### DB setup

- Add database config to `../../../../../shared/init-db.sql` for centralised DB setup
```
CREATE ROLE hello_manager;
CREATE DATABASE hello_manager OWNER hello_manager;
```


### Make

- At app root, perform
Expand Down Expand Up @@ -109,17 +118,17 @@ python manage.py runserver_plus
```

```
curl -s http://localhost:8000/hlo/v1/hello | jq
curl -s http://localhost:8000/api/v1/hello | jq
```

```
curl -s http://localhost:8000/hlo/v1/hello/1 | jq
curl -s http://localhost:8000/api/v1/hello/1 | jq
```

Or visit in browser:
- http://localhost:8000/hlo/v1
- http://localhost:8000/hlo/v1/hello
- http://localhost:8000/hlo/v1/hello/1
- http://localhost:8000/api/v1
- http://localhost:8000/api/v1/hello
- http://localhost:8000/api/v1/hello/1

### API Doc

Expand Down
2 changes: 1 addition & 1 deletion skel/django-api/project_name/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_get_api(self):
"""
python manage.py test {{project_name}}.tests.test_viewsets.HelloViewSetTestCase.test_get_api
"""
response = self.client.get('/hlo/v1/hello/')
response = self.client.get('/api/v1/hello/')
logger.info(response.json())
self.assertEqual(response.status_code, 200, 'Ok status response is expected')
3 changes: 1 addition & 2 deletions skel/django-api/project_name/urls/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from {{project_name}}.viewsets.helloworld import HelloWorldViewSet
from {{project_name}}.settings.base import API_VERSION

api_namespace = "hlo"
api_version = API_VERSION
api_base = f"{api_namespace}/{api_version}/"
api_base = f"api/{api_version}/"

router = OptionalSlashDefaultRouter()
router.register(r"hello", HelloWorldViewSet, basename="hello")
Expand Down