-
Notifications
You must be signed in to change notification settings - Fork 0
Add gcp cloud function #5
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
base: main
Are you sure you want to change the base?
Conversation
prajwal-pai77
commented
Jun 17, 2025
- Adds GCP cloud function API for support of Data api with Couchbase
- Currently untested with Data api feature, as it is blocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @prajwal-pai77, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new set of Google Cloud Functions designed to provide a serverless API for interacting with Couchbase's Data API. The API enables comprehensive management and querying of airport-related data, including CRUD operations for airport documents and advanced searches for routes, airlines, and geo-spatial hotel proximity. It includes all necessary infrastructure-as-code, deployment scripts, and a full suite of integration tests.
Highlights
- New GCP Cloud Functions API: Introduced a comprehensive set of GCP Cloud Functions to provide a serverless API for interacting with Couchbase's Data API, enabling management and querying of airport data.
- Airport Data Management (CRUD): Implemented Cloud Functions for full Create, Read, Update, and Delete (CRUD) operations on airport documents, leveraging Couchbase's document capabilities.
- Advanced Data Queries: Added functions to query airport routes and airlines using Couchbase N1QL, and a geo-spatial search function to find hotels near a given airport using Couchbase Full Text Search (FTS).
- Automated Deployment & Infrastructure: Included scripts for automated deployment of Cloud Functions and the GCP API Gateway, along with a detailed OpenAPI specification (
api-spec.yaml
) for the API endpoints. - Comprehensive Testing: Provided an extensive suite of Jest integration tests to ensure the functionality and reliability of all new API endpoints.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR introduces GCP Cloud Functions for a Couchbase Data API. Key improvements:
- Ensure
.gcloudignore
handlespackage-lock.json
and generated YAML files. - Clarify API behavior in the spec.
- Correct the typo in the deployment script.
- Refine integration tests.
} catch (error) { | ||
console.error('Error executing airlines query in GCP cloud function:', error); | ||
|
||
if (error.response) { | ||
const errorBody = error.response.data; | ||
console.error(`Query API Error (${error.response.status}): ${JSON.stringify(errorBody)}`); | ||
return res.status(error.response.status).json({ | ||
error: `Error executing airlines query: ${error.response.statusText}. Detail: ${JSON.stringify(errorBody)}` | ||
}); | ||
} | ||
|
||
res.status(500).json({ error: 'Error executing airlines query' }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/airports/{airportCode}/routes: | ||
get: | ||
summary: Get airport routes | ||
description: Find all routes for a specific airport (both incoming and outgoing) | ||
operationId: getAirportRoutes | ||
parameters: | ||
- name: airportCode | ||
in: path | ||
required: true | ||
type: string | ||
description: The airport code (FAA or ICAO) | ||
example: LAX | ||
responses: | ||
'200': | ||
description: Success - Routes retrieved | ||
schema: | ||
$ref: '#/definitions/RoutesResponse' | ||
'400': | ||
description: Bad Request - Invalid airport code | ||
schema: | ||
$ref: '#/definitions/ErrorResponse' | ||
'404': | ||
description: Not Found - No routes found for airport | ||
schema: | ||
$ref: '#/definitions/ErrorResponse' | ||
'500': | ||
description: Internal Server Error | ||
schema: | ||
$ref: '#/definitions/ErrorResponse' | ||
x-google-backend: | ||
address: {{GET_AIRPORT_ROUTES_FUNCTION_URL}} | ||
path_translation: APPEND_PATH_TO_ADDRESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post: | ||
summary: Create new airport | ||
description: Create a new airport document | ||
operationId: createAirport | ||
parameters: | ||
- name: airportId | ||
in: path | ||
required: true | ||
type: string | ||
description: The unique identifier for the new airport | ||
example: airport_new | ||
- name: body | ||
in: body | ||
required: true | ||
schema: | ||
$ref: '#/definitions/AirportInput' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('should handle query parameters for airline filtering', async () => { | ||
const airportId = 'SFO'; | ||
|
||
try { | ||
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/airlines?limit=5`); | ||
expect([200, 400]).toContain(response.status); | ||
if (response.status === 200) { | ||
expect(response.data).toBeDefined(); | ||
} | ||
} catch (error) { | ||
expect([400, 404]).toContain(error.response.status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/routes`); | ||
expect(response.status).toBe(200); | ||
expect(Array.isArray(response.data) ? response.data.length : 0).toBe(0); | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response from the /routes
endpoint is an object, not an array directly. Check response.data.results.length
.
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/routes`); | |
expect(response.status).toBe(200); | |
expect(Array.isArray(response.data) ? response.data.length : 0).toBe(0); | |
} catch (error) { | |
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/routes`); | |
expect(response.status).toBe(200); | |
expect(response.data.results ? response.data.results.length : 0).toBe(0); |
|
||
test('should handle query parameters for route filtering', async () => { | ||
const airportId = 'SFO'; | ||
|
||
try { | ||
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/routes?limit=10`); | ||
expect([200, 400]).toContain(response.status); | ||
if (response.status === 200) { | ||
expect(response.data).toBeDefined(); | ||
} | ||
} catch (error) { | ||
expect([400, 404]).toContain(error.response.status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/hotels/nearby/${distance}`); | ||
expect(response.status).toBe(200); | ||
expect(Array.isArray(response.data) ? response.data.length : 0).toBe(0); | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response from the /hotels/nearby/...
endpoint is an object containing a hotels
array. Check response.data.hotels.length
.
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/hotels/nearby/${distance}`); | |
expect(response.status).toBe(200); | |
expect(Array.isArray(response.data) ? response.data.length : 0).toBe(0); | |
} catch (error) { | |
const response = await axios.get(`${apiBaseUrl}/airports/${airportId}/hotels/nearby/${distance}`); | |
expect(response.status).toBe(200); | |
expect(response.data.hotels ? response.data.hotels.length : 0).toBe(0); |
gcp/utils/config.js
Outdated
{ path: '/airports/{airportId}', method: 'DELETE', function: 'data-api-deleteAirport' }, | ||
{ path: '/airports/{airportId}/routes', method: 'GET', function: 'data-api-getAirportRoutes' }, | ||
{ path: '/airports/{airportId}/airlines', method: 'GET', function: 'data-api-getAirportAirlines' }, | ||
{ path: '/airports/{airportId}/hotels/nearby', method: 'GET', function: 'data-api-getHotelsNearAirport' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path for data-api-getHotelsNearAirport
should include {distance}
: '/airports/{airportId}/hotels/nearby/{distance}'
.
{ path: '/airports/{airportId}/hotels/nearby', method: 'GET', function: 'data-api-getHotelsNearAirport' } | |
{ path: '/airports/{airportId}/hotels/nearby/{distance}', method: 'GET', function: 'data-api-getHotelsNearAirport' } |