Skip to content
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

Task(Sprints-da-Loucura): Merge das Sprints realizadas no recesso consolidando melhorias e novas funcionalidades ao projeto #122

Merged
merged 47 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
587e80e
Refactor(Banco de dados): Banco de dados configurado para usar enviro…
Potatoyz908 Dec 25, 2024
73adb61
Refactor(Settings.py): Atualiza para receber todos os hosts
Potatoyz908 Dec 26, 2024
4031694
Refactor(chat): Atualiza a estrutura do chat e melhora o tratamento …
Potatoyz908 Dec 26, 2024
ee031aa
Merge pull request #108 from unb-mds/106/feat/codecov-implementação-d…
Potatoyz908 Dec 26, 2024
c414c89
Feat(Django-Filter): Add django-filter para API requirements
Potatoyz908 Dec 27, 2024
c47a42f
Feat(models): Ajuste item model com category, color, e status fields;…
Potatoyz908 Dec 27, 2024
747831c
Feat(migrations): Add Category model e atualiza Item model com color,…
Potatoyz908 Dec 27, 2024
564a716
Merge branch 'main-da-loucura' into 109/refactor/ajuste-no-cadastro-d…
Potatoyz908 Dec 27, 2024
4534885
Merge pull request #110 from unb-mds/109/refactor/ajuste-no-cadastro-…
Potatoyz908 Dec 27, 2024
faab01f
feat(users): Implementação inicial para a captação de dados do usuári…
Dec 27, 2024
a4cf42a
feat(users): Cadastro de usuário funcional, captação de foto do usuár…
Dec 27, 2024
e06f279
feat(front): implementação do favicon
Davicamilo23 Dec 29, 2024
05db9ee
Update favicon
Davicamilo23 Dec 29, 2024
561e6f1
Feat(models): Add Color e Brand models; atualiza Item model para usar…
Potatoyz908 Dec 29, 2024
599375d
Feat(serializers): Adiciona ColorSerializer e BrandSerializer; atuali…
Potatoyz908 Dec 29, 2024
7d89bf4
Feat(views): Adiciona ColorViewSet e BrandViewSet; atualiza ItemViewS…
Potatoyz908 Dec 29, 2024
180ea4e
Feat(urls): Adiciona rotas para ColorViewSet e BrandViewSet
Potatoyz908 Dec 29, 2024
48b45ed
Feat(migrations): Adiciona modelos Brand e Color; atualiza Item para …
Potatoyz908 Dec 29, 2024
76c8cf6
Feat(serializers): Altera ColorSerializer e BrandSerializer para herd…
Potatoyz908 Dec 29, 2024
ed75a18
feat(user): Captação da foto do usuário pelo Microsoft Graph finalizada
Dec 29, 2024
da85a28
Merge pull request #113 from unb-mds/111/refactor/implementar-o-siste…
Potatoyz908 Dec 29, 2024
ae5dab8
Merge branch 'main-da-loucura' of https://github.com/unb-mds/2024-2-A…
314dro Dec 29, 2024
d620229
Merge pull request #114 from unb-mds/105/feat/gerenciamento-da-sessão…
314dro Dec 29, 2024
bfdef07
feat(migrations): Adiciona nova migração de mesclagem para o modelo d…
Potatoyz908 Dec 29, 2024
c1b1990
chore(.gitignore): Atualizando o .gitignore
314dro Dec 29, 2024
3a59fd0
Update favicon
Davicamilo23 Dec 29, 2024
485336d
Merge pull request #116 from unb-mds/112/feat/favicon
Davicamilo23 Dec 29, 2024
15db904
Feat(Favicon): Adiciona favicon às páginas HTML
Potatoyz908 Dec 30, 2024
b44be77
feat(requirements): Atualiza urllib3 para versão compatível e adicion…
Potatoyz908 Dec 30, 2024
80c6279
feat(cloudinary): Integra Cloudinary para upload de imagens e atualiz…
Potatoyz908 Dec 30, 2024
d25bcf6
refactor(API): Remove espaços em branco e melhora a formatação do código
Potatoyz908 Dec 30, 2024
04f9d74
fix(API): Corrige comentário sobre upload de imagem para o Cloudinary
Potatoyz908 Dec 30, 2024
599996b
feat(API): Adiciona suporte para upload de imagens e corrige campos d…
Potatoyz908 Dec 30, 2024
174d02b
feat(API): Atualiza serializadores para suportar upload de múltiplas …
Potatoyz908 Dec 30, 2024
ac66472
feat(API): Adiciona validação para limite de 3 imagens por item no up…
Potatoyz908 Dec 30, 2024
7997e55
Merge pull request #119 from unb-mds/118/feat/taskcloudinary-implemen…
Potatoyz908 Dec 30, 2024
0421eab
feat(API): Adiciona ruff como dependência para linting de código
Potatoyz908 Dec 30, 2024
8760b80
feat(API): Atualiza .gitignore e requirements.txt para incluir __pyca…
Potatoyz908 Dec 31, 2024
1cc4cbe
fix(API): Corrige aspas em manage.py e adiciona nova linha no final d…
Potatoyz908 Dec 31, 2024
10a44a0
feat(API): Adiciona suporte ao Black e Ruff para formatação e verific…
Potatoyz908 Dec 31, 2024
30de7b8
refactor(codebase): Organiza importações e melhora formatação
Potatoyz908 Dec 31, 2024
59c631c
refactor(admin): Remove importação não utilizada do Django admin
Potatoyz908 Dec 31, 2024
7872d7b
refactor(admin): Remove linha em branco desnecessária em admin.py
Potatoyz908 Dec 31, 2024
127126c
fix(ruff): Remove erro relacionado ao serviço ruff do docker-compose.yml
Potatoyz908 Dec 31, 2024
9668861
fix(requirements): Remove pre-commit da lista de dependências
Potatoyz908 Dec 31, 2024
1fa35a4
Refactor(images): Remove imagens de teste
Potatoyz908 Dec 31, 2024
c407ae7
Merge pull request #121 from unb-mds/120/feat/mplementação-do-ruff-no…
Potatoyz908 Dec 31, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.env
*.log
*.tmp
__pycache__
__pycache__/
secrets.env

API/media/
Binary file modified API/AcheiUnB/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified API/AcheiUnB/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified API/AcheiUnB/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions API/AcheiUnB/asgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application

from chat.routing import websocket_urlpatterns

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "AcheiUnB.settings")
Expand Down
49 changes: 28 additions & 21 deletions API/AcheiUnB/settings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
"""
Django settings for AcheiUnB project.

Generated by 'django-admin startproject' using Django 5.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

import os
from pathlib import Path
from datetime import timedelta
from pathlib import Path

import cloudinary
import cloudinary.uploader
from decouple import config

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -27,8 +19,12 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["0.0.0.0", "localhost"]

ALLOWED_HOSTS = ["*"]
AUTH_USER_MODEL = "auth.User"
MEDIA_URL = "/media/" # Prefixo da URL para os arquivos
MEDIA_ROOT = os.path.join(
BASE_DIR, "/home/pedroubu/Imagens/AcheiUnBFt"
) # Diretório onde os arquivos serão salvos

# Application definition

Expand All @@ -40,6 +36,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django_filters",
"users",
"rest_framework",
"AcheiUnB",
Expand Down Expand Up @@ -73,6 +70,8 @@
"DEFAULT_RENDERER_CLASSES": [
"rest_framework.renderers.JSONRenderer", # Apenas JSON será usado
],
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 10,
}

SIMPLE_JWT = {
Expand All @@ -87,7 +86,7 @@
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.channels_redis", # Para desenvolvimento local
"BACKEND": "channels.layers.InMemoryChannelLayer",
# "BACKEND": "channels.layers.InMemoryChannelLayer",
},
}

Expand Down Expand Up @@ -143,14 +142,22 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "db",
"USER": "postgres",
"PASSWORD": "senha",
"HOST": "db",
"PORT": "5432",
"NAME": os.getenv("DB_NAME"),
"USER": os.getenv("DB_USER"),
"PASSWORD": os.getenv("DB_PASSWORD"),
"HOST": os.getenv("DB_HOST"),
"PORT": os.getenv("DB_PORT"),
}
}

# Cloudinary


cloudinary.config(
cloud_name=config("CLOUDINARY_CLOUD_NAME"),
api_key=config("CLOUDINARY_API_KEY"),
api_secret=config("CLOUDINARY_API_SECRET"),
)

# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 15 additions & 12 deletions API/AcheiUnB/static/dist/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="UTF-8">
<!-- <link rel="icon" href="/favicon.ico"> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AcheiUnB</title>
<script type="module" crossorigin src="/static/dist/js/index-DnGNr4YP.js"></script>
<link rel="stylesheet" crossorigin href="/static/dist/assets/index-B8Uo463z.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

<head>
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="/static/dist/assets/Favicon-DZaE_dAz.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AcheiUnB</title>
<script type="module" crossorigin src="/static/dist/js/index-DnGNr4YP.js"></script>
<link rel="stylesheet" crossorigin href="/static/dist/assets/index-B8Uo463z.css">
</head>

<body>
<div id="app"></div>
</body>

</html>
19 changes: 12 additions & 7 deletions API/AcheiUnB/urls.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.shortcuts import render
from django.urls import include, path
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
from django.shortcuts import render

from users import views
from users.views import microsoft_callback
from users.views import DeleteUserView, microsoft_callback


# View para servir o arquivo Vue.js
def vue_app(request):
return render(
request, "index.html"
) # Caminho para o index.html dentro da pasta templates
return render(request, "index.html") # Caminho para o index.html dentro da pasta templates


urlpatterns = [
Expand All @@ -35,4 +35,9 @@ def vue_app(request):
), # Atualizar token de acesso
path("api/chat/", include("chat.urls")),
path("api/", include("users.urls")),
path("delete-user/<int:user_id>/", DeleteUserView.as_view(), name="delete_user"),
]

# Adiciona a configuração para servir arquivos estáticos no desenvolvimento
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2 changes: 1 addition & 1 deletion API/AcheiUnB/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AcheiUnB.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "AcheiUnB.settings")

application = get_wsgi_application()
42 changes: 30 additions & 12 deletions API/chat/consumers.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
import json

from asgiref.sync import sync_to_async
from channels.generic.websocket import AsyncWebsocketConsumer

from .models import ChatRoom, Message


class ChatConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.chat_id = self.scope["url_route"]["kwargs"]["chat_id"]
self.chat_group_name = f"chat_{self.chat_id}"
self.room_id = self.scope["url_route"]["kwargs"]["room_id"]
self.room_group_name = f"chat_{self.room_id}"

# Join the chat group
await self.channel_layer.group_add(self.chat_group_name, self.channel_name)
await self.accept()
# Verifica se o usuário tem acesso à sala
room = await sync_to_async(ChatRoom.objects.get)(id=self.room_id)
user = self.scope["user"]
if user not in {room.participant_1, room.participant_2}:
await self.close()
else:
await self.channel_layer.group_add(self.room_group_name, self.channel_name)
await self.accept()

async def disconnect(self, close_code):
# Leave the chat group
await self.channel_layer.group_discard(self.chat_group_name, self.channel_name)
await self.channel_layer.group_discard(self.room_group_name, self.channel_name)

async def receive(self, text_data):
data = json.loads(text_data)
message = data["message"]
message_content = data["message"]
sender = self.scope["user"]

# Salva a mensagem no banco
room = await sync_to_async(ChatRoom.objects.get)(id=self.room_id)
message = await sync_to_async(Message.objects.create)(
room=room, sender=sender, content=message_content
)

# Send message to the group
# Envia a mensagem para o grupo
await self.channel_layer.group_send(
self.chat_group_name,
self.room_group_name,
{
"type": "chat_message",
"message": message,
"message": message_content,
"sender": sender.username,
"timestamp": message.timestamp.isoformat(),
},
)

async def chat_message(self, event):
# Send message to WebSocket
await self.send(
text_data=json.dumps(
{
"message": event["message"],
"sender": event["sender"],
"timestamp": event["timestamp"],
}
)
)
53 changes: 42 additions & 11 deletions API/chat/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand All @@ -15,21 +14,53 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='Chat',
name="Chat",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('participants', models.ManyToManyField(related_name='chats', to=settings.AUTH_USER_MODEL)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"participants",
models.ManyToManyField(related_name="chats", to=settings.AUTH_USER_MODEL),
),
],
),
migrations.CreateModel(
name='Message',
name="Message",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('timestamp', models.DateTimeField(auto_now_add=True)),
('chat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='chat.chat')),
('sender', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("content", models.TextField()),
("timestamp", models.DateTimeField(auto_now_add=True)),
(
"chat",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="messages",
to="chat.chat",
),
),
(
"sender",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
Loading
Loading