-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create building and show in list view
- Loading branch information
1 parent
c9e8bc7
commit 75415bc
Showing
25 changed files
with
627 additions
and
84 deletions.
There are no files selected for viewing
6 changes: 1 addition & 5 deletions
6
sep490-enterprise/src/main/java/enterprise/dtos/BuildingDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
package enterprise.dtos; | ||
|
||
import green_buildings.commons.api.BaseDTO; | ||
import jakarta.validation.constraints.DecimalMin; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Builder; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.UUID; | ||
|
||
@Builder | ||
public record BuildingDTO( | ||
UUID id, | ||
int version, | ||
@NotBlank String name, | ||
@Min(1) int floors, | ||
@DecimalMin(value = "0.0", inclusive = true) BigDecimal squareMeters | ||
long numberOfDevices | ||
) implements BaseDTO { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
sep490-enterprise/src/main/resources/db/migration/V0.0.1.5__CorrectBuilding.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ALTER TABLE buildings | ||
DROP COLUMN floors; | ||
ALTER TABLE buildings | ||
DROP COLUMN square_meters; | ||
|
||
ALTER TABLE buildings | ||
ADD COLUMN number_of_devices BIGINT NOT NULL default 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
sep490-frontend/src/app/modules/core/services/http-error-handler.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
HttpEvent, | ||
HttpHandler, | ||
HttpInterceptor, | ||
HttpRequest | ||
} from '@angular/common/http'; | ||
import {Injectable} from '@angular/core'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {MessageService} from 'primeng/api'; | ||
import {Observable, catchError, throwError} from 'rxjs'; | ||
import {BusinessErrorParam} from '../../shared/models/models'; | ||
|
||
@Injectable() | ||
export class HttpErrorHandlerInterceptor implements HttpInterceptor { | ||
constructor( | ||
private readonly messageService: MessageService, | ||
private readonly translateService: TranslateService | ||
) {} | ||
|
||
intercept( | ||
req: HttpRequest<any>, | ||
next: HttpHandler | ||
): Observable<HttpEvent<any>> { | ||
return next.handle(req).pipe( | ||
catchError((error: any) => { | ||
if (error.error && error.error.errorType === 'TECHNICAL') { | ||
this.handleTechnicalErrorException(error); | ||
} | ||
if (error.error && error.error.errorType === 'BUSINESS') { | ||
this.handleBusinessErrorException(error); | ||
} | ||
return throwError(() => error); | ||
}) | ||
); | ||
} | ||
|
||
private handleTechnicalErrorException(error: any): void { | ||
const message = this.translateService.instant( | ||
'common.error.technicalServerError', | ||
{correlationId: error.error.correlationId} | ||
); | ||
this.messageService.add({ | ||
severity: 'error', | ||
summary: 'Error', | ||
detail: message, | ||
sticky: true | ||
}); | ||
error.error.errorNotified = true; | ||
} | ||
|
||
private handleBusinessErrorException(error: any): void { | ||
if (!error.error.field) { | ||
this.messageService.add({ | ||
severity: 'error', | ||
summary: 'Error', | ||
detail: this.translateService.instant( | ||
`validation.${error.error.i18nKey}`, | ||
this.convertErrorParams(error.error.args) | ||
), | ||
sticky: true | ||
}); | ||
} | ||
error.error.errorNotified = true; | ||
} | ||
|
||
private convertErrorParams(params: BusinessErrorParam[]): { | ||
[key: string]: string; | ||
} { | ||
return params?.reduce( | ||
(result, arg: BusinessErrorParam) => { | ||
result[arg.key] = arg.value; | ||
return result; | ||
}, | ||
{} as {[key: string]: string} | ||
); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...end/src/app/modules/enterprise/components/building-details/building-details.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
@apply flex flex-col gap-6; | ||
} |
73 changes: 73 additions & 0 deletions
73
...nd/src/app/modules/enterprise/components/building-details/building-details.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<span> | ||
<p-button | ||
(onClick)="back()" | ||
class="*:min-w-28" | ||
label="{{ 'common.back' | translate }}" | ||
severity="primary" | ||
outlined="true" | ||
icon="pi pi-arrow-left" | ||
/> | ||
</span> | ||
|
||
<div class="font-medium text-2xl"> | ||
{{ | ||
(isEdit | ||
? "enterprise.buildings.details.edit" | ||
: "enterprise.buildings.details.create" | ||
) | translate | ||
}} | ||
</div> | ||
|
||
<form | ||
[formGroup]="formGroup" | ||
class="grid grid-cols-2 border border-black rounded-lg p-4 gap-4" | ||
> | ||
<div class="flex flex-col gap-2" errorMessages> | ||
<label class="font-medium text-lg" for="name">{{ | ||
"enterprise.buildings.details.labels.name" | translate | ||
}}</label> | ||
<input pInputText formControlName="name" id="name" type="text" /> | ||
<form-field-error></form-field-error> | ||
</div> | ||
<span></span> | ||
|
||
<div class="flex flex-col gap-2" errorMessages> | ||
<label class="font-medium text-lg" for="numberOfDevices">{{ | ||
"enterprise.buildings.details.labels.numberOfDevices" | translate | ||
}}</label> | ||
<input | ||
pInputText | ||
formControlName="numberOfDevices" | ||
id="numberOfDevices" | ||
type="number" | ||
/> | ||
<form-field-error></form-field-error> | ||
</div> | ||
<div class="flex items-center gap-2"> | ||
<i class="pi pi-info-circle text-lg"></i> | ||
{{ | ||
"enterprise.buildings.details.labels.maxNumberOfDevices" | translate | ||
}} | ||
</div> | ||
</form> | ||
|
||
<div class="flex gap-4 justify-end"> | ||
<p-button | ||
(onClick)="reset()" | ||
class="*:min-w-24" | ||
label="{{ 'common.revert' | translate }}" | ||
[outlined]="true" | ||
/> | ||
<p-button | ||
(onClick)="submit()" | ||
class="*:min-w-16" | ||
label="{{ (isEdit ? 'common.save' : 'common.create') | translate }}" | ||
/> | ||
</div> | ||
|
||
<ng-template> | ||
<p-floatlabel variant="on"> | ||
<input pInputText formControlName="name" id="on_label" /> | ||
<label for="on_label">On Label</label> | ||
</p-floatlabel> | ||
</ng-template> |
Oops, something went wrong.