Skip to content

Commit a695517

Browse files
committed
feat: connect review form to api
1 parent f38cee6 commit a695517

22 files changed

Lines changed: 1360 additions & 212 deletions

src/frontend/src/app/core/api/commit-review/commit-review-api.mapper.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export function mapGetProposalReviewCommitResponse(
5959
): GetProposalReviewCommitResponse {
6060
return {
6161
id: res.id,
62-
listId: res.id,
6362
proposalReviewId: res.proposal_review_commit.proposal_review_id,
6463
userId: res.proposal_review_commit.user_id,
6564
createdAt: fromCandidDate(res.proposal_review_commit.created_at),
@@ -74,17 +73,17 @@ export function mapGetProposalReviewCommitResponse(
7473
function mapReviewCommitRequestDetails(
7574
req: ReviewCommitDetails,
7675
): ReviewCommitState {
77-
if (req.reviewed === false) {
78-
return { not_reviewed: null };
76+
if (req.reviewed) {
77+
return {
78+
reviewed: {
79+
highlights: req.highlights,
80+
comment: toCandidOpt(req.comment),
81+
matches_description: toCandidOpt(req.matchesDescription),
82+
},
83+
};
7984
}
8085

81-
return {
82-
reviewed: {
83-
highlights: req.highlights,
84-
comment: toCandidOpt(req.comment),
85-
matches_description: toCandidOpt(req.matchesDescription),
86-
},
87-
};
86+
return { not_reviewed: null };
8887
}
8988

9089
function mapReviewCommitResponseDetails(

src/frontend/src/app/core/api/commit-review/commit-review-api.model.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ export interface DeleteProposalReviewCommitRequest {
1414
}
1515

1616
export interface GetProposalReviewCommitResponse {
17-
id: string | null;
18-
listId: string;
17+
id: string;
1918
proposalReviewId: string;
2019
userId: string;
2120
createdAt: Date;
2221
lastUpdatedAt: Date | null;
23-
commitSha: string;
22+
commitSha: string | null;
2423
details: ReviewCommitDetails;
2524
}
2625

@@ -36,5 +35,5 @@ export interface ReviewedCommitDetails {
3635
}
3736

3837
export interface NotReviewedCommitDetails {
39-
reviewed: false;
38+
reviewed: false | null;
4039
}

src/frontend/src/app/core/api/commit-review/commit-review-api.service.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('CommitReviewApiService', () => {
6666
proposal_review_id: 'proposalReviewId',
6767
user_id: 'userId',
6868
commit_sha: 'commitSha',
69-
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).getTime().toString(),
69+
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).toISOString(),
7070
last_updated_at: [],
7171
state: {
7272
reviewed: {
@@ -80,7 +80,6 @@ describe('CommitReviewApiService', () => {
8080
};
8181
const commonResponse: GetProposalReviewCommitResponse = {
8282
id: 'id',
83-
listId: 'id',
8483
userId: 'userId',
8584
commitSha: 'commitSha',
8685
proposalReviewId: 'proposalReviewId',

src/frontend/src/app/core/api/review/review-api.mapper.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
GetProposalReviewRequest as GetProposalReviewApiRequest,
1515
GetMyProposalReviewRequest as GetMyProposalReviewApiRequest,
1616
ProposalReviewStatus as ProposalReviewStatusApi,
17+
ProposalVote as ApiProposalVote,
1718
} from '@cg/backend';
1819
import {
1920
GetProposalReviewResponse,
@@ -23,7 +24,6 @@ import {
2324
ListProposalReviewsRequest,
2425
GetProposalReviewRequest,
2526
ProposalReviewStatus,
26-
ProposalReviewVote,
2727
} from './review-api.model';
2828

2929
export function mapCreateProposalReviewRequest(
@@ -34,7 +34,7 @@ export function mapCreateProposalReviewRequest(
3434
review_duration_mins: toCandidOpt(req.reviewDurationMins),
3535
summary: toCandidOpt(req.summary),
3636
build_reproduced: toCandidOpt(req.buildReproduced),
37-
vote: [],
37+
vote: mapProposalVoteRequest(req.vote),
3838
};
3939
}
4040

@@ -48,7 +48,7 @@ export function mapUpdateProposalReviewRequest(
4848
review_duration_mins: toCandidOpt(req.reviewDurationMins),
4949
summary: toCandidOpt(req.summary),
5050
build_reproduced: toCandidOpt(req.buildReproduced),
51-
vote: [],
51+
vote: mapProposalVoteRequest(req.vote),
5252
};
5353
}
5454

@@ -86,8 +86,7 @@ export function mapGetProposalReviewResponse(
8686
id: res.id,
8787
proposalId: review.proposal_id,
8888
userId: review.user_id,
89-
// [TODO] - connect with API once it's implemented
90-
vote: ProposalReviewVote.NoVote,
89+
vote: mapProposalVoteResponse(review.vote),
9190
createdAt: fromCandidDate(review.created_at),
9291
lastUpdatedAt: fromCandidOptDate(review.last_updated_at),
9392
status: mapProposalReviewStatusResponse(review.status),
@@ -112,6 +111,32 @@ function mapProposalReviewStatusResponse(
112111
return ProposalReviewStatus.Draft;
113112
}
114113

114+
function mapProposalVoteRequest(vote?: boolean | null): [] | [ApiProposalVote] {
115+
switch (vote) {
116+
case true: {
117+
return [{ yes: null }];
118+
}
119+
case false: {
120+
return [{ no: null }];
121+
}
122+
default: {
123+
return [];
124+
}
125+
}
126+
}
127+
128+
function mapProposalVoteResponse(vote: ApiProposalVote): boolean | null {
129+
if ('yes' in vote) {
130+
return true;
131+
}
132+
133+
if ('no' in vote) {
134+
return false;
135+
}
136+
137+
return null;
138+
}
139+
115140
function getReviewImages(): ImageSet[] {
116141
return [
117142
{

src/frontend/src/app/core/api/review/review-api.model.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ import { ImageSet } from '@cg/angular-ui';
33

44
export interface CreateProposalReviewRequest {
55
proposalId: string;
6-
summary: string | null;
7-
reviewDurationMins: number | null;
8-
buildReproduced: boolean | null;
9-
reproducedBuildImageId: string | null;
6+
summary?: string | null;
7+
reviewDurationMins?: number | null;
8+
buildReproduced?: boolean | null;
9+
vote?: boolean | null;
1010
}
1111

1212
export interface UpdateProposalReviewRequest {
1313
proposalId: string;
14-
reviewDurationMins: number | null;
15-
summary: string | null;
16-
buildReproduced: boolean | null;
14+
reviewDurationMins?: number | null;
15+
summary?: string | null;
16+
buildReproduced?: boolean | null;
17+
vote?: boolean | null;
1718
}
1819

1920
export interface ListProposalReviewsRequest {
@@ -33,7 +34,7 @@ export interface GetProposalReviewResponse {
3334
id: string;
3435
proposalId: string;
3536
userId: string;
36-
vote: ProposalReviewVote;
37+
vote: boolean | null;
3738
createdAt: Date;
3839
lastUpdatedAt: Date | null;
3940
status: ProposalReviewStatus;
@@ -63,7 +64,7 @@ export interface ProposalCommitReviewHighlight {
6364
export interface ProposalCommitReviewSummary {
6465
proposalId: string;
6566
commitId: string;
66-
commitSha: string;
67+
commitSha: string | null;
6768
highlights: ProposalCommitReviewHighlight[];
6869
totalReviewers: number;
6970
reviewedCount: number;

src/frontend/src/app/core/api/review/review-api.service.spec.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
GetProposalReviewResponse,
2727
ListProposalReviewsRequest,
2828
ProposalReviewStatus,
29-
ProposalReviewVote,
3029
UpdateProposalReviewRequest,
3130
} from './review-api.model';
3231
import { ReviewApiService } from './review-api.service';
@@ -57,7 +56,6 @@ describe('ReviewApiService', () => {
5756
summary: null,
5857
reviewDurationMins: null,
5958
buildReproduced: null,
60-
reproducedBuildImageId: null,
6159
};
6260
const commonApiRequest: CreateProposalReviewApiRequest = {
6361
proposal_id: 'proposalId',
@@ -72,7 +70,7 @@ describe('ReviewApiService', () => {
7270
proposal_review: {
7371
proposal_id: 'proposalId',
7472
user_id: 'userId',
75-
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).getTime().toString(),
73+
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).toISOString(),
7674
last_updated_at: [],
7775
status: {
7876
draft: null,
@@ -90,7 +88,7 @@ describe('ReviewApiService', () => {
9088
id: 'id',
9189
proposalId: 'proposalId',
9290
userId: 'userId',
93-
vote: ProposalReviewVote.NoVote,
91+
vote: null,
9492
createdAt: new Date(2024, 1, 1, 0, 0, 0, 0),
9593
lastUpdatedAt: null,
9694
status: ProposalReviewStatus.Draft,
@@ -195,7 +193,7 @@ describe('ReviewApiService', () => {
195193
proposal_review: {
196194
proposal_id: 'proposalId',
197195
user_id: 'userId1',
198-
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).getTime().toString(),
196+
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).toISOString(),
199197
last_updated_at: [],
200198
status: {
201199
draft: null,
@@ -213,7 +211,7 @@ describe('ReviewApiService', () => {
213211
proposal_review: {
214212
proposal_id: 'proposalId',
215213
user_id: 'userId2',
216-
created_at: new Date(2024, 1, 2, 0, 0, 0, 0).getTime().toString(),
214+
created_at: new Date(2024, 1, 2, 0, 0, 0, 0).toISOString(),
217215
last_updated_at: [],
218216
status: {
219217
draft: null,
@@ -234,7 +232,7 @@ describe('ReviewApiService', () => {
234232
id: 'id1',
235233
proposalId: 'proposalId',
236234
userId: 'userId1',
237-
vote: ProposalReviewVote.NoVote,
235+
vote: null,
238236
createdAt: new Date(2024, 1, 1, 0, 0, 0, 0),
239237
lastUpdatedAt: null,
240238
status: ProposalReviewStatus.Draft,
@@ -249,7 +247,7 @@ describe('ReviewApiService', () => {
249247
id: 'id2',
250248
proposalId: 'proposalId',
251249
userId: 'userId2',
252-
vote: ProposalReviewVote.NoVote,
250+
vote: null,
253251
createdAt: new Date(2024, 1, 2, 0, 0, 0, 0),
254252
lastUpdatedAt: null,
255253
status: ProposalReviewStatus.Draft,
@@ -301,7 +299,7 @@ describe('ReviewApiService', () => {
301299
proposal_review: {
302300
proposal_id: 'proposalId',
303301
user_id: 'userId',
304-
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).getTime().toString(),
302+
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).toISOString(),
305303
last_updated_at: [],
306304
status: {
307305
draft: null,
@@ -319,7 +317,7 @@ describe('ReviewApiService', () => {
319317
id: 'id',
320318
proposalId: 'proposalId',
321319
userId: 'userId',
322-
vote: ProposalReviewVote.NoVote,
320+
vote: null,
323321
createdAt: new Date(2024, 1, 1, 0, 0, 0, 0),
324322
lastUpdatedAt: null,
325323
status: ProposalReviewStatus.Draft,
@@ -372,7 +370,7 @@ describe('ReviewApiService', () => {
372370
proposal_review: {
373371
proposal_id: 'proposalId',
374372
user_id: 'userId',
375-
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).getTime().toString(),
373+
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).toISOString(),
376374
last_updated_at: [],
377375
status: {
378376
draft: null,
@@ -390,7 +388,7 @@ describe('ReviewApiService', () => {
390388
id: 'id',
391389
proposalId: 'proposalId',
392390
userId: 'userId',
393-
vote: ProposalReviewVote.NoVote,
391+
vote: null,
394392
createdAt: new Date(2024, 1, 1, 0, 0, 0, 0),
395393
lastUpdatedAt: null,
396394
status: ProposalReviewStatus.Draft,
@@ -433,7 +431,6 @@ describe('ReviewApiService', () => {
433431
summary: null,
434432
reviewDurationMins: null,
435433
buildReproduced: null,
436-
reproducedBuildImageId: null,
437434
};
438435
const commonApiCreateRequest: CreateProposalReviewApiRequest = {
439436
proposal_id: 'proposalId',
@@ -451,7 +448,7 @@ describe('ReviewApiService', () => {
451448
proposal_review: {
452449
proposal_id: 'proposalId',
453450
user_id: 'userId',
454-
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).getTime().toString(),
451+
created_at: new Date(2024, 1, 1, 0, 0, 0, 0).toISOString(),
455452
last_updated_at: [],
456453
status: {
457454
draft: null,
@@ -469,7 +466,7 @@ describe('ReviewApiService', () => {
469466
id: 'id',
470467
proposalId: 'proposalId',
471468
userId: 'userId',
472-
vote: ProposalReviewVote.NoVote,
469+
vote: null,
473470
createdAt: new Date(2024, 1, 1, 0, 0, 0, 0),
474471
lastUpdatedAt: null,
475472
status: ProposalReviewStatus.Draft,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './profile';
22
export * from './proposal';
33
export * from './review';
4+
export * from './review-submission';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './review-submission.service';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ReviewSubmissionService } from './review-submission.service';
2+
3+
export type ReviewSubmissionServiceMock =
4+
jasmine.SpyObj<ReviewSubmissionService>;
5+
6+
export function reviewSubmissionServiceMockFactory(): ReviewSubmissionServiceMock {
7+
return jasmine.createSpyObj<ReviewSubmissionServiceMock>(
8+
'ReviewSubmissionService',
9+
[
10+
'addCommit',
11+
'loadOrCreateReview',
12+
'removeCommit',
13+
'updateCommit',
14+
'updateReview',
15+
],
16+
);
17+
}

0 commit comments

Comments
 (0)