diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2bcf066..941a762 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -23,5 +23,4 @@ jobs: - run: | python -m pip install --upgrade pip pip install flake8 - pip install isort - make lint + flake8 --config flake8 diff --git a/Makefile b/Makefile index 4fdc65f..6e2dc0c 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ migrations: lint: isort * + flake8 --config flake8 + start: docker-compose up diff --git a/README.md b/README.md index ff6e0c7..68ecc6b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ How to play: 1. run `make start` -2. go to http://localhost:5173/ +2. go to http://localhost:5173/ 3. click on `Create user / Login` 4. enter username and password and press `Create user` 5. log in with created user diff --git a/alembic/versions/68cb451e6f2c_add_unique_contsraint.py b/alembic/versions/68cb451e6f2c_add_unique_contsraint.py index 1690a62..ced5cc3 100644 --- a/alembic/versions/68cb451e6f2c_add_unique_contsraint.py +++ b/alembic/versions/68cb451e6f2c_add_unique_contsraint.py @@ -7,9 +7,9 @@ """ from typing import Sequence, Union -from alembic import op import sqlalchemy as sa +from alembic import op # revision identifiers, used by Alembic. revision: str = '68cb451e6f2c' diff --git a/app.py b/app.py index 836c2d1..4882d7d 100644 --- a/app.py +++ b/app.py @@ -1,20 +1,16 @@ import json +import os from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse -from sqlalchemy import MetaData, create_engine -from sqlalchemy.orm import (Session, sessionmaker) - -from src.db.orm_models import Base, UserORM -from src.game import (ConnectionManager, Game, Player, - PlayerOptions, Room, RoomManager, GameStatus) +from sqlalchemy import create_engine from src.db.db import DB +from src.errors import UserAlreadyExists, UserNotFoundError, WrongPassword +from src.game import (ConnectionManager, Game, GameStatus, Player, + PlayerOptions, Room, RoomManager) from src.models import CreateUserRequest -from src.errors import UserNotFoundError, UserAlreadyExists, WrongPassword -from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine -import os app = FastAPI() @@ -41,7 +37,7 @@ room_manager = RoomManager() engine = create_engine( - f'postgresql+psycopg://postgres:qwerty@{db_host}/postgres', + f'postgresql+psycopg://postgres:qwerty@{db_host}/postgres', echo=True, pool_size=5, max_overflow=10, @@ -57,8 +53,7 @@ async def websocket_endpoint(websocket: WebSocket, username: str): # Create player player = Player(ws=websocket, id=username) playing_room = None - - + try: while True: # If user already in a room @@ -100,7 +95,6 @@ async def websocket_endpoint(websocket: WebSocket, username: str): playing_room.game.p2_option = playing_room.player2.choice result = playing_room.game.find_winner() - # перенести в room manager? await playing_room.announce_result(result) db.save_result( playing_room.player1.id, @@ -113,9 +107,6 @@ async def websocket_endpoint(websocket: WebSocket, username: str): await playing_room.send_message_to_another_player(player, GameStatus.WAITING.name) # remove user room_manager.remove_player(player.id) - - - @app.get("/rating") @@ -124,6 +115,7 @@ async def rating(): return JSONResponse(json.dumps(users_rated)) + @app.post("/users/create") async def create_user(request: CreateUserRequest): try: @@ -140,6 +132,5 @@ async def login(request: CreateUserRequest): return JSONResponse('{}') except UserNotFoundError as e: return JSONResponse(json.dumps(e.message), status_code=400) - except WrongPassword as e: - return JSONResponse(json.dumps(e.message), status_code=401) - + except WrongPassword as e: + return JSONResponse(json.dumps(e.message), status_code=401) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2b0b495..2533896 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ services: app: build: ./ command: bash -c "./wait-for-postgres.sh db && uvicorn app:app --proxy-headers --host 0.0.0.0 --port 8000" - # - alembic upgrade head ports: - 8000:8000 depends_on: diff --git a/flake8 b/flake8 new file mode 100644 index 0000000..d65a493 --- /dev/null +++ b/flake8 @@ -0,0 +1,3 @@ +[flake8] +ignore = D203,E501,W293,W292,W291 +exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,./.venv,./alembic \ No newline at end of file diff --git a/game-client/src/components/AuthForm.vue b/game-client/src/components/AuthForm.vue index b942d95..668a22d 100644 --- a/game-client/src/components/AuthForm.vue +++ b/game-client/src/components/AuthForm.vue @@ -4,32 +4,9 @@ import { ref } from 'vue' import { useUsersStore } from '../../store/users' const usersStore = useUsersStore() - const message=ref('') -// const username=ref('') const password=ref('') -// function createUser(event) { -// if (username.value && password.value){ -// axios({ -// method: 'post', -// url: 'http://127.0.0.1:8000/users/create', -// data: { -// username: username.value.toLowerCase(), -// password: password.value, -// }, -// }) -// .then(function (response) { -// console.log(response.data) -// message.value = `User "${username.value}" created` -// }) -// .catch(function (error, response) { -// console.log(error); -// message.value = error.response.data; -// }) -// } -// } - function createUser(event) { if (usersStore.userName && password.value){ axios({ @@ -41,11 +18,9 @@ function createUser(event) { }, }) .then(function (response) { - // console.log(response.data) message.value = `User "${usersStore.userName}" created` }) .catch(function (error, response) { - // console.log(error); message.value = error.response.data; }) } @@ -62,38 +37,15 @@ function login(event) { }, }) .then(function (response) { - // console.log(response.data) message.value = `You logged in as "${usersStore.userName}"` usersStore.setIsLoggedIn(true) }) .catch(function (error, response) { - // console.log(error); message.value = error.response.data; }) } } -// function login(event) { -// if (username.value && password.value){ -// axios({ -// method: 'post', -// url: 'http://127.0.0.1:8000/auth/login', -// data: { -// username: username.value.toLowerCase(), -// password: password.value, -// }, -// }) -// .then(function (response) { -// console.log(response.data) -// message.value = `You logged in as "${username.value}"` -// }) -// .catch(function (error, response) { -// console.log(error); -// message.value = error.response.data; -// }) -// } -// } - const handleChange = (event) => { usersStore.setUserName(event.target.value); }; @@ -108,7 +60,6 @@ const handleChange = (event) => {