Skip to content

Commit

Permalink
Merge pull request #16 from akirachix/dev
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
Ndichu-shee authored Sep 18, 2024
2 parents ed849a1 + 06a2294 commit 8bc7d31
Show file tree
Hide file tree
Showing 79 changed files with 1,681 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/aquasense.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ jobs:
- name: Run tests
run: |
python manage.py test
- name: Format code with black
run: |
black .
35 changes: 35 additions & 0 deletions .github/workflows/django.yml
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 }}



30 changes: 30 additions & 0 deletions .gitignore
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








6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
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 added api/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions api/apps.py
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 added api/migrations/__init__.py
Empty file.
1 change: 1 addition & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from django.db import models
83 changes: 83 additions & 0 deletions api/serializers.py
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 added api/tests.py
Empty file.
53 changes: 53 additions & 0 deletions api/urls.py
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"}
),
),
]
Loading

0 comments on commit 8bc7d31

Please sign in to comment.