katarinasvedman-ms / agent-test

Testing the AI dev team repo
0 stars 0 forks source link

Developer.Implement chain for #54 #59

Open agent-app-kapeltol[bot] opened 4 months ago

agent-app-kapeltol[bot] commented 4 months ago

// Run the following command in your terminal to create a new ASP.NET Core Web API project named TodoListApp: dotnet new webapi -o TodoListApp

agent-app-kapeltol[bot] commented 4 months ago
#!/bin/bash

# Create a new ASP.NET Core Web API project named TodoListApp
dotnet new webapi -o TodoListApp

# Navigate into the TodoListApp directory
cd TodoListApp

# Add Azure Functions extension for dependency injection
dotnet add package Microsoft.Azure.Functions.Extensions

# Add Azure Functions SDK
dotnet add package Microsoft.NET.Sdk.Functions

# Create a directory for Azure Functions within the TodoListApp project
mkdir AzureFunctions

# Navigate into the AzureFunctions directory
cd AzureFunctions

# Here we create a basic Azure Function within the TodoListApp project
# This function will be a simple HTTP-triggered function

# Create the function class file
cat > TodoListFunction.cs <<EOF
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace TodoListApp.AzureFunctions
{
    public static class TodoListFunction
    {
        [FunctionName("TodoListFunction")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            return name != null
                ? (ActionResult)new OkObjectResult($"Hello, {name}")
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
        }
    }
}
EOF

# Create the function configuration file
cat > function.json <<EOF
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/TodoListFunction.dll",
  "entryPoint": "TodoListApp.AzureFunctions.TodoListFunction.Run"
}
EOF

# Navigate back to TodoListApp root directory
cd ..

# Since the function will be running in Azure, we don't need to build it locally
# Automation and deployment will be handled by CI/CD setup in the Azure DevOps pipeline

# The bash script ends here. The next steps would involve setting up Azure DevOps pipelines
# to automate the deployment of TodoListApp and its associated Azure Function to Azure.
# This would be done through the Azure DevOps portal and is not part of the script.

Please note that this script creates a basic structure of an ASP.NET Core Web API project along with a single Azure Function inside it. For a full application, you would likely need more setup, such as configuring the Startup.cs, adding models, controllers, and other dependencies. Also, the actual deployment to Azure would require additional steps such as creating Azure resources, setting up CI/CD pipelines, and more, which are beyond the scope of this script.