Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cars enhancements #29

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rule:
kind: user_type
inside:
any:
- kind: parameter
regex: pickupTime
- kind: parameter
regex: dropOffTime
stopBy:
kind: class_declaration
regex: Builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rule:
kind: user_type
pattern: $TYPE
inside:
any:
- kind: class_parameter
regex: pickupTime
- kind: class_parameter
regex: dropOffTime
- kind: nullable_type
inside:
any:
- kind: class_parameter
regex: pickupTime
- kind: class_parameter
regex: dropOffTime
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rule:
kind: "import_header"
regex: "OperationParams"
pattern: "$HEADER"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rule:
kind: value_argument
nthChild: 2
inside:
kind: call_suffix
stopBy: end
has:
any:
- kind: value_arguments
regex: pickupTime
- kind: value_arguments
regex: dropOffTime
inside:
kind: function_declaration
stopBy: end
regex: getQueryParams
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {GetLodgingQuotesOperationParamsProcessor} from './processors/get-lodging
import {NonCancellableDateTimeRangeProcessor} from './processors/non-cancellable-date-time-range-processor';
import {PenaltyRuleProcessor} from './processors/penalty-rule-processor';
import {VendorLocationDetailsProcessor} from './processors/vendor-location-details-processor';
import {GetCarsListingsOperationParamsProcessor} from './processors/get-cars-listings-operation-params-processor';

import * as path from 'path';

Expand All @@ -30,4 +31,7 @@ switch (fileName) {
case 'VendorLocationDetails':
new VendorLocationDetailsProcessor().process(filePath);
break;
case 'GetCarsListingsOperationParams':
new GetCarsListingsOperationParamsProcessor().process(filePath);
break;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {Edit, NapiConfig, SgNode} from '@ast-grep/napi';
import {Processor} from './processor';
import {RuleFunction} from './shared.types';

export class GetCarsListingsOperationParamsProcessor extends Processor {
rules: RuleFunction[];
id: String = 'get-cars-listings-operation-params';

constructor() {
super();
this.rules = [
this.changeClassParamType,
this.changeBuilderMethodParamType,
this.importChronoUnit,
this.truncatePickupDropoffTimes,
].map(rule => rule.bind(this));
}

changeClassParamType(root: SgNode): Edit[] {
const config = this.readRule('change-class-params-type');

return root.findAll(config).map(node => {
return node.replace('java.time.LocalDateTime');
});
}

changeBuilderMethodParamType(root: SgNode): Edit[] {
const config = this.readRule('change-builder-method-params-type');

return root.findAll(config).map(node => {
return node.replace('java.time.LocalDateTime');
});
}

importChronoUnit(root: SgNode): Edit[] {
const config = this.readRule('import-chrono-unit');

return root.findAll(config).map(node => {
const room = 'import java.time.temporal.ChronoUnit';
const header = node.getMatch('HEADER')?.text();

return node.replace(`${room}\n${header}`);
});

}

truncatePickupDropoffTimes(root: SgNode): Edit[] {
const config = this.readRule('truncate-pickup-dropoff-times');

return root.findAll(config).map(node => {
return node.replace('it.truncatedTo(ChronoUnit.MINUTES).toString()');
});
}
}
13 changes: 8 additions & 5 deletions specs/xap-car.specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ paths:
in: query
description: 'Radius used in conjunction with a point to define the search area when searching by lat/ long, city or address.See '' unit'' parameter below to select miles or kilometers.If no value is specified a default value of 25 will be assumed.'
schema:
type: string
example: '10'
type: integer
example: 10
- name: dropOff.airport
in: query
description: 'Three letter code for the airport at which the customer would like to drop off the car.Supported values: standard 3 letter IATA Airport Code.Please see a full list of Car Vendor Codes and Airport Codes in the Related Links Section below.Cannot coexist with other drop off parameters, only one drop off parameter is allowed per request.If no drop off location is specified, it is assumed that the customer will be dropping the car off at the same location at which they picked it up.'
Expand Down Expand Up @@ -98,19 +98,23 @@ paths:
in: query
description: 'Radius used in conjunction with a point to define the search area when searching by lat/ long, city or address.See '' unit'' parameter below to select miles or kilometers.If no value is specified a default value of 25 will be assumed.Note: The pickup radius value will be used (instead of the the drop-off radius) when the requested pickup and drop-off city/address are exactly the same.'
schema:
type: string
example: '10'
type: integer
example: 10
- name: pickupTime
in: query
description: 'Requested car pickup date and time.Date should be ISO8601 Date format.The default TIME is 10:30:00.The supported search window is today to 330 days in the future.(Note that each rental counter has different hours of operation. If you select a time in the middle of the night there may be no inventory available as all locations may be closed.)'
required: true
schema:
type: string
format: date-time
example: '2021-06-05T10:00'
- name: dropOffTime
in: query
description: 'Requested car drop off date and time. Date should be ISO8601 Date format.The supported search window is today to 330 days in the future.Note: The dropOffTime must be at least 2 hours later than the pickupTime for the request to be valid.'
required: true
schema:
type: string
format: date-time
example: '2021-06-06T10:00'
- name: sortType
in: query
Expand Down Expand Up @@ -1477,7 +1481,6 @@ components:
description: Details of requested car.
CarDetailsResponse:
required:
- CarDetails
- TransactionId
type: object
properties:
Expand Down