Skip to content

API V3 Refactoring #44

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

Merged
merged 34 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
86dd9fd
Introduce interfaces
GabrielBarberini Feb 9, 2025
da1e16d
Fixes runtime errors
GabrielBarberini Feb 9, 2025
b51ecaf
format and lint
GabrielBarberini Feb 9, 2025
55d884d
fixes imports
GabrielBarberini Feb 9, 2025
e8e2d50
migrate Enum to Literal when possible
GabrielBarberini Feb 15, 2025
0eb8d8a
refactor test rockets route
GabrielBarberini Feb 15, 2025
2083d36
adapts selected motor kind to new API interface
GabrielBarberini Feb 16, 2025
4a8c79c
allows extra fields on model instantiation to bridge for views
GabrielBarberini Feb 16, 2025
2a1635d
adapts flight route tests
GabrielBarberini Feb 16, 2025
6a9ff31
fixes tests and runs formatting
GabrielBarberini Feb 16, 2025
8ff0c8d
improves conditional reading
GabrielBarberini Feb 16, 2025
44581ad
moves unit tests to unit dir
GabrielBarberini Feb 16, 2025
57f3142
removes unnecessary validator
GabrielBarberini Feb 16, 2025
4417bee
fixes runtime issues
GabrielBarberini Feb 16, 2025
a595acc
removes unnecessary response data from PUT/DELETE
GabrielBarberini Feb 17, 2025
df6c4c2
change lib to src
GabrielBarberini Feb 17, 2025
e68f748
adapts motor model
GabrielBarberini Feb 22, 2025
a46116a
typo fix
GabrielBarberini Feb 22, 2025
469a13e
fixes pylint issues
GabrielBarberini Feb 22, 2025
f3074b7
Fixes enum value inconsistency
GabrielBarberini Feb 22, 2025
4a0408b
Replaces assert with explicit validation
GabrielBarberini Feb 22, 2025
e0acdc9
Fixes typo in method name
GabrielBarberini Feb 22, 2025
ae84bbc
adds await keyword for async method call
GabrielBarberini Feb 22, 2025
d7877fd
Adds await keyword for async method calls
GabrielBarberini Feb 22, 2025
3f028cf
removes snippet garbage
GabrielBarberini Feb 22, 2025
aaab1a5
solves nitpick comments
GabrielBarberini Feb 22, 2025
40c7a91
improves HTTP code semantics
GabrielBarberini Feb 22, 2025
7f539ee
Update src/models/flight.py
GabrielBarberini Mar 8, 2025
871921d
Update src/models/flight.py
GabrielBarberini Mar 8, 2025
54c8ce8
Update src/models/environment.py
GabrielBarberini Mar 8, 2025
9ba7aa2
changes ControllerInterface to ControllerBase
GabrielBarberini Mar 8, 2025
499f505
adds docstring to interfaces
GabrielBarberini Mar 8, 2025
5bcd592
adds uvloop
GabrielBarberini Mar 8, 2025
b29ae1c
adds uvloop to make dev
GabrielBarberini Mar 8, 2025
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ RUN apt-get update && \
apt-get purge -y --auto-remove && \
rm -rf /var/lib/apt/lists/*

COPY ./lib /app/lib
COPY ./src /app/src

CMD ["gunicorn", "-c", "lib/settings/gunicorn.py", "-w", "1", "--threads=2", "-k", "uvicorn.workers.UvicornWorker", "lib.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60"]
CMD ["gunicorn", "-c", "src/settings/gunicorn.py", "-w", "1", "--threads=2", "-k", "uvicorn.workers.UvicornWorker", "src.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60"]
10 changes: 5 additions & 5 deletions Makefile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a job on GitHub Actions to automatically run all these tests every Pull Request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai please create a gh issue with that specification so we can address it later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for setting up GitHub Actions to run tests on PRs

gh issue create \
  --title "Set up GitHub Actions CI workflow for automated testing on PRs" \
  --body "## Overview
As discussed in PR #44, we need to set up a GitHub Actions workflow to automatically run all tests on each Pull Request.

## Specifications
The workflow should:
- Trigger on each PR and push to main branch
- Run the following commands from the Makefile:
  - \`black\` for code formatting check
  - \`flake8\` for linting
  - \`pylint\` for static code analysis
  - \`ruff\` for additional linting/checking
  - \`pytest\` for running all tests
- Fail the check if any of these commands fail
- Show test results in the PR

## Additional considerations
- Consider caching dependencies to speed up workflow
- Consider using separate jobs for linting vs testing
- Ensure it works with the new source directory structure (\`src\` instead of \`lib\`)

## Reference
- Originally requested by @Gui-FernandesBR in PR #44
- URL: https://github.com/RocketPy-Team/Infinity-API/pull/44#discussion_r1978372522" \
  --assignee "GabrielBarberini"

Length of output: 1076


@GabrielBarberini I've created a GitHub issue as requested for setting up GitHub Actions to run automated tests on each PR. The issue has been assigned to you and can be found here: #45

The issue includes specifications for running all the tests from the Makefile (black, flake8, pylint, ruff, and pytest) when PRs are created or updated. I've also included some additional considerations about caching dependencies and ensuring compatibility with the new src directory structure.

(_/)
(•ᴥ•)
/ >📝

Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ format: black ruff
lint: flake8 pylint

black:
black ./lib || true
black ./src || true
black ./tests || true

flake8:
flake8 --ignore E501,E402,F401,W503,C0414 ./lib || true
flake8 --ignore E501,E402,F401,W503,C0414 ./src || true
flake8 --ignore E501,E402,F401,W503,C0414 ./tests || true

pylint:
pylint ./lib || true
pylint ./src || true
pylint ./tests || true

ruff:
ruff check --fix ./lib || true
ruff check --fix ./src || true
ruff check --fix ./tests || true

test:
python3 -m pytest .

dev:
python3 -m uvicorn lib:app --reload --port 3000
python3 -m uvicorn src:app --reload --port 3000

clean:
docker stop infinity-api
Expand Down
85 changes: 26 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
- run docker compose: `docker-compose up --build -d`

### Standalone
- Dev: `python3 -m uvicorn lib:app --reload --port 3000`
- Prod: `gunicorn -k uvicorn.workers.UvicornWorker lib:app -b 0.0.0.0:3000`
- Dev: `python3 -m uvicorn src:app --reload --port 3000`
- Prod: `gunicorn -k uvicorn.workers.UvicornWorker src:app -b 0.0.0.0:3000`

## Project structure
```
Expand All @@ -39,6 +39,7 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
│ │── secrets.py
│   │  
│   ├── controllers
│   │   ├── interface.py
│   │   ├── environment.py
│   │   ├── flight.py
│   │   ├── motor.py
Expand All @@ -57,65 +58,31 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
│   │   └── rocket.py
│   │  
│   ├── repositories
│   │   ├── repo.py
│   │   ├── interface.py
│   │   ├── environment.py
│   │   ├── flight.py
│   │   ├── motor.py
│   │   └── rocket.py
│   │  
│   ├── models
│   │   ├── aerosurfaces.py
│   │   ├── interface.py
│   │   ├── environment.py
│   │   ├── flight.py
│   │   ├── motor.py
│   │   └── rocket.py
│   │   ├── rocket.py
│   │   │  
│   │   └── sub
│   │ ├── aerosurfaces.py
│ │ └── tanks.py
│   │  
│   └── views
│   ├── interface.py
│   ├── environment.py
│   ├── flight.py
│   ├── motor.py
│   └── rocket.py
│  
└── tests
├── integration
│   ├── test_environment_integration.py
│   ├── test_motor_integration.py
│   ├── test_rocket_integration.py
│   └── test_flight_integration.py
│  
└── unit
├── test_secrets.py
├── test_api.py
│  
├── test_controllers
│   ├── test_environment_controller.py
│   ├── test_flight_controller.py
│   ├── test_motor_controller.py
│   └── test_rocket_controller.py
│  
├── test_services
│   ├── test_environment_service.py
│   ├── test_flight_service.py
│   ├── test_motor_service.py
│   └── test_rocket_serice.py
├── test_repositories
│   ├── test_environment_repo.py
│   ├── test_flight_repo.py
│   ├── test_motor_repo.py
│   └── test_rocket_repo.py
├── test_models
│   ├── test_environment_model.py
│   ├── test_flight_model.py
│   ├── test_motor_model.py
│   └── test_rocket_model.py
│  
└── test_views
   ├── test_environment_view.py
   ├── test_flight_view.py
   ├── test_motor_view.py
   └── test_rocket_view.py
```

## DOCS
Expand All @@ -135,21 +102,21 @@ sequenceDiagram
User ->> API: POST /model
API ->> MongoDB: Persist API Model as a document
MongoDB -->> API: Model ID
API -->> User: ModelCreated View
API -->> User: 201 ModelCreated View

User ->> API: GET /model/:id
API ->> MongoDB: Read API Model document
MongoDB -->> API: API Model document
API -->> User: API ModelView
API -->> User: 200 API ModelView

User ->> API: PUT /model/:id
API ->> MongoDB: Update API Model document
API -->> User: ModelUpdated View
API -->> User: 204

User ->> API: DELETE /model/:id
API ->> MongoDB: Delete API Model document
MongoDB -->> API: Deletion Confirmation
API -->> User: ModelDeleted View
API -->> User: 204

```

Expand All @@ -159,19 +126,19 @@ sequenceDiagram
participant User
participant API
participant MongoDB
participant Rocketpy lib
participant RocketPy lib

User ->> API: GET /summary/model/:id
API -->> MongoDB: Retrieve Rocketpy native class
MongoDB -->> API: Rocketpy native class
API ->> Rocketpy lib: Simulate Rocketpy native class
Rocketpy lib -->> API: Simulation Results
User ->> API: GET model/:id/simulate/
API -->> MongoDB: Retrieve API Model document
MongoDB -->> API: API Model document
API ->> RocketPy: Initialize RocketPy native class and simulate
RocketPy lib -->> API: Simulation Results
API -->> User: Simulation Results

User ->> API: GET /model/:id/rocketpy
API -->> MongoDB: Retrieve Rocketpy Model
MongoDB -->> API: Rocketpy Model
API ->> Rocketpy lib: Rocketpy Model
Rocketpy lib -->> API: Rocketpy native class
API -->> User: Rocketpy native class as .dill binary
API -->> MongoDB: Retrieve API Model document
MongoDB -->> API: API Model document
API ->> RocketPy: Initialize RocketPy native class
RocketPy lib -->> API: RocketPy native class
API -->> User: RocketPy native class as .dill binary (amd64)
```
1 change: 0 additions & 1 deletion lib/controllers/__init__.py

This file was deleted.

Loading