Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit dd96069

Browse files
Release V1.1 (#12)
* removed old configurations * Add or update the Azure App Service build and deployment workflow config * using development env * removed slot name from deployment workflow * docs improved * added documentation that explain how to run the thing * doc detail * removed properties * reduced section name lenght * Fixed vs code launch settings * Feature get plugins with metadata (#9) get Plugins return both the plugins, counter, and max count of plugins allowed for the user * Feature prevent plugin create after max reached (#11) * plugin name validation * fixed plugin not appearing * removed legacy setting * [vs code env] some fixes to properly run and debug in vs code * get Plugins shall return both the plugins, counter, and max count of plugins allowed for the user * [vs code env] fixes to tasks.json to properly build project * prevent user from creating more plugins than allowed * Added name validation on update * minor fixes and cleanup using mapper * version update * ammend on previous wrong merge * added missing repo * added missing null check --------- Co-authored-by: Michele Bortot <[email protected]> * minor fix --------- Co-authored-by: TouchySpidey <[email protected]>
1 parent 2f68eeb commit dd96069

24 files changed

+231
-416
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Build and deploy ASP.Net Core app to Azure Web App - aiplugin-dev
5+
6+
on:
7+
push:
8+
branches:
9+
- dev
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Set up .NET Core
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: '7.x'
23+
include-prerelease: true
24+
25+
- name: Build with dotnet
26+
run: dotnet build --configuration Release
27+
28+
- name: dotnet publish
29+
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
30+
31+
- name: Upload artifact for deployment job
32+
uses: actions/upload-artifact@v2
33+
with:
34+
name: .net-app
35+
path: ${{env.DOTNET_ROOT}}/myapp
36+
37+
deploy:
38+
runs-on: ubuntu-latest
39+
needs: build
40+
environment:
41+
name: 'Development'
42+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
43+
44+
steps:
45+
- name: Download artifact from build job
46+
uses: actions/download-artifact@v2
47+
with:
48+
name: .net-app
49+
50+
- name: Deploy to Azure Web App
51+
id: deploy-to-webapp
52+
uses: azure/webapps-deploy@v2
53+
with:
54+
app-name: 'aiplugin-dev'
55+
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_4A2553DE2662436582B6E3FD7FBBBC7B }}
56+
package: .

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,7 @@ ASALocalRun/
335335
/AiPlugin.Api/AiPlugin.Api.csproj.user
336336
/Api/appsettings.Development.json
337337
/Api/FirebaseDoNotShareKeys.json
338+
/Api/appsettings.Prod.json
339+
/Api/appsettings.LocalDevelopment.json
340+
/Api/appsettings.Staging.json
341+
/Api/appsettings.Production.json

.vscode/launch.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
// Use IntelliSense to find out which attributes exist for C# debugging
6-
// Use hover for the description of the existing attributes
7-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
85
"name": ".NET Core Launch (web)",
96
"type": "coreclr",
107
"request": "launch",
118
"preLaunchTask": "build",
12-
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/AiPlugin.Api/bin/Debug/net7.0/AiPlugin.Api.dll",
9+
"program": "${workspaceFolder}/Api/bin/Debug/net7.0/Api.dll",
1410
"args": [],
15-
"cwd": "${workspaceFolder}/AiPlugin.Api",
11+
"cwd": "${workspaceFolder}/Api",
1612
"stopAtEntry": false,
17-
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
1813
"serverReadyAction": {
1914
"action": "openExternally",
20-
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
15+
"uriFormat": "%s/swagger/index.html"
2116
},
2217
"env": {
2318
"ASPNETCORE_ENVIRONMENT": "Development"

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "process",
88
"args": [
99
"build",
10-
"${workspaceFolder}/AiPlugin.Api/AiPlugin.Api.csproj",
10+
"${workspaceFolder}/Api/Api.csproj",
1111
"/property:GenerateFullPaths=true",
1212
"/consoleloggerparameters:NoSummary"
1313
],
@@ -19,7 +19,7 @@
1919
"type": "process",
2020
"args": [
2121
"publish",
22-
"${workspaceFolder}/AiPlugin.Api/AiPlugin.Api.csproj",
22+
"${workspaceFolder}/Api/Api.csproj",
2323
"/property:GenerateFullPaths=true",
2424
"/consoleloggerparameters:NoSummary"
2525
],
@@ -33,7 +33,7 @@
3333
"watch",
3434
"run",
3535
"--project",
36-
"${workspaceFolder}/AiPlugin.Api/AiPlugin.Api.csproj"
36+
"${workspaceFolder}/Api/Api.csproj"
3737
],
3838
"problemMatcher": "$msCompile"
3939
}

Api/Controllers/PluginController.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace AiPlugin.Api.Controllers;
1414
[Route("api/plugins")]
1515
public class PluginController : ControllerBase
1616
{
17-
private readonly IBaseRepository<Plugin> pluginRepository;
17+
private readonly IPluginRepository pluginRepository;
1818
private readonly IMapper mapper;
19-
public PluginController(IBaseRepository<Plugin> pluginRepository, IMapper mapper)
19+
public PluginController(IPluginRepository pluginRepository, IMapper mapper)
2020
{
2121
this.pluginRepository = pluginRepository;
2222
this.mapper = mapper;
@@ -26,6 +26,9 @@ public PluginController(IBaseRepository<Plugin> pluginRepository, IMapper mapper
2626
[HttpPost]
2727
public async Task<ActionResult<Plugin>> CreatePlugin([FromBody] PluginCreateRequest request)
2828
{
29+
var plugins = await GetUserPlugins();
30+
if (plugins.PluginsCount >= plugins.MaxPlugins) return BadRequest("Max plugins reached");
31+
2932
var plugin = mapper.Map<Plugin>(request);
3033
plugin.UserId = GetUserId();
3134
var createdPlugin = await pluginRepository.Add(plugin);
@@ -34,11 +37,9 @@ public async Task<ActionResult<Plugin>> CreatePlugin([FromBody] PluginCreateRequ
3437

3538
// Get plugins
3639
[HttpGet]
37-
public async Task<ActionResult<IEnumerable<Plugin>>> GetPlugins()
40+
public async Task<ActionResult<PluginsGetResponse>> GetPlugins()
3841
{
39-
var userId = GetUserId();
40-
var plugins = await pluginRepository.Get().Where(p => p.UserId == userId).ToListAsync();
41-
return Ok(plugins);
42+
return Ok(await GetUserPlugins());
4243
}
4344

4445
// Get plugin
@@ -201,5 +202,15 @@ private bool IsMatchingAuthenticatedUserId(string userId)
201202
{
202203
return string.Equals(userId, GetUserId(), StringComparison.OrdinalIgnoreCase);
203204
}
205+
206+
private async Task<PluginsGetResponse> GetUserPlugins()
207+
{
208+
var plugins = await pluginRepository
209+
.Get(GetUserId())
210+
.ToListAsync();
211+
212+
return mapper.Map<PluginsGetResponse>(plugins);
213+
}
214+
204215
#endregion
205216
}

Api/Controllers/PublicPluginController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace AiPlugin.Api.Controllers;
1212
[ApiController]
1313
public class PublicPluginController : ControllerBase
1414
{
15-
private readonly IBaseRepository<Plugin> pluginRepository;
15+
private readonly IPluginRepository pluginRepository;
1616
private readonly int millisecondsDelay = 700;
1717
private readonly IMapper mapper;
18-
public PublicPluginController(IBaseRepository<Plugin> pluginRepository, IMapper mapper)
18+
public PublicPluginController(IPluginRepository pluginRepository, IMapper mapper)
1919
{
2020
this.pluginRepository = pluginRepository;
2121
this.mapper = mapper;

Api/Dto/PluginsGetResponse.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using AiPlugin.Domain;
3+
4+
namespace AiPlugin.Api.Dto;
5+
public class PluginsGetResponse
6+
{
7+
public int PluginsCount { get; set; }
8+
public int MaxPlugins { get; set; }
9+
public IEnumerable<Plugin> Plugins { get; set; } = null!;
10+
}

Api/Mappings/MappingProfile.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public MappingProfile()
2929
{
3030
dest.Paths = new OpenApiPaths();
3131

32-
foreach (var section in src.Sections)
32+
foreach (var section in src.Sections?? new List<Section>())
3333
{
3434
dest.Paths.Add($"/{section.Name}", new OpenApiPathItem
3535
{
@@ -112,6 +112,11 @@ public MappingProfile()
112112
CreateMap<PluginUpdateRequest, Plugin>();
113113
CreateMap<SectionCreateRequest, Section>();
114114
CreateMap<SectionUpdateRequest, Section>();
115+
116+
CreateMap<IEnumerable<Plugin>, PluginsGetResponse>()
117+
.ForMember(dest => dest.PluginsCount, opt => opt.MapFrom(src => src.Count()))
118+
.ForMember(dest => dest.MaxPlugins, opt => opt.MapFrom(src => 3))
119+
.ForMember(dest => dest.Plugins, opt => opt.MapFrom(src => src));
115120
}
116121

117122
private string GetBaseUrl()

Api/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
var builder = WebApplication.CreateBuilder(args);
1111

1212
builder.Logging.AddConsole();
13-
//deserialize and inject GPTSettings fron "GPTSettings" section of appsettings.json
14-
var gPTSettings = builder.Configuration.GetSection("GPTSettings").Get<GPTSettings>()!;
15-
builder.Services.AddSingleton(gPTSettings);
1613

1714
//var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
1815
//builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
@@ -33,7 +30,7 @@
3330
});
3431
});
3532

36-
var version = "1.2.2"; //pluginId and admin subdomain management with authenticated users
33+
var version = "1.2.3"; //added plugin count and max plugin count to get plugins response
3734
builder.Services.AddSwaggerGen(options =>
3835
{
3936
options.OperationFilter<OpenApiParameterIgnoreFilter>();
@@ -46,7 +43,7 @@
4643
});
4744

4845

49-
builder.Services.AddScoped<IBaseRepository<Plugin>, PluginRepository>();
46+
builder.Services.AddScoped<IPluginRepository, PluginRepository>();
5047

5148
builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; })
5249
.AddJwtBearer(options =>

0 commit comments

Comments
 (0)