Skip to content

Commit

Permalink
update package json
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabarzin committed Jan 13, 2024
2 parents 8babd02 + 717bdde commit 232a8e3
Show file tree
Hide file tree
Showing 82 changed files with 1,187 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea

/animals_photo/
/node_modules/
/frontend/node_modules/
Expand Down
9 changes: 5 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn precommit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm test
yarn precommit
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.6
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,46 @@ A system for animal shelters, providing an easy and free way for shelter owners
- [board to work on](https://github.com/orgs/qase-tms/projects/5/views/1)
- [meta page](https://meta.shelterpaws.org)
- [website](https://shelterpaws.org)

## Preparing the dev mode

Before committing changes, it is necessary to install dependencies:

```
npx husky-init && yarn install
```

### Possible Issues

#### Found incompatible module.

We support **node >=18.12.0**. To switch between node versions, use [nvm](https://github.com/nvm-sh/nvm).

#### fatal: cannot exec '.husky/pre-commit': No such file or directory

1. Remove `.husky/pre-commit` file

2. Create empty `.husky/pre-commit` and paste the following code into the file:

```
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn precommit
```

3. Run `npx husky install`

5. Try committing once again.

If this instruction did not solve the problem, you can bypass the check using the `--no-verify` flag:

```
git commit -m 'commit name' --no-verify
```

Before committing changes with the `--no-verify` flag, it is recommended to run checks manually and fix errors if there are any:"

```
yarn stylelint
```
51 changes: 51 additions & 0 deletions README_ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# shelterpaws
A system for animal shelters, providing an easy and free way for shelter owners to display their pets, help them find new homes, and fundraise.

- [board to work on](https://github.com/orgs/qase-tms/projects/5/views/1)
- [meta page](https://meta.shelterpaws.org)
- [website](https://shelterpaws.org)

## Режим разработки

Перед тем, как закоммитить изменения, необходимо установить зависимости:

```
npx husky-init && yarn install
```

### Возможные проблемы

#### Found incompatible module.

Для успешной установки всех зависимостей желательно использовать **node >=18.12.0**. Для переключения между версиями node можно воспользоваться [nvm](https://github.com/nvm-sh/nvm).

#### fatal: cannot exec '.husky/pre-commit': No such file or directory

1. Скопировать содержимое файла `.husky/pre-commit`:

```
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn precommit
```

2. Удалить файл `.husky/pre-commit`

3. Создать пустой `.husky/pre-commit` и вставить туда скопированный код.

4. Запустить команду `npx husky install`

5. Попробовать еще раз сделать коммит.

Если данная инструкция не решила проблему, можно обойти проверку, используя флаг `--no-verify`:

```
git commit -m 'commit name' --no-verify
```

Перед тем, как закоммитить изменения с флагом `--no-verify`, рекомендуется запустить проверки вручную и исправить ошибки, если они есть:

```
yarn stylelint
```
4 changes: 4 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gitignore
*_env*
*.pyc
**/.pytest_cache/*
1 change: 1 addition & 0 deletions backend/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.6
21 changes: 21 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.11.6-alpine

ARG SERVICE_NAME=backend

ADD ./$SERVICE_NAME/poetry.lock ./$SERVICE_NAME/pyproject.toml ./

ENV PYTHONPATH=/

ENV PATH=/root/.poetry/bin:${PATH}
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev \
&& apk add libffi-dev
RUN pip install --upgrade pip
RUN pip install poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev
RUN poetry show

COPY ./$SERVICE_NAME/ backend/

CMD ["python", "/backend/main.py"]
24 changes: 24 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.3"
services:
backend:
container_name: backend
command: python3 /backend/main.py
build:
context: ../
dockerfile: ./backend/Dockerfile
ports:
- 8080:8080
volumes:
- ./:/app
- '/var/data/shelterpaws/animal_photo:/var/animal_photos'
env_file:
- .env

psql:
image: postgres:15.5
volumes:
- './docker/database:/var/lib/psql'
ports:
- "5432:5432"
env_file:
- .env
3 changes: 2 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi_pagination import add_pagination

from backend.settings import Settings
from backend.utils import bind_routes, bind_events, bind_exceptions
from backend.utils import bind_routes, bind_events, bind_exceptions, bind_static


def make_app(settings: Settings):
Expand All @@ -27,6 +27,7 @@ def make_app(settings: Settings):
bind_routes(app)
bind_events(app, settings.database_url)
bind_exceptions(app)
bind_static(app)
add_pagination(app)

return app
Expand Down
19 changes: 18 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ greenlet = "^3.0.2"
fastapi-pagination = "^0.12.14"
asyncpg = "^0.29.0"
python-multipart = "^0.0.6"
jinja2 = "^3.1.2"


[build-system]
Expand Down
9 changes: 9 additions & 0 deletions backend/routers/animal_router.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse

from backend.schemas.animal_schemas import AnimalResponseSchema, AnimalCreateSchema, AnimalUpdateSchema
from backend.schemas.base_schema import BaseOkResponse
from backend.services.animal_service import AnimalService
from backend.services.animal_template_service import AnimalTemplateService

router = APIRouter(
tags=["animals"],
prefix="/animals"
)


@router.get('/index')
async def get_index_template(
request: Request,
) -> HTMLResponse:
return AnimalTemplateService(request).get_index_template()


@router.get("/")
async def get_animals(
request: Request
Expand Down
17 changes: 17 additions & 0 deletions backend/services/animal_template_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from fastapi.responses import HTMLResponse
from backend.services.base_template_service import BaseTemplateService


class AnimalTemplateService(BaseTemplateService):
def __init__(self, request):
super().__init__(request)

@staticmethod
def _complete_template_path(template_name: str):
return f"pages/index/{template_name}"

def get_index_template(self) -> HTMLResponse:
return self.templates.TemplateResponse(
name=self._complete_template_path("index.html"),
context={"request": self.request}
)
9 changes: 9 additions & 0 deletions backend/services/base_template_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from fastapi import Request
from fastapi.templating import Jinja2Templates


class BaseTemplateService:
templates = Jinja2Templates(directory="./backend/templates")

def __init__(self, request: Request):
self.request = request
1 change: 1 addition & 0 deletions backend/settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.local.env
1 change: 1 addition & 0 deletions backend/static/img/icon-phone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/static/img/icon-telegram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/static/img/wave.webp
Binary file not shown.
Loading

0 comments on commit 232a8e3

Please sign in to comment.