-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from akirachix/dev
Deployment
- Loading branch information
Showing
79 changed files
with
1,681 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,6 @@ jobs: | |
- name: Run tests | ||
run: | | ||
python manage.py test | ||
- name: Format code with black | ||
run: | | ||
black . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Django CI | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Python environment | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.11 | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
- name: Set up Git remote for Heroku | ||
run: | | ||
git remote -v | ||
git remote add heroku https://git.heroku.com/aquasense.git || echo "Heroku remote already exists" | ||
- name: Set Heroku buildpack | ||
run: | | ||
heroku buildpacks:set heroku/python -a aquasense | ||
env: | ||
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}aquasense-project | ||
- name: Deploy to Heroku | ||
uses: akhileshns/[email protected] | ||
with: | ||
heroku_api_key: ${{ secrets.HEROKU_API_KEY }} | ||
heroku_app_name: "aquasense" | ||
heroku_email: ${{ secrets.HEROKU_EMAIL }} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Virtual environment (if applicable) | ||
venv/ | ||
# Environment variables | ||
.env | ||
# Django | ||
db.sqlite3 | ||
__pycache__/ | ||
*.pyc | ||
# Backup files | ||
*.bak | ||
# PyCharm | ||
.idea/ | ||
# Python Packaginga | ||
*.egg-info/ | ||
dist/ | ||
build/ | ||
# VSCode | ||
.vscode/ | ||
# Ignore custom file containing databases | ||
database_config.py | ||
env/ | ||
env | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 23.1.0 | ||
hooks: | ||
- id: black | ||
language_version: python3 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ApiConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "api" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from django.db import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from rest_framework import serializers | ||
from user.models import User, ROLE_CHOICES | ||
from django.contrib.auth.models import User as DjangoUser | ||
from datamonitoring.models import MonitoringData | ||
from drainagesystem.models import DrainageSystem | ||
from sensor.models import Sensor | ||
from map.models import Device | ||
from notification.models import Notification | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
password = serializers.CharField(write_only=True, required=True) | ||
|
||
class Meta: | ||
model = User | ||
fields = [ | ||
"id", | ||
"first_name", | ||
"last_name", | ||
"phone_number", | ||
"email", | ||
"role", | ||
"password", | ||
] | ||
read_only_fields = ["id"] | ||
|
||
def create(self, validated_data): | ||
django_user = DjangoUser.objects.create_user( | ||
username=validated_data["email"], | ||
email=validated_data["email"], | ||
password=validated_data["password"], | ||
) | ||
user = User.objects.create( | ||
user=django_user, | ||
first_name=validated_data["first_name"], | ||
last_name=validated_data["last_name"], | ||
phone_number=validated_data["phone_number"], | ||
email=validated_data["email"], | ||
role=validated_data["role"], | ||
) | ||
return user | ||
|
||
|
||
class RoleSerializer(serializers.Serializer): | ||
user_id = serializers.IntegerField() | ||
# role = serializers.ChoiceField(choices=User.ROLE_CHOICES) | ||
|
||
|
||
class MonitoringDataSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = MonitoringData | ||
fields = [ | ||
"monitoring_id", | ||
"user_id", | ||
"drainage_id", | ||
"timestamp", | ||
"water_level", | ||
"water_pressure", | ||
] | ||
|
||
|
||
class DrainageSystemSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = DrainageSystem | ||
fields = "__all__" | ||
|
||
|
||
class DeviceSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Device | ||
fields = ["id", "latitude", "longitude", "address", "type"] | ||
|
||
|
||
class SensorSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Sensor | ||
fields = ["Sensor_ID", "Type", "Location", "Status", "Time_Date"] | ||
|
||
|
||
class NotificationSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Notification | ||
fields = ["id", "title", "message", "type", "created_at"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django.urls import path | ||
from .views import UserListView, UserDetailView, RegisterView, LoginView, RoleBasedView | ||
from django.urls import path, include | ||
from rest_framework.routers import DefaultRouter | ||
from .views import MonitoringDataViewSet | ||
from .views import DrainageSystemList, DrainageSystemDetail | ||
from map.views import map_view | ||
from map.views import MapDeviceListView, DeviceSearchView, map_view | ||
from .views import SensorListCreateView, SensorDetailView | ||
from .views import NotificationViewSet | ||
|
||
router = DefaultRouter() | ||
router.register(r"monitoring-data", MonitoringDataViewSet) | ||
router = DefaultRouter() | ||
router.register(r"notifications", NotificationViewSet) | ||
urlpatterns = router.urls | ||
|
||
urlpatterns = [ | ||
path("", include(router.urls)), | ||
path("users/", UserListView.as_view(), name="user-list"), | ||
path("users/<int:id>/", UserDetailView.as_view(), name="user-detail"), | ||
path("users/register/", RegisterView.as_view(), name="user-register"), | ||
path("users/login/", LoginView.as_view(), name="user-login"), | ||
path("users/role-based/", RoleBasedView.as_view(), name="role-based"), | ||
path("", include(router.urls)), | ||
path( | ||
"drainage-systems/", DrainageSystemList.as_view(), name="drainage-system-list" | ||
), | ||
path( | ||
"drainage-systems/<int:pk>/", | ||
DrainageSystemDetail.as_view(), | ||
name="drainage-system-detail", | ||
), | ||
path("api", map_view, name="map_view"), | ||
path("map/", map_view, name="map_view"), | ||
path("devices/", MapDeviceListView.as_view(), name="device-list"), | ||
path("search/", DeviceSearchView.as_view(), name="device-search"), | ||
path("sensors/", SensorListCreateView.as_view(), name="sensor-list-create"), | ||
path("sensors/<int:pk>/", SensorDetailView.as_view(), name="sensor-detail"), | ||
path( | ||
"notifications/", NotificationViewSet.as_view({"get": "list", "post": "create"}) | ||
), | ||
path( | ||
"datamonitoring/", | ||
MonitoringDataViewSet.as_view({"get": "list", "post": "create"}), | ||
), | ||
path( | ||
"notifications/<int:pk>/", | ||
NotificationViewSet.as_view( | ||
{"get": "retrieve", "put": "update", "delete": "destroy"} | ||
), | ||
), | ||
] |
Oops, something went wrong.