Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add gcp cloud function #5

wants to merge 4 commits into from

Conversation

prajwal-pai77
Copy link

  • Adds GCP cloud function API for support of Data api with Couchbase
  • Currently untested with Data api feature, as it is blocked.

@prajwal-pai77 prajwal-pai77 requested a review from shyam-cb June 17, 2025 13:13
Copy link

@gemini-code-assist gemini-code-assist bot left a 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 handles package-lock.json and generated YAML files.
  • Clarify API behavior in the spec.
  • Correct the typo in the deployment script.
  • Refine integration tests.

Comment on lines 44 to 56
} 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' });
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The API spec indicates a 404 Not Found if "No airlines found". This handler should check for empty results and return a 404, or the API spec should be updated.

Comment on lines +154 to +185
/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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The handler gcp/src/handler/getAirportRoutes.js includes LIMIT 10 in its N1QL query. Document this default limit or make it configurable via a query parameter.

Comment on lines +52 to +67
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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For POST /airports/{airportId}, the airportId is in the path and AirportInput.id. Clarify which takes precedence or omit AirportInput.id.

Comment on lines 43 to 54
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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The getAirportAirlines handler and API spec do not support a limit query parameter. Remove this test or implement the parameter.

Comment on lines 35 to 38
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The response from the /routes endpoint is an object, not an array directly. Check response.data.results.length.

Suggested change
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);

Comment on lines 42 to 54

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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The getAirportRoutes handler does not accept a limit query parameter. Remove this test or implement the parameter.

Comment on lines 46 to 49
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The response from the /hotels/nearby/... endpoint is an object containing a hotels array. Check response.data.hotels.length.

Suggested change
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);

{ 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' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path for data-api-getHotelsNearAirport should include {distance}: '/airports/{airportId}/hotels/nearby/{distance}'.

Suggested change
{ path: '/airports/{airportId}/hotels/nearby', method: 'GET', function: 'data-api-getHotelsNearAirport' }
{ path: '/airports/{airportId}/hotels/nearby/{distance}', method: 'GET', function: 'data-api-getHotelsNearAirport' }

@prajwal-pai77 prajwal-pai77 requested a review from shyam-cb June 23, 2025 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants