-
Notifications
You must be signed in to change notification settings - Fork 18
[Backend API] Implement endpoint for new resource details #308 #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
o-ii
wants to merge
8
commits into
aliencube:main
Choose a base branch
from
o-ii:feature/308-endpoint-for-resource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+353
−3
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e27891b
[Backend API] Implement endpoint for new resource details #308
o-ii b541abf
Refactor tableNames parameter to use 'events' instead of 'resources'
o-ii fbcbb81
Merge branch 'aliencube:main' into feature/308-endpoint-for-resource
o-ii b10c7ed
Merge branch 'aliencube:main' into feature/308-endpoint-for-resource
o-ii 717e415
Merge branch 'aliencube:main' into feature/308-endpoint-for-resource
o-ii 69e6eb4
Add unit tests for AdminResourceRepository and AdminResourceService
o-ii 37a2fe5
Rename test methods in AdminResourceServiceTests
o-ii 0379436
Add failure test for CreateResource in AdminResourceRepositoryTests
o-ii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
65 changes: 65 additions & 0 deletions
65
src/AzureOpenAIProxy.ApiApp/Repositories/AdminResourceRepository.cs
This file contains hidden or 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,65 @@ | ||
| using Azure.Data.Tables; | ||
|
|
||
| using AzureOpenAIProxy.ApiApp.Configurations; | ||
| using AzureOpenAIProxy.ApiApp.Models; | ||
|
|
||
| namespace AzureOpenAIProxy.ApiApp.Repositories; | ||
|
|
||
| /// <summary> | ||
| /// This provides interfaces to the <see cref="AdminResourceRepository"/> class. | ||
| /// </summary> | ||
| public interface IAdminResourceRepository | ||
| { | ||
| /// <summary> | ||
| /// Creates a new record of resource details. | ||
| /// </summary> | ||
| /// <param name="resourceDetails">Resource details instance.</param> | ||
| /// <returns>Returns the resource details instance created.</returns> | ||
| Task<AdminResourceDetails> CreateResource(AdminResourceDetails resourceDetails); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This represents the repository entity for the admin resource. | ||
| /// </summary> | ||
| public class AdminResourceRepository(TableServiceClient tableServiceClient, StorageAccountSettings storageAccountSettings) : IAdminResourceRepository | ||
| { | ||
| private readonly TableServiceClient _tableServiceClient = tableServiceClient ?? throw new ArgumentNullException(nameof(tableServiceClient)); | ||
| private readonly StorageAccountSettings _storageAccountSettings = storageAccountSettings ?? throw new ArgumentNullException(nameof(storageAccountSettings)); | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<AdminResourceDetails> CreateResource(AdminResourceDetails resourceDetails) | ||
| { | ||
| TableClient tableClient = await GetTableClientAsync(); | ||
|
|
||
| await tableClient.AddEntityAsync(resourceDetails).ConfigureAwait(false); | ||
|
|
||
| return resourceDetails; | ||
| } | ||
|
|
||
| private async Task<TableClient> GetTableClientAsync() | ||
| { | ||
| TableClient tableClient = _tableServiceClient.GetTableClient(_storageAccountSettings.TableStorage.TableName); | ||
|
|
||
| await tableClient.CreateIfNotExistsAsync().ConfigureAwait(false); | ||
|
|
||
| return tableClient; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This represents the extension class for <see cref="IServiceCollection"/> | ||
| /// </summary> | ||
| public static class AdminResourceRepositoryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds the <see cref="AdminResourceRepository"/> instance to the service collection. | ||
| /// </summary> | ||
| /// <param name="services"><see cref="IServiceCollection"/> instance.</param> | ||
| /// <returns>Returns <see cref="IServiceCollection"/> instance.</returns> | ||
| public static IServiceCollection AddAdminResourceRepository(this IServiceCollection services) | ||
| { | ||
| services.AddScoped<IAdminResourceRepository, AdminResourceRepository>(); | ||
|
|
||
| return services; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
src/AzureOpenAIProxy.ApiApp/Services/AdminResourceService.cs
This file contains hidden or 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,57 @@ | ||
| using AzureOpenAIProxy.ApiApp.Models; | ||
| using AzureOpenAIProxy.ApiApp.Repositories; | ||
|
|
||
| namespace AzureOpenAIProxy.ApiApp.Services; | ||
|
|
||
| /// <summary> | ||
| /// This provides interfaces to the <see cref="AdminResourceService"/> class. | ||
| /// </summary> | ||
| public interface IAdminResourceService | ||
| { | ||
| /// <summary> | ||
| /// Creates a new resource. | ||
| /// </summary> | ||
| /// <param name="resourceDetails">Resource payload.</param> | ||
| /// <returns>Returns the resource payload created.</returns> | ||
| Task<AdminResourceDetails> CreateResource(AdminResourceDetails resourceDetails); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This represents the service entity for admin resource. | ||
| /// </summary> | ||
| public class AdminResourceService : IAdminResourceService | ||
| { | ||
| private readonly IAdminResourceRepository _repository; | ||
|
|
||
| public AdminResourceService(IAdminResourceRepository repository) | ||
| { | ||
| _repository = repository ?? throw new ArgumentNullException(nameof(repository)); | ||
| } | ||
justinyoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<AdminResourceDetails> CreateResource(AdminResourceDetails resourceDetails) | ||
| { | ||
| resourceDetails.PartitionKey = PartitionKeys.ResourceDetails; | ||
| resourceDetails.RowKey = resourceDetails.ResourceId.ToString(); | ||
|
|
||
| var result = await _repository.CreateResource(resourceDetails).ConfigureAwait(false); | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This represents the extension class for <see cref="IServiceCollection"/>. | ||
| /// </summary> | ||
| public static class AdminResourceServiceExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds the <see cref="AdminResourceService"/> instance to the service collection. | ||
| /// </summary> | ||
| /// <param name="services"><see cref="IServiceCollection"/> instance.</param> | ||
| /// <returns>Returns <see cref="IServiceCollection"/> instance.</returns> | ||
| public static IServiceCollection AddAdminResourceService(this IServiceCollection services) | ||
| { | ||
| services.AddScoped<IAdminResourceService, AdminResourceService>(); | ||
| return services; | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminResourceRepositoryTests.cs
This file contains hidden or 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,19 @@ | ||
| using Azure; | ||
| using Azure.Data.Tables; | ||
|
|
||
| using AzureOpenAIProxy.ApiApp.Configurations; | ||
| using AzureOpenAIProxy.ApiApp.Models; | ||
| using AzureOpenAIProxy.ApiApp.Repositories; | ||
|
|
||
| using FluentAssertions; | ||
|
|
||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| using NSubstitute; | ||
| using NSubstitute.ExceptionExtensions; | ||
|
|
||
| namespace AzureOpenAIProxy.ApiApp.Tests.Repositories; | ||
|
|
||
| public class AdminResourceRepositoryTests | ||
| { | ||
| } |
18 changes: 18 additions & 0 deletions
18
test/AzureOpenAIProxy.ApiApp.Tests/Services/AdminResourceServiceTests.cs
This file contains hidden or 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,18 @@ | ||
| using Azure; | ||
|
|
||
| using AzureOpenAIProxy.ApiApp.Models; | ||
| using AzureOpenAIProxy.ApiApp.Repositories; | ||
| using AzureOpenAIProxy.ApiApp.Services; | ||
|
|
||
| using FluentAssertions; | ||
|
|
||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| using NSubstitute; | ||
| using NSubstitute.ExceptionExtensions; | ||
|
|
||
| namespace AzureOpenAIProxy.ApiApp.Tests.Services; | ||
|
|
||
| public class AdminResourceServiceTests | ||
| { | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.