Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:ES2-UFPI/WiseBuilder into servico-de…
Browse files Browse the repository at this point in the history
…-interpretacao-de-string-#30
  • Loading branch information
vitin-m committed Mar 28, 2023
2 parents a5535ed + 35980b1 commit 3c3643f
Show file tree
Hide file tree
Showing 24 changed files with 1,177 additions and 1,071 deletions.
2 changes: 1 addition & 1 deletion src/SearchEngine/infrastructure/message_bus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from framework.infrastructure.connection_util import get_message_bus
from ..application.handlers import SE_COMMAND_HANDLER_MAPPER, SE_EVENT_HANDLER_MAPPER
from ..application.unit_of_work import SQLAlchemyUnitOfWork
from ..application.unit_of_work import SQLAlchemyUnitOfWork, MockUnitOfWork

__all__ = ["se_message_bus"]

Expand Down
7 changes: 5 additions & 2 deletions src/entrypoints/api/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import sys, os
import os
import sys

sys.path.insert(0, os.getcwd())

print(os.getcwd())
from flask import Flask
from flask_cors import CORS
from endpoints.api import blueprint

app = Flask(__name__)
app.register_blueprint(blueprint)

CORS(app, resources={r"/*": {"origins": "*"}})
if __name__ == "__main__":
app.run(debug=True)
3 changes: 3 additions & 0 deletions src/entrypoints/api/endpoints/api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from flask import Blueprint
from flask_restx import Api

from .cpus import cpu_namespace
from .gpus import gpu_namespace
from .psus import psu_namespace
from .motherboards import motherboard_namespace
from .persistence import persistence_namespace
from .ram import ram_namespace
from .search import search_namespace

blueprint: Blueprint = Blueprint("api", __name__, url_prefix="/api/v1")
api: Api = Api(
Expand All @@ -21,3 +23,4 @@
api.add_namespace(motherboard_namespace, "/motherboards")
api.add_namespace(persistence_namespace, "/persistences")
api.add_namespace(ram_namespace, "/rams")
api.add_namespace(search_namespace, "/search")
20 changes: 12 additions & 8 deletions src/entrypoints/api/endpoints/cpus.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import uuid
from typing import List
from uuid import UUID

from flask import request
from flask_restx import Namespace, Resource, fields

from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus
from SearchEngine.domain.repositories import (
EntityUIDNotFoundException,
EntityUIDCollisionException,
)
from SearchEngine.domain.commands import (
AddComponent,
ListComponentsByType,
GetComponentByUID,
ListComponentsByType,
)
from SearchEngine.domain.repositories import (
EntityUIDCollisionException,
EntityUIDNotFoundException,
)
from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus

cpu_namespace = Namespace("CPUs", description="Operações relacionadas à CPUs.")

cpu_model = cpu_namespace.model(
"CPU",
{
"_id": fields.String(description="Identificador da CPU."),
"type": fields.String(description="Tipo do componente."),
"manufacturer": fields.String(required=True, description="Fabricante da CPU."),
"model": fields.String(required=True, description="Modelo da CPU."),
"socket": fields.Integer(required=True, description="Socket da CPU."),
Expand Down Expand Up @@ -48,12 +49,15 @@ class CPUList(Resource):
@cpu_namespace.marshal_list_with(cpu_model)
def get(self):
_cpus = message_bus.handle(ListComponentsByType.CPU())
for _cpu in _cpus:
_cpu.type = _cpu.type._name_
return _cpus

@cpu_namespace.expect(cpu_model)
def post(self):
body: dict = request.json
cpu = dict((key, body[key]) for key in list(cpu_model.keys())[1:])
print(body)
cpu = dict((key, body[key]) for key in list(cpu_model.keys())[2:])
try:
_ = message_bus.handle(AddComponent.buildCPU(**cpu))
return cpu, 201
Expand Down
21 changes: 12 additions & 9 deletions src/entrypoints/api/endpoints/gpus.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from uuid import UUID
from typing import List
from uuid import UUID

from flask import request
from flask_restx import Namespace, Resource, fields

from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus
from SearchEngine.domain.repositories import (
EntityUIDNotFoundException,
EntityUIDCollisionException,
)
from SearchEngine.domain.commands import (
AddComponent,
ListComponentsByType,
GetComponentByUID,
ListComponentsByType,
)
from SearchEngine.domain.repositories import (
EntityUIDCollisionException,
EntityUIDNotFoundException,
)
from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus

gpu_namespace = Namespace("GPUs", description="Operações relacionadas à GPUs.")
gpu_model = gpu_namespace.model(
"GPU",
{
"_id": fields.String(description="Identificador da GPU."),
"type": fields.String(description="Tipo do componente."),
"manufacturer": fields.String(required=True, description="Fabricante da GPU."),
"model": fields.String(required=True, description="Modelo da GPU"),
"consumption": fields.Integer(required=True, description="Consumo da GPU."),
Expand All @@ -38,12 +39,14 @@ class GPUList(Resource):
@gpu_namespace.marshal_list_with(gpu_model)
def get(self):
_gpus = message_bus.handle(ListComponentsByType.GPU())
for _gpu in _gpus:
_gpu.type = _gpu.type._name_
return _gpus

@gpu_namespace.expect(gpu_model)
def post(self):
body: dict = request.json
gpu = dict((key, body[key]) for key in list(gpu_model.keys())[1:])
gpu = dict((key, body[key]) for key in list(gpu_model.keys())[2:])
try:
_ = message_bus.handle(AddComponent.buildGPU(**gpu))
return gpu, 201
Expand Down
23 changes: 13 additions & 10 deletions src/entrypoints/api/endpoints/motherboards.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from uuid import UUID
from typing import List
from flask_restx import Namespace, Resource, fields
from flask import request
from uuid import UUID

from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus
from SearchEngine.domain.repositories import (
EntityUIDNotFoundException,
EntityUIDCollisionException,
)
from flask import request
from flask_restx import Namespace, Resource, fields
from SearchEngine.domain.commands import (
AddComponent,
ListComponentsByType,
GetComponentByUID,
ListComponentsByType,
)
from SearchEngine.domain.repositories import (
EntityUIDCollisionException,
EntityUIDNotFoundException,
)
from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus

motherboard_namespace = Namespace(
"MotherBoards", description="Operações relacionadas à Placa-Mãe."
Expand All @@ -21,6 +21,7 @@
"MotherBoard",
{
"_id": fields.String(description="Identificador da Placa-Mãe."),
"type": fields.String(description="Tipo do componente."),
"manufacturer": fields.String(
required=True, description="Fabricante da Placa-Mãe."
),
Expand Down Expand Up @@ -51,13 +52,15 @@ class MotherBoardList(Resource):
@motherboard_namespace.marshal_list_with(motherboard_model)
def get(self):
_motherboards = message_bus.handle(ListComponentsByType.Motherboard())
for _motherboard in _motherboards:
_motherboard.type = _motherboard.type._name_
return _motherboards

@motherboard_namespace.expect(motherboard_model)
def post(self):
body = request.json
motherboard = dict(
(key, body[key]) for key in list(motherboard_model.keys())[1:]
(key, body[key]) for key in list(motherboard_model.keys())[2:]
)
try:
_ = message_bus.handle(AddComponent.buildMotherboard(**motherboard))
Expand Down
23 changes: 13 additions & 10 deletions src/entrypoints/api/endpoints/persistence.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from uuid import UUID
from typing import List
from flask_restx import Namespace, Resource, fields
from flask import request
from uuid import UUID

from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus
from SearchEngine.domain.repositories import (
EntityUIDNotFoundException,
EntityUIDCollisionException,
)
from flask import request
from flask_restx import Namespace, Resource, fields
from SearchEngine.domain.commands import (
AddComponent,
ListComponentsByType,
GetComponentByUID,
ListComponentsByType,
)
from SearchEngine.domain.repositories import (
EntityUIDCollisionException,
EntityUIDNotFoundException,
)
from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus

persistence_namespace = Namespace(
"Persistences", description="Operações relacionadas à Persistência."
Expand All @@ -21,6 +21,7 @@
"persistence",
{
"_id": fields.String(description="Identificador da Persistência."),
"type": fields.String(description="Tipo do componente."),
"manufacturer": fields.String(
required=True, description="Fabricante da Persistência."
),
Expand All @@ -43,13 +44,15 @@ class persistenceList(Resource):
@persistence_namespace.marshal_list_with(persistence_model)
def get(self):
_persistences = message_bus.handle(ListComponentsByType.Persistence())
for _persistence in _persistences:
_persistence.type = _persistence.type._name_
return _persistences

@persistence_namespace.expect(persistence_model)
def post(self):
body = request.json
persistence = dict(
(key, body[key]) for key in list(persistence_model.keys())[1:]
(key, body[key]) for key in list(persistence_model.keys())[2:]
)
try:
_ = message_bus.handle(AddComponent.buildPersistence(**persistence))
Expand Down
23 changes: 13 additions & 10 deletions src/entrypoints/api/endpoints/psus.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from uuid import UUID
from typing import List
from flask_restx import Namespace, Resource, fields
from flask import request
from uuid import UUID

from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus
from SearchEngine.domain.repositories import (
EntityUIDNotFoundException,
EntityUIDCollisionException,
)
from flask import request
from flask_restx import Namespace, Resource, fields
from SearchEngine.domain.commands import (
AddComponent,
ListComponentsByType,
GetComponentByUID,
ListComponentsByType,
)
from SearchEngine.domain.repositories import (
EntityUIDCollisionException,
EntityUIDNotFoundException,
)
from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus

psu_namespace = Namespace("PSUs", description="Operações relacionadas à PSUs.")
psu_model = psu_namespace.model(
"PSU",
{
"_id": fields.String(description="Identificador da PSU."),
"type": fields.String(description="Tipo do componente."),
"manufacturer": fields.String(required=True, description="Fabricante da PSU."),
"model": fields.String(required=True, description="Modelo da PSU"),
"power": fields.Integer(required=True, description="Potência da fonte."),
Expand All @@ -34,12 +35,14 @@ class PSUList(Resource):
@psu_namespace.marshal_list_with(psu_model)
def get(self):
_psus = message_bus.handle(ListComponentsByType.PSU())
for _psu in _psus:
_psu.type = _psu.type._name_
return _psus

@psu_namespace.expect(psu_model)
def post(self):
body = request.json
psu = dict((key, body[key]) for key in list(psu_model.keys())[1:])
psu = dict((key, body[key]) for key in list(psu_model.keys())[2:])
try:
_ = message_bus.handle(AddComponent.buildPSU(**psu))
return psu, 201
Expand Down
21 changes: 12 additions & 9 deletions src/entrypoints/api/endpoints/ram.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from uuid import UUID
from typing import List
from uuid import UUID

from flask import request
from flask_restx import Namespace, Resource, fields

from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus
from SearchEngine.domain.repositories import (
EntityUIDNotFoundException,
EntityUIDCollisionException,
)
from SearchEngine.domain.commands import (
AddComponent,
ListComponentsByType,
GetComponentByUID,
ListComponentsByType,
)
from SearchEngine.domain.repositories import (
EntityUIDCollisionException,
EntityUIDNotFoundException,
)
from SearchEngine.infrastructure.message_bus import se_message_bus as message_bus

ram_namespace = Namespace("RAMs", description="Operações relacionadas à RAMs.")
ram_model = ram_namespace.model(
"RAM",
{
"_id": fields.String(description="Identificador da memória RAM."),
"type": fields.String(description="Tipo do componente."),
"manufacturer": fields.String(required=True, description="Fabricante da GPU."),
"model": fields.String(required=True, description="Modelo da GPU"),
"generation": fields.Integer(
Expand All @@ -37,12 +38,14 @@ class RAMList(Resource):
@ram_namespace.marshal_list_with(ram_model)
def get(self):
_rams = message_bus.handle(ListComponentsByType.RAM())
for _ram in _rams:
_ram.type = _ram.type._name_
return _rams

@ram_namespace.expect(ram_model)
def post(self):
body = request.json
ram = dict((key, body[key]) for key in list(ram_model.keys())[1:])
ram = dict((key, body[key]) for key in list(ram_model.keys())[2:])
try:
_ = message_bus.handle(AddComponent.buildRAM(**ram))
return ram, 201
Expand Down
Loading

0 comments on commit 3c3643f

Please sign in to comment.