Skip to content

Commit

Permalink
Merge pull request #24 from Cirilus/feedback
Browse files Browse the repository at this point in the history
Feedback
  • Loading branch information
Cirilus authored Dec 5, 2023
2 parents b69600c + 6eb4990 commit 9feacaf
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 41 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/HackatonService_CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:
push:
branches:
- master
- CI_CD


pull_request:
branches:
- master
- CI_CD


jobs:
run_CI:
Expand Down Expand Up @@ -88,6 +88,7 @@ jobs:
python manage.py test Resume.tests.Work_tests
python manage.py test Score.tests.HistoryPoint_tests
python manage.py test Score.tests.PointCondition_tests
python manage.py test users.tests.Feedback_tests

# добавить тесты Вити когда он их пофиксит
# что еще нужно делать? полностью билдить проект - это же уже к CD относится? (разворачивать докер и все такое..)
6 changes: 3 additions & 3 deletions Resume/tests/Contact_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def test_create_contact(self):

def test_delete_contact_by_own(self):
# удаление записи по id ||api/v1/contactlist/<int: pk>/
url_by_resume_id = url = reverse("contact-detail", kwargs={'pk': 2})
response = self.client.delete(url_by_resume_id)
url_by_own_id = url = reverse("contact-detail", kwargs={'pk': 2})
response = self.client.delete(url_by_own_id)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

count_of_records = Contact.objects.filter(resume_id=1).count()
count_of_records = Contact.objects.filter(pk=2).count()
self.assertEqual(count_of_records, 0)

def test_update_contact_by_own_id(self):
Expand Down
2 changes: 1 addition & 1 deletion Resume/tests/Resume_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_get_resume_by_userid(self):
self.assertEqual({"error": "Резюме с таким user_id 10 не существует."}, response.data)

def test_delete_resume_by_userid(self):
# получение записи по id ||api/v1/resumelist/byuserid/<int: user_id>/
# удаление записи по id ||api/v1/resumelist/byuserid/<int: user_id>/
url_by_user_id = '/api/v1/resumelist/byuserid/1/'
response = self.client.delete(url_by_user_id)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Expand Down
3 changes: 0 additions & 3 deletions Resume/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,5 @@

path('api/v1/educationlist/byresumeid/<int:resume_id>/', EducationCRUD.as_view({'get': 'byresumeid'})),


path('helpcd/', cd_test_endpoint, name='cd_test_endpoint'),

]

34 changes: 23 additions & 11 deletions Resume/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

from drf_spectacular.utils import extend_schema

from .serializers import ResumeSerializer, GraduationSerializer, EducationSerializer, WorkSerializer, ContactSerializer, HackatonsSerializer
from .serializers import ResumeSerializer, GraduationSerializer, EducationSerializer, WorkSerializer, ContactSerializer, \
HackatonsSerializer

from .models import Resume, Graduation, Education, Work, Contact, Hackatons


@extend_schema(description="Resume URLs:", tags=["Resume"])
@extend_schema(description="Resume URLs: (CRUD по Resume по собственному id)", tags=["Resume"])
class ResumeCRUD(viewsets.ModelViewSet):
permission_classes = [AllowAny, ]
queryset = Resume.objects.all()
Expand All @@ -28,6 +29,9 @@ def get_queryset(self):

return queryset

@extend_schema(
description='получить резюме относящиеся к пользователю с определенным user_id + можно выставить фильтрацию по полю visible &visible=true/false',
)
def byuserid(self, request, user_id=None):
self.lookup_field = 'user_id'

Expand Down Expand Up @@ -59,12 +63,15 @@ def byuserid(self, request, user_id=None):


# получение списка всех объектов, получение создание удаление изменение объектов по resume_id
@extend_schema(description="Work URLs:", tags=["Work"])
@extend_schema(description="Work URLs: (CRUD по Work)", tags=["Work"])
class WorkCRUD(viewsets.ModelViewSet):
permission_classes = [AllowAny, ]
queryset = Work.objects.all()
serializer_class = WorkSerializer

@extend_schema(
description='получить works относящиеся к пользователю с определенным resume',
)
@action(detail=False, methods=['get'], ) # может добавить и другие методы?
def byresumeid(self, request, resume_id=None):
# http://127.0.0.1:8000/api/v1/worklist/byuserid/<int:user_id>/
Expand All @@ -82,12 +89,15 @@ def byresumeid(self, request, resume_id=None):


# получение списка всех объектов, получение создание удаление изменение объектов по resume_id
@extend_schema(description="Contact URLs:", tags=["Contact"])
@extend_schema(description="Contact URLs: (CRUD по Contact)", tags=["Contact"])
class ContactCRUD(viewsets.ModelViewSet):
permission_classes = [AllowAny, ]
queryset = Contact.objects.all()
serializer_class = ContactSerializer

@extend_schema(
description='получить contacts относящиеся к пользователю с определенным resume',
)
@action(detail=False, methods=['get'], ) # может добавить и другие методы?
def byresumeid(self, request, resume_id=None):
# http://127.0.0.1:8000/api/v1/pointconditionlist/byuserid/<int:user_id>/
Expand All @@ -105,12 +115,15 @@ def byresumeid(self, request, resume_id=None):


# получение списка всех объектов, получение создание удаление изменение объектов по resume_id
@extend_schema(description="Hackatons URLs:", tags=["Hackatons"])
@extend_schema(description="Hackatons URLs: (CRUD по Hackatons)", tags=["Hackatons"])
class HackatonsCRUD(viewsets.ModelViewSet):
permission_classes = [AllowAny, ]
queryset = Hackatons.objects.all()
serializer_class = HackatonsSerializer

@extend_schema(
description='получить hackatons относящиеся к пользователю с определенным resume',
)
@action(detail=False, methods=['get'], )
def byresumeid(self, request, resume_id=None):
# http://127.0.0.1:8000/api/v1/hackatonslist/byresumeid/<int:user_id>/
Expand All @@ -128,12 +141,15 @@ def byresumeid(self, request, resume_id=None):


# получение списка всех объектов, получение создание удаление изменение объектов по resume_id
@extend_schema(description="Education URLs:", tags=["Education"])
@extend_schema(description="Education URLs: (CRUD по Education)", tags=["Education"])
class EducationCRUD(viewsets.ModelViewSet):
permission_classes = [AllowAny, ]
queryset = Education.objects.all()
serializer_class = EducationSerializer

@extend_schema(
description='получить education относящиеся к пользователю с определенным resume',
)
@action(detail=False, methods=['get'], ) # может добавить и другие методы?
def byresumeid(self, request, resume_id=None):
# http://127.0.0.1:8000/api/v1/educationlist/byresumeid/<int:user_id>/
Expand All @@ -151,14 +167,10 @@ def byresumeid(self, request, resume_id=None):


# получение списка всех объектов, получение создание удаление изменение объектов по id
@extend_schema(description="Graduation URLs:", tags=["Graduation"])
@extend_schema(description="Graduation URLs: (CRUD по Graduation)", tags=["Graduation"])
class GraduationCRUD(viewsets.ModelViewSet):
permission_classes = [AllowAny, ]
queryset = Graduation.objects.all()
serializer_class = GraduationSerializer


from django.http import JsonResponse

def cd_test_endpoint(request):
return JsonResponse({'cd_test': 'ok'})
7 changes: 6 additions & 1 deletion app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'drf_spectacular_sidecar',
'rest_framework',
'corsheaders',
'django_filters',

'Authentication.apps.AuthenticationConfig',
'Hackaton',
Expand Down Expand Up @@ -163,7 +164,11 @@

'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
]
],

'DEFAULT_FILTER_BACKENDS': [
'django_filters.rest_framework.DjangoFilterBackend'
],
}

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ djangorestframework-simplejwt = "^4.7.1"
psycopg2-binary = "^2.9.9"
pillow = "^10.1.0"
psycopg = {extras = ["binary"], version = "^3.1.13"}
django-filter = "^23.4"


[build-system]
Expand Down
14 changes: 13 additions & 1 deletion users/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
from .models import User, Feedback

class CustomUserAdmin(admin.ModelAdmin):
model = User
Expand All @@ -12,3 +12,15 @@ class CustomUserAdmin(admin.ModelAdmin):
admin.site.register(User, CustomUserAdmin)



class FeedbackAdmin(admin.ModelAdmin):
model = Feedback
list_display = ('user', 'contact_back', 'create_at', 'status')
list_filter = ('user', 'contact_back', 'create_at', 'status')

search_fields = ('user', 'contact_back', 'create_at', 'status')

admin.site.register(Feedback, FeedbackAdmin)



18 changes: 18 additions & 0 deletions users/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from .models import Feedback

import django_filters





class FeedbackFilter(django_filters.FilterSet):
create_at = django_filters.DateFilter(lookup_expr='date__exact')
create_at__gt = django_filters.DateFilter(field_name='create_at', lookup_expr='gt')
create_at__lt = django_filters.DateFilter(field_name='create_at', lookup_expr='lt')


class Meta:
model = Feedback
fields = ['create_at', 'status' ]
19 changes: 18 additions & 1 deletion users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by Django 4.2.5 on 2023-11-27 19:19
# Generated by Django 4.2.7 on 2023-12-05 07:01

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down Expand Up @@ -34,4 +36,19 @@ class Migration(migrations.Migration):
'abstract': False,
},
),
migrations.CreateModel(
name='Feedback',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('contact_back', models.CharField(blank=True, max_length=150, verbose_name='Способ связи с пользователем')),
('feedback_massage', models.TextField(verbose_name='Фидбек пользователя')),
('create_at', models.DateTimeField(auto_now_add=True, verbose_name='Время создания фидбек-месседжа')),
('status', models.CharField(choices=[('New', 'New'), ('Current', 'Current'), ('Completed', 'Completed')], default='New', max_length=60, verbose_name='Статус заявки')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='feedback', to=settings.AUTH_USER_MODEL, verbose_name='user_id')),
],
options={
'verbose_name': 'Обратная связь',
'verbose_name_plural': 'Обратная связь',
},
),
]
26 changes: 26 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.contrib.auth.hashers import make_password
from django.db import models
import datetime
from django.db.models.signals import post_save
from django.dispatch import receiver

class UserManager(BaseUserManager):
def create_user(self, email, password=None, **extra_fields):
Expand Down Expand Up @@ -39,3 +41,27 @@ def __str__(self):
return self.email



class Feedback(models.Model):
class FeedbackChoices(models.TextChoices):
NEW = 'New', 'New'
CURRENT = 'Current', 'Current'
COMPLETED = 'Completed', 'Completed'

user = models.ForeignKey(User, on_delete=models.CASCADE, unique=False,
related_name="feedback", verbose_name='user_id',
null=True)
contact_back = models.CharField(max_length=150, verbose_name="Способ связи с пользователем", blank=True)
feedback_massage = models.TextField(verbose_name="Фидбек пользователя")
create_at = models.DateTimeField(auto_now_add=True, verbose_name='Время создания фидбек-месседжа')
status = models.CharField(max_length=60, choices=FeedbackChoices.choices, default=FeedbackChoices.NEW,
verbose_name='Статус заявки')

class Meta:
verbose_name = "Обратная связь"
verbose_name_plural = "Обратная связь"


def __str__(self):
return f'own_id: {self.pk}, user_id:{self.user}'

12 changes: 10 additions & 2 deletions users/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from .models import User
from .models import User, Feedback
from rest_framework import serializers

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = '__all__'
fields = '__all__'


class FeedbackSerializer(serializers.ModelSerializer):
# разобраться что сериализатор делает с полем даты create_at
class Meta:
model = Feedback
fields = ['id', 'user', 'contact_back', 'feedback_massage', 'create_at', 'status']

Loading

0 comments on commit 9feacaf

Please sign in to comment.