Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ export class DeleteCatalogoController {
try {

const id = req.params.id;
const userID = req.body?.userID as string | undefined;

if (!id) throw new Error('ID não informado')
if (id.length !== 36) throw new Error('ID inválido')
if (!userID) throw new Error('O campo userID deve ser informado')

const deletedCatalogo = this.usecase.execute(id)

const catalogoDeletedEvent: CatalogoEvent = {
eventType: CatalogoEventNames.CatalogoDeleted,
payload: {
userID: "",
userID,
...deletedCatalogo
}
}
Expand All @@ -48,4 +50,4 @@ export class DeleteCatalogoController {

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Environments } from "../../shared/environments";
import { DeletePropertyUsecase } from "./delete_property_usecase";

const repo = Environments.getPropertyRepo();
export const deletePropertyUsecase = new DeletePropertyUsecase(repo);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PropertyRepository } from "../../shared/domain/repo/propertyRepository";

export class DeletePropertyUsecase {

constructor(private repo: PropertyRepository) {}

public execute(userID: string, catalogID: string) {
const userProperties = this.repo.deleteProperty(userID, catalogID);
return userProperties;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ export interface PropertyRepository {
createPropertyManagement(userID: string): PropertyManagement;

createProperty(userID: string, catalog: CatalogoType): PropertyManagement;

deleteProperty(userID: string, catalogID: string): PropertyManagement;
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
import { createPropertyUsecase } from "../../../app/createProperty/create_property_presenter";
import { createPropertyManagementUsecase } from "../../../app/createPropertyManagement/create_property_management_presenter";
import { deletePropertyUsecase } from "../../../app/deleteProperty/delete_property_presenter";
import { CatalogoEventNames, UserEventNames } from "../../infra/clients/rabbitmq/enums";
import { BaseEvent } from "../../infra/clients/rabbitmq/interfaces";
import { consumeEvents } from "../../infra/clients/rabbitmq/rabbitmq";
import { catalogo, userInformation } from "../../infra/clients/rabbitmq/types";



type EventType = keyof typeof eventsFunctions;

const eventsFunctions: { [event in UserEventNames.UserCreated | CatalogoEventNames.CatalogoCreated] : (payload: any) => void } = {

UserCreated: async (userInfo: userInformation) => {
const created_user = createPropertyManagementUsecase.execute(userInfo.id)
console.log(created_user)
const eventsFunctions: Record<string, (payload: any) => Promise<void> | void> = {
[UserEventNames.UserCreated]: async (userInfo: userInformation) => {
const created_user = createPropertyManagementUsecase.execute(userInfo.id);
console.log(created_user);
},
CatalogoCreated: async (catalogoInfo: catalogo) => {

const { userID, ...catalog } = catalogoInfo

const created_catalogo = createPropertyUsecase.execute(userID, catalog)

console.log(created_catalogo)
}

}
[CatalogoEventNames.CatalogoCreated]: async (catalogoInfo: catalogo) => {
const { userID, ...catalog } = catalogoInfo;
const created_catalogo = createPropertyUsecase.execute(userID, catalog);
console.log(created_catalogo);
},
[CatalogoEventNames.CatalogoDeleted]: async (catalogoInfo: catalogo) => {
const { userID, id } = catalogoInfo;
if (!userID) {
console.warn('catalogo.deleted recebido sem userID, ignorando');
return;
}
const deleted = deletePropertyUsecase.execute(userID, id);
console.log(deleted);
},
};

export async function eventHandler(event: BaseEvent) {
try {
const { eventType, payload } = event
eventsFunctions[eventType as EventType](payload);
} catch(err) {
console.log(err)
const handler = eventsFunctions[event.eventType];
if (handler) {
await handler(event.payload);
}
} catch (err) {
console.log(err);
}
}

export const startQueue = async () => {

try {
await consumeEvents("property_queue", "user.created", eventHandler)
await consumeEvents("property_queue", "catalogo.created", eventHandler)
await consumeEvents("property_queue", "catalogo.*", eventHandler)
} catch(err){
console.error("Couldn't start the service queues");
process.exit(1);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,18 @@ export class PropertyRepositoryMock implements PropertyRepository{

}

}
public deleteProperty(userID: string, catalogID: string): PropertyManagement {

const userProperties = this.baseProperty[userID]

if(!userProperties) throw new Error('Usuário não foi encontrado')

if(!userProperties.properties[catalogID]) throw new Error('Não foi encontrado o catálogo para esse usuário')

delete userProperties.properties[catalogID]

return userProperties

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export class CreateUserUsecase {

public execute(props: createUserPropsType) {
if (!userInfoValidation.validateEmail(props.auth.username))
throw new Error("Field email is invalid");
throw new Error("Campo e-mail inválido");

if (!userInfoValidation.validateCPF(props.information.cpf))
throw new Error("Field cpf is invalid");
throw new Error("Campo CPF inválido");

if (!userInfoValidation.validateBirth(props.information.birth))
throw new Error("Field birth must be over 18 years old");
throw new Error("Campo nascimento deve ter mais de 18 anos");

if (!userInfoValidation.validatePhone(props.information.phone))
throw new Error("Field phone is invalid");
throw new Error("Campo telefone inválido");

const user_info = this.repo.createUser(props);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export class UpdateUserUsecase {

public execute(props: updateUserPropsType) {

if(props.cpf && !userInfoValidation.validateCPF(props.cpf)) throw new Error("Field user CPF is invalid")
if(props.cpf && !userInfoValidation.validateCPF(props.cpf)) throw new Error("Campo CPF inválido")

if(props.birth && !userInfoValidation.validateBirth(props.birth)) throw new Error("Field user birth must be over 18 years old")
if(props.birth && !userInfoValidation.validateBirth(props.birth)) throw new Error("Campo nascimento deve ter mais de 18 anos")

if((props.birth) && !userInfoValidation.validateBirth(props.birth)) throw new Error("Field user phone is invalid")
if((props.phone) && !userInfoValidation.validatePhone(props.phone)) throw new Error("Campo telefone inválido")

const user_info = this.repo.updateUser(props)

Expand Down
7 changes: 7 additions & 0 deletions mobile/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
WORKUP_API_BASE=http://localhost
WORKUP_API_HOST=localhost
WORKUP_CATALOGO_PORT=4000
WORKUP_USER_PORT=4001
WORKUP_ALUGUEL_PORT=4002
WORKUP_AVAILABILITY_PORT=4003
WORKUP_PROPERTY_PORT=4004
75 changes: 75 additions & 0 deletions mobile/lib/models/listing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class Listing {
final String id;
final String name;
final String description;
final String address;
final List<String> comodities;
final List<String> pictures;
final double price;
final int capacity;
final String? doorSerial;

const Listing({
required this.id,
required this.name,
required this.description,
required this.address,
required this.comodities,
required this.pictures,
required this.price,
required this.capacity,
this.doorSerial,
});

factory Listing.fromJson(Map<String, dynamic> json) {
return Listing(
id: json['id']?.toString() ?? '',
name: json['name'] ?? '',
description: json['description'] ?? '',
address: json['address'] ?? '',
comodities: List<String>.from(json['comodities'] ?? []),
pictures: List<String>.from(json['pictures'] ?? []),
price: (json['price'] as num?)?.toDouble() ?? 0.0,
capacity: (json['capacity'] as num?)?.toInt() ?? 0,
doorSerial: json['doorSerial']?.toString(),
);
}

Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'description': description,
'address': address,
'comodities': comodities,
'pictures': pictures,
'price': price,
'capacity': capacity,
'doorSerial': doorSerial,
};
}

Listing copyWith({
String? id,
String? name,
String? description,
String? address,
List<String>? comodities,
List<String>? pictures,
double? price,
int? capacity,
String? doorSerial,
}) {
return Listing(
id: id ?? this.id,
name: name ?? this.name,
description: description ?? this.description,
address: address ?? this.address,
comodities: comodities ?? this.comodities,
pictures: pictures ?? this.pictures,
price: price ?? this.price,
capacity: capacity ?? this.capacity,
doorSerial: doorSerial ?? this.doorSerial,
);
}
}
22 changes: 18 additions & 4 deletions mobile/lib/models/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ class Property {
id: json['id']?.toString() ?? '',
name: json['name'] ?? '',
price: (json['price'] is num) ? (json['price'] as num).toDouble() : 0.0,
images: (json['images'] as List<dynamic>?)?.map((e) => e.toString()).toList() ?? [],
images:
(json['images'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
[],
address: json['address'] ?? '',
description: json['description'] ?? '',
rating: json['rating'] != null ? (json['rating'] as num).toDouble() : null,
reviewCount: json['reviewCount'] is int ? json['reviewCount'] as int : (json['reviewCount'] is num ? (json['reviewCount'] as num).toInt() : null),
amenities: (json['amenities'] as List<dynamic>?)?.map((e) => e.toString()).toList() ?? [],
rating: json['rating'] != null
? (json['rating'] as num).toDouble()
: null,
reviewCount: json['reviewCount'] is int
? json['reviewCount'] as int
: (json['reviewCount'] is num
? (json['reviewCount'] as num).toInt()
: null),
amenities:
(json['amenities'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
[],
);
}
}
75 changes: 75 additions & 0 deletions mobile/lib/models/reservation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class Reservation {
static final Reservation empty = Reservation(
id: '',
userId: '',
workspaceId: '',
startDate: 0,
endDate: 0,
people: 0,
finalPrice: 0,
status: '',
createdAt: 0,
updatedAt: 0,
);
final String id;
final String userId;
final String workspaceId;
final int startDate;
final int endDate;
final int people;
final double finalPrice;
final String status;
final String? doorCode;
final int createdAt;
final int updatedAt;

const Reservation({
required this.id,
required this.userId,
required this.workspaceId,
required this.startDate,
required this.endDate,
required this.people,
required this.finalPrice,
required this.status,
required this.createdAt,
required this.updatedAt,
this.doorCode,
});

factory Reservation.fromJson(Map<String, dynamic> json) {
return Reservation(
id: json['id']?.toString() ?? '',
userId: json['userId']?.toString() ?? '',
workspaceId: json['workspaceId']?.toString() ?? '',
startDate: (json['startDate'] as num?)?.toInt() ?? 0,
endDate: (json['endDate'] as num?)?.toInt() ?? 0,
people: (json['people'] as num?)?.toInt() ?? 0,
finalPrice: (json['finalPrice'] as num?)?.toDouble() ?? 0.0,
status: json['status']?.toString() ?? '',
doorCode: json['doorCode']?.toString(),
createdAt: (json['createdAt'] as num?)?.toInt() ?? 0,
updatedAt: (json['updatedAt'] as num?)?.toInt() ?? 0,
);
}

Map<String, dynamic> toJson() {
return {
'id': id,
'userId': userId,
'workspaceId': workspaceId,
'startDate': startDate,
'endDate': endDate,
'people': people,
'finalPrice': finalPrice,
'status': status,
'doorCode': doorCode,
'createdAt': createdAt,
'updatedAt': updatedAt,
};
}

DateTime get startDateTime => DateTime.fromMillisecondsSinceEpoch(startDate);

DateTime get endDateTime => DateTime.fromMillisecondsSinceEpoch(endDate);
}
Loading