-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stubbed API server for I/O 2024 Picnic Shelter Reservation Demo
- Loading branch information
1 parent
518ccaf
commit 3b16d35
Showing
4 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
ai-ml/io-2024-vertex-agent-api-stub/ReservationsAPI.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright 2024 Google LLC | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
openapi: 3.0.0 | ||
info: | ||
title: Park Reservation API | ||
description: API for managing picnic shelter reservations in parks | ||
version: 1.0.0 | ||
|
||
servers: | ||
- url: <PLACE HOLDER> | ||
|
||
paths: | ||
/list-available-reservations: | ||
get: | ||
summary: List available picnic shelter reservations | ||
operationId: list-available-reservations | ||
description: Retrieve available reservation slots for picnic shelters in a given park. | ||
parameters: | ||
- name: parkName | ||
in: query | ||
description: The name of the park | ||
required: true | ||
schema: | ||
type: string | ||
- name: requestedDate | ||
in: query | ||
description: The date for which to check availability (YYYY-MM-DD) | ||
required: true | ||
schema: | ||
type: string | ||
format: date | ||
responses: | ||
'200': | ||
description: Successful retrieval of available reservations | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
type: object | ||
properties: | ||
parkName: | ||
type: string | ||
reservationDateTime: | ||
type: string | ||
format: date-time | ||
'400': | ||
description: Bad request (e.g., invalid park name or date) | ||
'500': | ||
description: Internal server error | ||
|
||
/makeReservation: | ||
post: | ||
summary: Make a picnic shelter reservation | ||
operationId: makeReservations | ||
description: Attempt to reserve a picnic shelter in a given park for a specified date and time. | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
parkName: | ||
type: string | ||
description: Name of the park where the shelter is located. | ||
dateTime: | ||
type: string | ||
format: date-time | ||
description: Date and time of the reservation. | ||
responses: | ||
'200': | ||
description: Successful reservation | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
success: | ||
type: boolean | ||
description: True if the reservation was successful, False otherwise. | ||
reservationID: | ||
type: string | ||
description: (Optional) a reservation ID string | ||
'400': | ||
description: Bad request (e.g., invalid park name, date, or time) | ||
'409': | ||
description: Conflict (the shelter is already reserved for the specified time) | ||
'500': | ||
description: Internal server error |
37 changes: 37 additions & 0 deletions
37
ai-ml/io-2024-vertex-agent-api-stub/list-available-reservations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
const functions = require('@google-cloud/functions-framework'); | ||
|
||
functions.http('listAvailableReservations', (req, res) => { | ||
parkName = req.parkName; | ||
requestedDate = req.requestedDate | ||
|
||
res.json([ | ||
{ | ||
"parkName": parkName, | ||
"reservationDateTime": "11:30:00" | ||
}, | ||
{ | ||
"parkName": parkName, | ||
"reservationDateTime": "12:30:00" | ||
}, | ||
{ | ||
"parkName": parkName, | ||
"reservationDateTime": "15:00:00" | ||
} | ||
]) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2024 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
const functions = require('@google-cloud/functions-framework'); | ||
|
||
functions.http('makeReservation', (req, res) => { | ||
reservationId = getRandomIntInclusive(100000,999999); | ||
|
||
res.json({"success":true, "reservationId":reservationId}); | ||
}); | ||
|
||
function getRandomIntInclusive(min, max) { | ||
const minCeiled = Math.ceil(min); | ||
const maxFloored = Math.floor(max); | ||
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // The maximum is inclusive and the minimum is inclusive | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"@google-cloud/functions-framework": "^3.0.0" | ||
} | ||
} |