Skip to content

Commit

Permalink
fix: update API paths and descriptions for repairs (#11525)
Browse files Browse the repository at this point in the history
  • Loading branch information
huimiu authored May 6, 2024
1 parent 0d4f61e commit d292dc7
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ using Microsoft.Extensions.Logging;

namespace {{SafeProjectName}}
{
public class Repair
public class Repairs
{
private readonly ILogger _logger;
public Repair(ILoggerFactory loggerFactory)
public Repairs(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Repair>();
_logger = loggerFactory.CreateLogger<Repairs>();
}

[Function("repair")]
[Function("repairs")]
public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req)
{
// Log that the HTTP trigger function received a request.
Expand All @@ -25,6 +25,14 @@ namespace {{SafeProjectName}}
// Get the repair records.
var repairRecords = RepairData.GetRepairs();
// If the assignedTo query parameter is not provided, return all repair records.
if (string.IsNullOrEmpty(assignedTo))
{
var response = req.CreateResponse();
await response.WriteAsJsonAsync(new { results = repairRecords });
return response;
}

// Filter the repair records by the assignedTo query parameter.
var repairs = repairRecords.Where(r =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,66 @@
{
"schema_version": "v2.1",
"name_for_human": "{{appName}}${{APP_NAME_SUFFIX}}",
"namespace": "repairs",
"description_for_human": "Track your repair records",
"description_for_model": "Plugin for searching a repair list, you can search by who's assigned to the repair.",
"functions": [
{
"name": "repair",
"description": "Search for repairs"
"name": "listRepairs",
"description": "Returns a list of repairs with their details and images",
"capabilities": {
"response_semantics": {
"data_path": "$",
"properties": {
"title": "$.title",
"subtitle": "$.description",
"url": "$.image"
},
"static_template": {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"body": [
{
"type": "Container",
"$data": "${$root}",
"items": [
{
"type": "TextBlock",
"text": "id: ${if(id, id, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "title: ${if(title, title, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "description: ${if(description, description, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "assignedTo: ${if(assignedTo, assignedTo, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "date: ${if(date, date, 'N/A')}",
"wrap": true
},
{
"type": "Image",
"url": "${image}",
"$when": "${image != null}"
}
]
}
]
}
}
}
}
],
"runtimes": [
Expand All @@ -19,7 +73,7 @@
"url": "apiSpecificationFile/repair.yml",
"progress_style": "ShowUsageWithInputAndOutput"
},
"run_for_functions": ["repair"]
"run_for_functions": ["listRepairs"]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ servers:
- url: ${{OPENAPI_SERVER_URL}}/api
description: The repair api server
paths:
/repair:
/repairs:
get:
operationId: repair
summary: Search for repairs
description: Search for repairs info with its details and image
operationId: listRepairs
summary: List all repairs
description: Returns a list of repairs with their details and images
parameters:
- name: assignedTo
in: query
Expand Down
6 changes: 3 additions & 3 deletions templates/js/api-plugin-from-scratch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ When you extend Copilot for Microsoft 365, you maximize the efficiency of your a

## What's included in the template

| Folder | Contents |
| Folder | Contents |
| ------------ | ------------------------------------------------------------------------------------------- |
| `.vscode` | VSCode files for debugging |
| `appPackage` | Templates for the Teams application manifest, the plugin manifest and the API specification |
Expand All @@ -43,7 +43,7 @@ The following files can be customized and demonstrate an example implementation

| File | Contents |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| `src/functions/repair.js` | The main file of a function in Azure Functions. |
| `src/functions/repairs.js` | The main file of a function in Azure Functions. |
| `src/repairsData.json` | The data source for the repair API. |
| `appPackage/apiSpecificationFile/repair.yml` | A file that describes the structure and behavior of the repair API. |
| `appPackage/manifest.json` | Teams application manifest that defines metadata for your plugin inside Microsoft Teams. |
Expand All @@ -61,4 +61,4 @@ The following are Teams Toolkit specific project files. You can [visit a complet
- [Extend Microsoft Copilot for Microsoft 365](https://aka.ms/teamsfx-copilot-plugin)
- [Message extensions for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-message-extension-bot)
- [Microsoft Graph Connectors for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-graph-connector)
- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples)
- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples)
60 changes: 57 additions & 3 deletions templates/js/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,66 @@
{
"schema_version": "v2.1",
"name_for_human": "{{appName}}${{APP_NAME_SUFFIX}}",
"namespace": "repairs",
"description_for_human": "Track your repair records",
"description_for_model": "Plugin for searching a repair list, you can search by who's assigned to the repair.",
"functions": [
{
"name": "repair",
"description": "Search for repairs"
"name": "listRepairs",
"description": "Returns a list of repairs with their details and images",
"capabilities": {
"response_semantics": {
"data_path": "$",
"properties": {
"title": "$.title",
"subtitle": "$.description",
"url": "$.image"
},
"static_template": {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"body": [
{
"type": "Container",
"$data": "${$root}",
"items": [
{
"type": "TextBlock",
"text": "id: ${if(id, id, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "title: ${if(title, title, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "description: ${if(description, description, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "assignedTo: ${if(assignedTo, assignedTo, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "date: ${if(date, date, 'N/A')}",
"wrap": true
},
{
"type": "Image",
"url": "${image}",
"$when": "${image != null}"
}
]
}
]
}
}
}
}
],
"runtimes": [
Expand All @@ -19,7 +73,7 @@
"url": "apiSpecificationFile/repair.yml",
"progress_style": "ShowUsageWithInputAndOutput"
},
"run_for_functions": ["repair"]
"run_for_functions": ["listRepairs"]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ servers:
- url: ${{OPENAPI_SERVER_URL}}/api
description: The repair api server
paths:
/repair:
/repairs:
get:
operationId: repair
summary: Search for repairs
description: Search for repairs info with its details and image
operationId: listRepairs
summary: List all repairs
description: Returns a list of repairs with their details and images
parameters:
- name: assignedTo
in: query
Expand All @@ -29,7 +29,7 @@ paths:
items:
properties:
id:
type: integer
type: string
description: The unique identifier of the repair
title:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ const { app } = require("@azure/functions");
* @param context - The Azure Functions context object.
* @returns A promise that resolves with the HTTP response containing the repair information.
*/
async function repair(req, context) {
async function repairs(req, context) {
context.log("HTTP trigger function processed a request.");

// Get the repair records from the data.json file.
const repairRecords = require("../repairsData.json");

// Initialize response.
const res = {
status: 200,
jsonBody: {
results: [],
results: repairRecords,
},
};

Expand All @@ -28,9 +32,6 @@ async function repair(req, context) {
return res;
}

// Get the repair records from the data.json file.
const repairRecords = require("../repairsData.json");

// Filter the repair records by the assignedTo query parameter.
const repairs = repairRecords.filter((item) => {
const query = assignedTo.trim().toLowerCase();
Expand All @@ -44,8 +45,8 @@ async function repair(req, context) {
return res;
}

app.http("repair", {
app.http("repairs", {
methods: ["GET"],
authLevel: "anonymous",
handler: repair,
handler: repairs,
});
4 changes: 2 additions & 2 deletions templates/ts/api-plugin-from-scratch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following files can be customized and demonstrate an example implementation

| File | Contents |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| `src/functions/repair.ts` | The main file of a function in Azure Functions. |
| `src/functions/repairs.ts` | The main file of a function in Azure Functions. |
| `src/repairsData.json` | The data source for the repair API. |
| `appPackage/apiSpecificationFile/repair.yml` | A file that describes the structure and behavior of the repair API. |
| `appPackage/manifest.json` | Teams application manifest that defines metadata for your plugin inside Microsoft Teams. |
Expand All @@ -61,4 +61,4 @@ The following are Teams Toolkit specific project files. You can [visit a complet
- [Extend Microsoft Copilot for Microsoft 365](https://aka.ms/teamsfx-copilot-plugin)
- [Message extensions for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-message-extension-bot)
- [Microsoft Graph Connectors for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-graph-connector)
- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples)
- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples)
60 changes: 57 additions & 3 deletions templates/ts/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,66 @@
{
"schema_version": "v2.1",
"namespace": "repairs",
"name_for_human": "{{appName}}${{APP_NAME_SUFFIX}}",
"description_for_human": "Track your repair records",
"description_for_model": "Plugin for searching a repair list, you can search by who's assigned to the repair.",
"functions": [
{
"name": "repair",
"description": "Search for repairs"
"name": "listRepairs",
"description": "Returns a list of repairs with their details and images",
"capabilities": {
"response_semantics": {
"data_path": "$",
"properties": {
"title": "$.title",
"subtitle": "$.description",
"url": "$.image"
},
"static_template": {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"body": [
{
"type": "Container",
"$data": "${$root}",
"items": [
{
"type": "TextBlock",
"text": "id: ${if(id, id, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "title: ${if(title, title, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "description: ${if(description, description, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "assignedTo: ${if(assignedTo, assignedTo, 'N/A')}",
"wrap": true
},
{
"type": "TextBlock",
"text": "date: ${if(date, date, 'N/A')}",
"wrap": true
},
{
"type": "Image",
"url": "${image}",
"$when": "${image != null}"
}
]
}
]
}
}
}
}
],
"runtimes": [
Expand All @@ -19,7 +73,7 @@
"url": "apiSpecificationFile/repair.yml",
"progress_style": "ShowUsageWithInputAndOutput"
},
"run_for_functions": ["repair"]
"run_for_functions": ["listRepairs"]
}
]
}
Loading

0 comments on commit d292dc7

Please sign in to comment.