Skip to content

Commit

Permalink
Merge pull request #126 from CodeHive-Solutions/dev
Browse files Browse the repository at this point in the history
Remove brothers image
  • Loading branch information
S-e-b-a-s authored Sep 10, 2024
2 parents 7a3e62a + 182e266 commit 8ef2af9
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions INSIGHTSAPI/INSIGHTSAPI/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def str_to_bool(value: str) -> bool:
"employment_management",
"vacation",
"notifications",
"carousel_image",
]

MIDDLEWARE = [
Expand Down
2 changes: 2 additions & 0 deletions INSIGHTSAPI/INSIGHTSAPI/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.conf import settings
from django.urls import include, path
from django.contrib import admin

# from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView


Expand All @@ -44,6 +45,7 @@
path("users/", include("users.urls")),
path("vacation/", include("vacation.urls")),
path("notifications/", include("notifications.urls")),
path("carousel-images/", include("carousel_image.urls")),
]

if settings.DEBUG:
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions INSIGHTSAPI/carousel_image/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 INSIGHTSAPI/carousel_image/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CarouselImageConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'carousel_image'
25 changes: 25 additions & 0 deletions INSIGHTSAPI/carousel_image/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.7 on 2024-09-09 16:51

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Banner',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('link', models.URLField(blank=True, null=True)),
('active', models.BooleanField(default=True)),
('image', models.ImageField(upload_to='carousel_images/banners/')),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
]
Empty file.
12 changes: 12 additions & 0 deletions INSIGHTSAPI/carousel_image/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models


class Banner(models.Model):
title = models.CharField(max_length=100)
link = models.URLField(blank=True, null=True)
active = models.BooleanField(default=True)
image = models.ImageField(upload_to="carousel_images/banners/")
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.title
8 changes: 8 additions & 0 deletions INSIGHTSAPI/carousel_image/serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Banner


class BannerSerializer(serializers.ModelSerializer):
class Meta:
model = Banner
fields = "__all__"
30 changes: 30 additions & 0 deletions INSIGHTSAPI/carousel_image/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from services.tests import BaseTestCase
from django.urls import reverse
from .models import Banner


# Create your tests here.
class BannerTestCase(BaseTestCase):
def setUp(self):
self.banner = Banner.objects.create(
title="Test Banner",
link="https://www.google.com",
active=True,
image="carousel_images/banners/test.jpg",
)

def test_get_banner(self):
banner_2 = self.banner
response = self.client.get(reverse("banners-list"))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
self.assertEqual(response.data[0]["title"], "Test Banner")
self.assertEqual(response.data[0]["link"], "https://www.google.com")
self.assertEqual(response.data[0]["active"], True)
self.assertEqual(response.data[0]["image"], "carousel_images/banners/test.jpg")

def test_delete_banner(self):
response = self.client.delete(reverse("banners-detail", args=[self.banner.id]))
self.assertEqual(response.status_code, 204)
self.assertEqual(Banner.objects.count(), 1)
self.assertEqual(Banner.objects.filter(active=True).count(), 0)
8 changes: 8 additions & 0 deletions INSIGHTSAPI/carousel_image/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework.routers import DefaultRouter
from .views import BannerViewSet

router = DefaultRouter()

router.register(r"banners", BannerViewSet, basename="banners")

urlpatterns = router.urls
16 changes: 16 additions & 0 deletions INSIGHTSAPI/carousel_image/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from rest_framework import viewsets
from rest_framework import status
from rest_framework.response import Response
from .models import Banner
from .serializer import BannerSerializer


class BannerViewSet(viewsets.ModelViewSet):
queryset = Banner.objects.filter(active=True)
serializer_class = BannerSerializer

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
instance.active = False
instance.save()
return Response(status=status.HTTP_204_NO_CONTENT)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-09-09 16:51

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('vacation', '0016_vacationrequest_sat_is_working'),
]

operations = [
migrations.AlterField(
model_name='vacationrequest',
name='status',
field=models.CharField(choices=[('PENDIENTE', 'PENDIENTE'), ('APROBADA', 'APROBADA'), ('RECHAZADA', 'RECHAZADA'), ('CANCELADA', 'CANCELADA')], default='PENDIENTE', max_length=100),
),
]
Binary file removed src/images/home-carousel/brothers.png
Binary file not shown.

0 comments on commit 8ef2af9

Please sign in to comment.