Skip to content

Commit

Permalink
Stubbed API server for I/O 2024 Picnic Shelter Reservation Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
thagomizer committed Jun 3, 2024
1 parent 518ccaf commit 3b16d35
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
107 changes: 107 additions & 0 deletions ai-ml/io-2024-vertex-agent-api-stub/ReservationsAPI.yaml
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 ai-ml/io-2024-vertex-agent-api-stub/list-available-reservations.js
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"
}
])
});
29 changes: 29 additions & 0 deletions ai-ml/io-2024-vertex-agent-api-stub/makeReservation.js
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
}
5 changes: 5 additions & 0 deletions ai-ml/io-2024-vertex-agent-api-stub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0"
}
}

0 comments on commit 3b16d35

Please sign in to comment.