- Updated TenantController to utilize TenantService and DTOs for tenant operations. - Refactored UserController to return UserResponse DTO. - Introduced LeaseService and ApartmentService to handle business logic and data mapping. - Created DTOs for Apartment, Lease, Tenant, and User to standardize data transfer. - Implemented mappers for converting between entities and DTOs using MapStruct. - Removed landlordId from Apartment and Lease entities and adjusted related tests. - Added validation and normalization logic for tenant and guarantor data. - Enhanced unit tests to ensure proper mapping and data integrity during updates.
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable, inject } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
|
|
export interface TenantAttachment {
|
|
id: string;
|
|
fileName: string;
|
|
contentType: string;
|
|
size: number;
|
|
}
|
|
|
|
export interface Tenant {
|
|
id?: string;
|
|
firstName: string;
|
|
lastName: string;
|
|
email: string;
|
|
phone: string;
|
|
address: string;
|
|
attachments?: TenantAttachment[];
|
|
}
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class TenantService {
|
|
private readonly http = inject(HttpClient);
|
|
|
|
getTenants(): Observable<Tenant[]> {
|
|
return this.http.get<Tenant[]>('/api/tenants');
|
|
}
|
|
|
|
createTenant(tenant: Tenant): Observable<Tenant> {
|
|
return this.http.post<Tenant>('/api/tenants', tenant);
|
|
}
|
|
|
|
updateTenant(id: string, tenant: Tenant): Observable<Tenant> {
|
|
return this.http.put<Tenant>(`/api/tenants/${id}`, tenant);
|
|
}
|
|
|
|
deleteTenant(id: string): Observable<void> {
|
|
return this.http.delete<void>(`/api/tenants/${id}`);
|
|
}
|
|
|
|
uploadAttachment(tenantId: string, file: File): Observable<TenantAttachment> {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
return this.http.post<TenantAttachment>(`/api/tenants/${tenantId}/attachments`, formData);
|
|
}
|
|
|
|
downloadAttachment(tenantId: string, attachmentId: string): Observable<Blob> {
|
|
return this.http.get(`/api/tenants/${tenantId}/attachments/${attachmentId}`, {
|
|
responseType: 'blob',
|
|
});
|
|
}
|
|
}
|