Add optional comment to Ad type and records #7409

This commit is contained in:
Romain Thouvenin 2024-02-28 14:50:59 +01:00
parent da4b30350b
commit a7b342c049
15 changed files with 36 additions and 3 deletions

View File

@ -115,7 +115,8 @@ The app exposes the following [gRPC](https://grpc.io/) services :
"postalCode": "75000",
"country": "France"
}
]
],
"comment": "I'm flexible with the departure time"
}
```
@ -157,7 +158,8 @@ The app exposes the following [gRPC](https://grpc.io/) services :
"postalCode": "75000",
"country": "France"
}
]
],
"comment": "I'm flexible with the departure time"
}
```
@ -207,7 +209,8 @@ The app exposes the following [gRPC](https://grpc.io/) services :
"postalCode": "75000",
"country": "France"
}
]
],
"comment": "I'm flexible with the departure time"
}
```
@ -227,6 +230,7 @@ The app exposes the following [gRPC](https://grpc.io/) services :
- seatsRequested: number of seats requested as passenger (required if `passenger` is true)
- strict (boolean): if set to true, allow matching only with similar frequency ads
- waypoints: an array of addresses that represent the waypoints of the journey (only first and last waypoints are used for passenger ads). Note that positions are **required** and **must** be consecutives
- comment: optional freetext comment / description about the ad
## Messages

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ad" ADD COLUMN "comment" TEXT;

View File

@ -27,6 +27,7 @@ model Ad {
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
waypoints Waypoint[]
comment String?
@@map("ad")
}

View File

@ -82,6 +82,7 @@ export class AdMapper
})),
}
: undefined,
comment: copy.comment,
};
return record;
};
@ -128,6 +129,7 @@ export class AdMapper
},
},
})),
comment: record.comment,
},
});
return entity;
@ -193,6 +195,7 @@ export class AdMapper
lon: waypoint.address.coordinates.lon,
lat: waypoint.address.coordinates.lat,
}));
response.comment = props.comment;
return response;
};
}

View File

@ -15,6 +15,7 @@ export class CreateAdCommand extends Command {
readonly seatsRequested?: number;
readonly strict: boolean;
readonly waypoints: Waypoint[];
readonly comment?: string;
constructor(props: CommandProps<CreateAdCommand>) {
super(props);
@ -29,5 +30,6 @@ export class CreateAdCommand extends Command {
this.seatsRequested = props.seatsRequested;
this.strict = props.strict;
this.waypoints = props.waypoints;
this.comment = props.comment;
}
}

View File

@ -95,6 +95,7 @@ export class CreateAdService implements ICommandHandler {
},
},
})),
comment: command.comment,
});
try {

View File

@ -47,6 +47,7 @@ export class AdEntity extends AggregateRoot<AdProps> {
lon: waypoint.address.coordinates.lon,
lat: waypoint.address.coordinates.lat,
})),
comment: props.comment,
}),
);
return ad;

View File

@ -15,6 +15,7 @@ export interface AdProps {
seatsRequested: number;
strict: boolean;
waypoints: WaypointProps[];
comment?: string;
}
// Properties that are needed for an Ad creation
@ -30,6 +31,7 @@ export interface CreateAdProps {
seatsRequested: number;
strict: boolean;
waypoints: WaypointProps[];
comment?: string;
}
export enum Frequency {

View File

@ -12,6 +12,7 @@ export class AdCreatedDomainEvent extends DomainEvent {
readonly seatsRequested: number;
readonly strict: boolean;
readonly waypoints: Waypoint[];
readonly comment?: string;
constructor(props: DomainEventProps<AdCreatedDomainEvent>) {
super(props);
@ -26,6 +27,7 @@ export class AdCreatedDomainEvent extends DomainEvent {
this.seatsRequested = props.seatsRequested;
this.strict = props.strict;
this.waypoints = props.waypoints;
this.comment = props.comment;
}
}

View File

@ -24,6 +24,7 @@ export type AdBaseModel = {
seatsProposed: number;
seatsRequested: number;
strict: boolean;
comment?: string;
};
export type AdReadModel = AdBaseModel & {

View File

@ -28,4 +28,5 @@ export class AdResponseDto extends ResponseBase {
lon: number;
lat: number;
}[];
comment?: string;
}

View File

@ -36,6 +36,7 @@ message Ad {
int32 seatsRequested = 10;
bool strict = 11;
repeated Waypoint waypoints = 12;
optional string comment = 13;
}
message ScheduleItem {

View File

@ -3,8 +3,10 @@ import {
IsBoolean,
IsInt,
IsEnum,
IsString,
ValidateNested,
ArrayMinSize,
Length,
IsUUID,
IsArray,
IsISO8601,
@ -78,4 +80,9 @@ export class CreateAdRequestDto {
@HasValidPositionIndexes()
@ValidateNested({ each: true })
waypoints: WaypointDto[];
@Length(0, 2000)
@IsString()
@IsOptional()
comment?: string;
}

View File

@ -111,6 +111,7 @@ const adReadModel: AdReadModel = {
strict: false,
seatsProposed: 3,
seatsRequested: 1,
comment: '',
createdAt: now,
updatedAt: now,
};

View File

@ -39,6 +39,7 @@ const baseCreateAdProps = {
seatsRequested: 1,
strict: false,
waypoints: [originWaypointProps, destinationWaypointProps],
comment: "J'accepte les chiens mais pas les chats",
};
const punctualCreateAdProps = {
fromDate: '2023-06-21',
@ -134,6 +135,9 @@ describe('Ad entity create', () => {
expect(punctualPassengerAd.getProps().schedule[0].time).toBe('08:30');
expect(punctualPassengerAd.getProps().driver).toBeFalsy();
expect(punctualPassengerAd.getProps().passenger).toBeTruthy();
expect(punctualPassengerAd.getProps().comment).toBe(
"J'accepte les chiens mais pas les chats",
);
});
it('should create a new punctual driver ad entity', async () => {
const punctualDriverAd: AdEntity = AdEntity.create(