Commit b4827927 authored by vtduong0912's avatar vtduong0912

update: refactored

parent 4608598b
export namespace Jobs { export namespace JobApi {
export type Job = { export interface Response {
id: null | string; id: string;
type: string; type: string;
created_at: string; created_at: string;
company: string; company: string;
...@@ -13,21 +13,7 @@ export namespace Jobs { ...@@ -13,21 +13,7 @@ export namespace Jobs {
url?: string; url?: string;
} }
export interface GetResponse { export interface Request {
items: Job[];
total: number
}
export type GetRequest = {
}
export interface Response {
newItem: Job
}
export type Request = {
id: string;
type: string; type: string;
created_at: string; created_at: string;
company: string; company: string;
......
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { Jobs } from "../model/job-manager.model"; import { JobApi } from "../model/job-manager.model";
import { ResponseResult, Rows } from "../../../../../shared/data-access/interface/response.type"; import { ResponseResult, Rows } from "../../../../../shared/data-access/interface/response.type";
@Injectable({ @Injectable({
...@@ -10,7 +10,7 @@ export class JobManagerService { ...@@ -10,7 +10,7 @@ export class JobManagerService {
constructor(private _http: HttpClient) {} constructor(private _http: HttpClient) {}
jobsGet(pageIndex: number = 1, pageSize: number = 5) { jobsGet(pageIndex: number = 1, pageSize: number = 5) {
return this._http.get<ResponseResult<Rows<Jobs.Job>>>('jobs', { return this._http.get<ResponseResult<Rows<JobApi.Response>>>('jobs', {
params: { params: {
page: pageIndex, page: pageIndex,
take: pageSize take: pageSize
...@@ -18,17 +18,15 @@ export class JobManagerService { ...@@ -18,17 +18,15 @@ export class JobManagerService {
}); });
} }
jobsPost(request: Jobs.Request) { jobsPost(request: JobApi.Request) {
return this._http.post<ResponseResult<Jobs.Response>>('jobs', request); return this._http.post<ResponseResult<JobApi.Request>>('jobs', request);
} }
jobsPut(request: Jobs.Request) { jobsPut(request: JobApi.Request) {
return this._http.put<ResponseResult<Jobs.Response>>('jobs', request); return this._http.put<ResponseResult<JobApi.Request>>('jobs', request);
} }
jobsDelete(request: Jobs.Request) { jobsDelete(id: number) {
return this._http.delete<ResponseResult<Jobs.Response>>('jobs', { return this._http.delete<ResponseResult<JobApi.Request>>('jobs');
body: request
});
} }
} }
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'job-form',
standalone: true,
template: `
`
})
export class JobFormComponent implements OnInit {
isHidden: boolean = true;
constructor() { }
ngOnInit() { }
}
\ No newline at end of file
...@@ -5,7 +5,7 @@ import { CommonModule } from '@angular/common'; ...@@ -5,7 +5,7 @@ import { CommonModule } from '@angular/common';
import { JobManagerService } from '../data-access/service/job-manager.service'; import { JobManagerService } from '../data-access/service/job-manager.service';
import { catchError, of, tap } from 'rxjs'; import { catchError, of, tap } from 'rxjs';
import { ResponseResult, Rows } from '../../../../shared/data-access/interface/response.type'; import { ResponseResult, Rows } from '../../../../shared/data-access/interface/response.type';
import { Jobs } from '../data-access/model/job-manager.model'; import { JobApi } from '../data-access/model/job-manager.model';
import { NzButtonModule } from 'ng-zorro-antd/button'; import { NzButtonModule } from 'ng-zorro-antd/button';
@Component({ @Component({
...@@ -15,38 +15,49 @@ import { NzButtonModule } from 'ng-zorro-antd/button'; ...@@ -15,38 +15,49 @@ import { NzButtonModule } from 'ng-zorro-antd/button';
CommonModule, CommonModule,
NzLayoutModule, NzLayoutModule,
NzTableModule, NzTableModule,
NzButtonModule NzButtonModule,
], ],
styles: `
nz-table[_ngcontent-jjj-c198] nz-pagination[_ngcontent-jjj-c198] {
justify-content: center;
}
`,
template: ` template: `
<nz-content class="tw-my-3"> <nz-content class="tw-my-3">
<button nz-button nzType="primary">Create new job</button>
<nz-table <nz-table
#rowTable #rowTable
[nzData]="jobsList" [nzData]="jobsList"
[nzPageSize]="5" [nzPageSize]="5"
nzShowPagination nzShowPagination
nzShowSizeChanger nzShowSizeChanger
[nzPageSizeOptions]="[5, 10, 25, 50, 100]" [nzPageSizeOptions]="[5, 10, 25, 50, 100]"
class="tw-my-3" class="tw-my-3"
> >
<thead> <thead>
<tr> <tr>
<th class="tw-text-start"> <th>
Ord.
</th>
<th>
Title Title
</th> </th>
<th class="tw-text-start"> <th>
Company Company
</th> </th>
<th class="tw-text-start"> <th>
Created at Created at
</th> </th>
<th class="tw-text-start"> <th>
Actions Actions
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let job of rowTable.data" class="tw-border-b"> <tr *ngFor="let job of rowTable.data; let idx = index" class="tw-border-b">
<td>
<p> {{ rowTable.nzPageSize * (rowTable.nzPageIndex - 1) + idx }}</p>
</td>
<td> <td>
<p>{{ job.title }}</p> <p>{{ job.title }}</p>
</td> </td>
...@@ -71,7 +82,7 @@ export class JobListComponent implements OnInit { ...@@ -71,7 +82,7 @@ export class JobListComponent implements OnInit {
pageIndex: number = 1; pageIndex: number = 1;
pageSize: number = 999; pageSize: number = 999;
jobsList: Jobs.Job[] = []; jobsList: JobApi.Response[] = [];
@Output() pageIndexChange: EventEmitter<number> = new EventEmitter<number>; @Output() pageIndexChange: EventEmitter<number> = new EventEmitter<number>;
constructor(private _service: JobManagerService, private _cdr: ChangeDetectorRef) { } constructor(private _service: JobManagerService, private _cdr: ChangeDetectorRef) { }
...@@ -82,7 +93,7 @@ export class JobListComponent implements OnInit { ...@@ -82,7 +93,7 @@ export class JobListComponent implements OnInit {
getAllJobs(pageIndex: number = 1, pageSize: number = 5) { getAllJobs(pageIndex: number = 1, pageSize: number = 5) {
this._service.jobsGet(pageIndex, pageSize) this._service.jobsGet(pageIndex, pageSize)
.pipe( .pipe(
tap((response: ResponseResult<Rows<Jobs.Job>>) => { tap((response: ResponseResult<Rows<JobApi.Response>>) => {
this.jobsList = response.responseData?.rows || []; this.jobsList = response.responseData?.rows || [];
console.log(this.jobsList); console.log(this.jobsList);
this._cdr.markForCheck(); this._cdr.markForCheck();
......
import { Component, OnInit } from '@angular/core';
import { JobListComponent } from './job-list.component';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { JobFormComponent } from './job-form.component';
@Component({
selector: 'job-parent',
standalone: true,
imports: [
JobListComponent,
JobFormComponent,
NzButtonModule
],
template: `
<h1 class="tw-text-center tw-text-3xl tw-font-semibold tw-my-3">Jobs</h1>
<div class="tw-w-full tw-grid tw-justify-items-end">
<button nz-button nzType="primary">Create new job</button>
</div>
<job-form></job-form>
<job-list></job-list>
`
})
export class JobComponent implements OnInit {
constructor() { }
ngOnInit() { }
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ const JOB_MANANGER_ROUTES: Route[] = [ ...@@ -4,7 +4,7 @@ const JOB_MANANGER_ROUTES: Route[] = [
{ {
path: '', path: '',
loadComponent: () => loadComponent: () =>
import('./feature/job-list.component').then((m) => m.JobListComponent), import('./feature/job.component').then((m) => m.JobComponent),
} }
] ]
export default JOB_MANANGER_ROUTES export default JOB_MANANGER_ROUTES
\ No newline at end of file
...@@ -23,3 +23,6 @@ body { ...@@ -23,3 +23,6 @@ body {
margin: 0; margin: 0;
font-family: Roboto, "Helvetica Neue", sans-serif; font-family: Roboto, "Helvetica Neue", sans-serif;
} }
.ant-table-pagination {
justify-content: center !important;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment