diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..ef84a27 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.25.0", + "commands": [ + "dotnet-csharpier" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9965de2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,477 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6abb0ba --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dotnet.defaultSolution": "GitHubActionsDemo.sln" +} diff --git a/GitHubActionsDemo.sln b/GitHubActionsDemo.sln new file mode 100644 index 0000000..c245ed4 --- /dev/null +++ b/GitHubActionsDemo.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{53A44CCA-C5C6-4D98-91B8-D331D68BF7B0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubActionsDemo.Api", "src\GitHubActionsDemo.Api\GitHubActionsDemo.Api.csproj", "{E3C34F79-B74E-44A4-99F0-B0B3C2D7CCB2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubActionsDemo.Service", "src\GitHubActionsDemo.Service\GitHubActionsDemo.Service.csproj", "{F6807FFB-3C0D-4F84-8803-8ECAFD72EF76}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubActionsDemo.Persistance", "src\GitHubActionsDemo.Persistance\GitHubActionsDemo.Persistance.csproj", "{339301B3-E9BD-45D1-B6A9-94F41367DF16}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E3C34F79-B74E-44A4-99F0-B0B3C2D7CCB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3C34F79-B74E-44A4-99F0-B0B3C2D7CCB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3C34F79-B74E-44A4-99F0-B0B3C2D7CCB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3C34F79-B74E-44A4-99F0-B0B3C2D7CCB2}.Release|Any CPU.Build.0 = Release|Any CPU + {F6807FFB-3C0D-4F84-8803-8ECAFD72EF76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6807FFB-3C0D-4F84-8803-8ECAFD72EF76}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6807FFB-3C0D-4F84-8803-8ECAFD72EF76}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6807FFB-3C0D-4F84-8803-8ECAFD72EF76}.Release|Any CPU.Build.0 = Release|Any CPU + {339301B3-E9BD-45D1-B6A9-94F41367DF16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {339301B3-E9BD-45D1-B6A9-94F41367DF16}.Debug|Any CPU.Build.0 = Debug|Any CPU + {339301B3-E9BD-45D1-B6A9-94F41367DF16}.Release|Any CPU.ActiveCfg = Release|Any CPU + {339301B3-E9BD-45D1-B6A9-94F41367DF16}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {E3C34F79-B74E-44A4-99F0-B0B3C2D7CCB2} = {53A44CCA-C5C6-4D98-91B8-D331D68BF7B0} + {F6807FFB-3C0D-4F84-8803-8ECAFD72EF76} = {53A44CCA-C5C6-4D98-91B8-D331D68BF7B0} + {339301B3-E9BD-45D1-B6A9-94F41367DF16} = {53A44CCA-C5C6-4D98-91B8-D331D68BF7B0} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index 00f09e9..44dbeac 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# cicd-github-actions +# Setup a CI/CD Pipeline Using GitHub Actions The code from my YouTube video on "Setup a CI/CD Pipeline Using GitHub Actions" diff --git a/src/GitHubActionsDemo.Api/Controllers/LibraryController.cs b/src/GitHubActionsDemo.Api/Controllers/LibraryController.cs new file mode 100644 index 0000000..b9a0509 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Controllers/LibraryController.cs @@ -0,0 +1,51 @@ +using GitHubActionsDemo.Api.Models; +using GitHubActionsDemo.Api.Mappers; +using GitHubActionsDemo.Service; +using Microsoft.AspNetCore.Mvc; + +namespace GitHubActionsDemo.Api.Controllers; + +[ApiController] +[Route("[controller]")] +public class LibraryController : ControllerBase +{ + private readonly ILogger _logger; + private readonly ILibraryService _libraryService; + + public LibraryController( + ILogger logger, + ILibraryService libraryService + ) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _libraryService = libraryService ?? throw new ArgumentNullException(nameof(libraryService)); + } + + [HttpGet(Name = "GetBooks")] + public async Task> GetBooksAsync(int page = 0, int pageSize = 10) + { + var books = await _libraryService.GetBooksAsync(page, pageSize); + return books.Select(x => x.Map()); + } + + [HttpGet(Name = "GetBook")] + public async Task GetBookAsync(int bookId) + { + var book = await _libraryService.GetBookAsync(bookId); + return book.Map(); + } + + [HttpPost(Name = "AddBook")] + public async Task AddBookAsync(BookRequest bookRequest) + { + var book = await _libraryService.AddBookAsync(bookRequest.Map()); + return book.Map(); + } + + [HttpPost(Name = "AddAuthor")] + public async Task AddauthorAsync(AuthorRequest authorRequest) + { + var author = await _libraryService.AddAuthorAsync(authorRequest.Map()); + return author.Map(); + } +} diff --git a/src/GitHubActionsDemo.Api/GitHubActionsDemo.Api.csproj b/src/GitHubActionsDemo.Api/GitHubActionsDemo.Api.csproj new file mode 100644 index 0000000..c3b2f07 --- /dev/null +++ b/src/GitHubActionsDemo.Api/GitHubActionsDemo.Api.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + enable + enable + GitHubActionsDemo.Api + + + + + + + + + + + + diff --git a/src/GitHubActionsDemo.Api/Mappers/AuthorMapper.cs b/src/GitHubActionsDemo.Api/Mappers/AuthorMapper.cs new file mode 100644 index 0000000..a2b42f4 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Mappers/AuthorMapper.cs @@ -0,0 +1,26 @@ +using GitHubActionsDemo.Api.Models; +using GitHubActionsDemo.Service.Models; + +namespace GitHubActionsDemo.Api.Mappers; + +public static class AuthorMapper +{ + public static NewAuthor Map(this AuthorRequest request) + { + return new NewAuthor( + request.FirstName, + request.LastName + ); + } + + public static AuthorResponse Map(this Author author) + { + return new AuthorResponse( + author.AuthorId, + author.FirstName, + author.LastName, + author.DateCreated, + author.DateModified + ); + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Api/Mappers/BookMapper.cs b/src/GitHubActionsDemo.Api/Mappers/BookMapper.cs new file mode 100644 index 0000000..f2ac907 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Mappers/BookMapper.cs @@ -0,0 +1,30 @@ +using GitHubActionsDemo.Api.Models; +using GitHubActionsDemo.Service.Models; + +namespace GitHubActionsDemo.Api.Mappers; + +public static class BookMapper +{ + public static NewBook Map(this BookRequest request) + { + return new NewBook( + request.Title, + request.AuthorId, + request.Isbn, + request.DatePublished + ); + } + + public static BookResponse Map(this Book book) + { + return new BookResponse( + book.BookId, + book.Title, + book.Author.Map(), + book.Isbn, + book.DatePublished, + book.DateCreated, + book.DateModified + ); + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Api/Models/AuthorRequest.cs b/src/GitHubActionsDemo.Api/Models/AuthorRequest.cs new file mode 100644 index 0000000..1ab4593 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Models/AuthorRequest.cs @@ -0,0 +1,7 @@ +namespace GitHubActionsDemo.Api.Models; + +public class AuthorRequest +{ + public string FirstName { get; set; } + public string LastName { get; set; } +} diff --git a/src/GitHubActionsDemo.Api/Models/AuthorResponse.cs b/src/GitHubActionsDemo.Api/Models/AuthorResponse.cs new file mode 100644 index 0000000..2c04b51 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Models/AuthorResponse.cs @@ -0,0 +1,25 @@ +namespace GitHubActionsDemo.Api.Models; + +public class AuthorResponse +{ + public AuthorResponse( + int authorId, + string firstName, + string lastName, + DateTime dateCreated, + DateTime dateModified + ) + { + AuthorId = authorId; + FirstName = firstName; + LastName = lastName; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public int AuthorId { get; } + public string FirstName { get; } + public string LastName { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Api/Models/BookRequest.cs b/src/GitHubActionsDemo.Api/Models/BookRequest.cs new file mode 100644 index 0000000..1d099a8 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Models/BookRequest.cs @@ -0,0 +1,9 @@ +namespace GitHubActionsDemo.Api.Models; + +public class BookRequest +{ + public string Title { get; set; } + public int AuthorId { get; set; } + public string Isbn { get; set; } + public DateOnly DatePublished { get; set; } +} diff --git a/src/GitHubActionsDemo.Api/Models/BookResponse.cs b/src/GitHubActionsDemo.Api/Models/BookResponse.cs new file mode 100644 index 0000000..9b340ad --- /dev/null +++ b/src/GitHubActionsDemo.Api/Models/BookResponse.cs @@ -0,0 +1,31 @@ +namespace GitHubActionsDemo.Api.Models; + +public class BookResponse +{ + public BookResponse( + int bookId, + string title, + AuthorResponse author, + string isbn, + DateOnly datePublished, + DateTime dateCreated, + DateTime dateModified + ) + { + BookId = bookId; + Title = title; + Author = author; + Isbn = isbn; + DatePublished = datePublished; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public int BookId { get; } + public string Title { get; } + public AuthorResponse Author { get; } + public string Isbn { get; } + public DateOnly DatePublished { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Api/Program.cs b/src/GitHubActionsDemo.Api/Program.cs new file mode 100644 index 0000000..0c58634 --- /dev/null +++ b/src/GitHubActionsDemo.Api/Program.cs @@ -0,0 +1,22 @@ +using GitHubActionsDemo.Service; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +// DI +builder.Services.AddScoped(); +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); +app.MapControllers(); +app.Run(); diff --git a/src/GitHubActionsDemo.Api/Properties/launchSettings.json b/src/GitHubActionsDemo.Api/Properties/launchSettings.json new file mode 100644 index 0000000..972646e --- /dev/null +++ b/src/GitHubActionsDemo.Api/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:41272", + "sslPort": 44315 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5275", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7025;http://localhost:5275", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/GitHubActionsDemo.Api/appsettings.Development.json b/src/GitHubActionsDemo.Api/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/src/GitHubActionsDemo.Api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/GitHubActionsDemo.Api/appsettings.json b/src/GitHubActionsDemo.Api/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/src/GitHubActionsDemo.Api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/GitHubActionsDemo.Persistance/GitHubActionsDemo.Persistance.csproj b/src/GitHubActionsDemo.Persistance/GitHubActionsDemo.Persistance.csproj new file mode 100644 index 0000000..360ddbe --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/GitHubActionsDemo.Persistance.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/src/GitHubActionsDemo.Persistance/ILibraryRespository.cs b/src/GitHubActionsDemo.Persistance/ILibraryRespository.cs new file mode 100644 index 0000000..097624a --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/ILibraryRespository.cs @@ -0,0 +1,12 @@ +namespace GitHubActionsDemo.Persistance; + +using GitHubActionsDemo.Persistance.Models; + +public interface ILibraryRespository +{ + Task> GetBooksAsync(int page, int pageSize); + Task GetBookAsync(int bookId); + Task AddBookAsync(NewBookDb book); + Task AddAuthorAsync(NewAuthorDb author); + Task GetAuthorAsync(int authorId); +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Persistance/Infrastructure/InfrastructureExtensions.cs b/src/GitHubActionsDemo.Persistance/Infrastructure/InfrastructureExtensions.cs new file mode 100644 index 0000000..711f26c --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/Infrastructure/InfrastructureExtensions.cs @@ -0,0 +1,13 @@ +using GitHubActionsDemo.Persistance; +using Microsoft.Extensions.DependencyInjection; + +namespace GitHubActionsDemo.Service.Infrastructure +{ + public static class InfrastructureExtensions + { + public static IServiceCollection AddPersistanceDependencies(this IServiceCollection services) + { + return services.AddSingleton(); + } + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Persistance/LibraryRespository.cs b/src/GitHubActionsDemo.Persistance/LibraryRespository.cs new file mode 100644 index 0000000..45f6d83 --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/LibraryRespository.cs @@ -0,0 +1,36 @@ +using GitHubActionsDemo.Persistance.Models; + +namespace GitHubActionsDemo.Persistance; + +public class LibraryRespository : ILibraryRespository +{ + public LibraryRespository() + { + + } + + public async Task AddAuthorAsync(NewAuthorDb author) + { + throw new NotImplementedException(); + } + + public async Task GetAuthorAsync(int authorId) + { + throw new NotImplementedException(); + } + + public async Task AddBookAsync(NewBookDb book) + { + throw new NotImplementedException(); + } + + public async Task GetBookAsync(int bookId) + { + throw new NotImplementedException(); + } + + public async Task> GetBooksAsync(int page, int pageSize) + { + throw new NotImplementedException(); + } +} diff --git a/src/GitHubActionsDemo.Persistance/Models/AuthorDb.cs b/src/GitHubActionsDemo.Persistance/Models/AuthorDb.cs new file mode 100644 index 0000000..f587a5a --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/Models/AuthorDb.cs @@ -0,0 +1,25 @@ +namespace GitHubActionsDemo.Persistance.Models; + +public class AuthorDb +{ + public AuthorDb( + int authorId, + string firstName, + string lastName, + DateTime dateCreated, + DateTime dateModified + ) + { + AuthorId = authorId; + FirstName = firstName; + LastName = lastName; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public int AuthorId { get; } + public string FirstName { get; } + public string LastName { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Persistance/Models/BookDb.cs b/src/GitHubActionsDemo.Persistance/Models/BookDb.cs new file mode 100644 index 0000000..5bad5ff --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/Models/BookDb.cs @@ -0,0 +1,31 @@ +namespace GitHubActionsDemo.Persistance.Models; + +public class BookDb +{ + public BookDb( + int bookId, + string title, + AuthorDb author, + string isbn, + DateOnly datePublished, + DateTime dateCreated, + DateTime dateModified + ) + { + BookId = bookId; + Title = title; + Author = author; + Isbn = isbn; + DatePublished = datePublished; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public int BookId { get; } + public string Title { get; } + public AuthorDb Author { get; } + public string Isbn { get; } + public DateOnly DatePublished { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Persistance/Models/NewAuthorDb.cs b/src/GitHubActionsDemo.Persistance/Models/NewAuthorDb.cs new file mode 100644 index 0000000..aa15b20 --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/Models/NewAuthorDb.cs @@ -0,0 +1,22 @@ +namespace GitHubActionsDemo.Persistance.Models; + +public class NewAuthorDb +{ + public NewAuthorDb( + string firstName, + string lastName, + DateTime dateCreated, + DateTime dateModified + ) + { + FirstName = firstName; + LastName = lastName; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public string FirstName { get; } + public string LastName { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Persistance/Models/NewBookDb.cs b/src/GitHubActionsDemo.Persistance/Models/NewBookDb.cs new file mode 100644 index 0000000..6144cf6 --- /dev/null +++ b/src/GitHubActionsDemo.Persistance/Models/NewBookDb.cs @@ -0,0 +1,29 @@ +namespace GitHubActionsDemo.Persistance.Models; + +public class NewBookDb +{ + public NewBookDb( + string title, + int authorId, + string isbn, + DateOnly datePublished, + DateTime dateCreated, + DateTime dateModified + ) + { + Title = title; + AuthorId = authorId; + Isbn = isbn; + DatePublished = datePublished; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public int BookId { get; } + public string Title { get; } + public int AuthorId { get; } + public string Isbn { get; } + public DateOnly DatePublished { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Service/GitHubActionsDemo.Service.csproj b/src/GitHubActionsDemo.Service/GitHubActionsDemo.Service.csproj new file mode 100644 index 0000000..5216cb4 --- /dev/null +++ b/src/GitHubActionsDemo.Service/GitHubActionsDemo.Service.csproj @@ -0,0 +1,17 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + diff --git a/src/GitHubActionsDemo.Service/ILibraryService.cs b/src/GitHubActionsDemo.Service/ILibraryService.cs new file mode 100644 index 0000000..8b52d9d --- /dev/null +++ b/src/GitHubActionsDemo.Service/ILibraryService.cs @@ -0,0 +1,11 @@ +using GitHubActionsDemo.Service.Models; + +namespace GitHubActionsDemo.Service; + +public interface ILibraryService +{ + Task> GetBooksAsync(int page, int pageSize); + Task GetBookAsync(int bookId); + Task AddBookAsync(NewBook book); + Task AddAuthorAsync(NewAuthor author); +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Service/Infrastructure/InfrastructureExtensions.cs b/src/GitHubActionsDemo.Service/Infrastructure/InfrastructureExtensions.cs new file mode 100644 index 0000000..f928db3 --- /dev/null +++ b/src/GitHubActionsDemo.Service/Infrastructure/InfrastructureExtensions.cs @@ -0,0 +1,15 @@ +using GitHubActionsDemo.Persistance; +using Microsoft.Extensions.DependencyInjection; + +namespace GitHubActionsDemo.Service.Infrastructure +{ + public static class InfrastructureExtensions + { + public static IServiceCollection AddServiceDependencies(this IServiceCollection services) + { + return services + .AddScoped() + .AddPersistanceDependencies(); + } + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Service/LibraryService.cs b/src/GitHubActionsDemo.Service/LibraryService.cs new file mode 100644 index 0000000..47e7283 --- /dev/null +++ b/src/GitHubActionsDemo.Service/LibraryService.cs @@ -0,0 +1,39 @@ +using GitHubActionsDemo.Persistance; +using GitHubActionsDemo.Service.Mappers; +using GitHubActionsDemo.Service.Models; + +namespace GitHubActionsDemo.Service; + +public class LibraryService : ILibraryService +{ + private readonly ILibraryRespository _libraryRepository; + + public LibraryService(ILibraryRespository libraryRepository) + { + _libraryRepository = libraryRepository ?? throw new ArgumentNullException(nameof(libraryRepository)); + } + + public async Task AddAuthorAsync(NewAuthor newAuthor) + { + var author = await _libraryRepository.AddAuthorAsync(newAuthor.Map()); + return author.Map(); + } + + public async Task AddBookAsync(NewBook newBook) + { + var book = await _libraryRepository.AddBookAsync(newBook.Map()); + return book.Map(); + } + + public async Task GetBookAsync(int bookId) + { + var book = await _libraryRepository.GetBookAsync(bookId); + return book.Map(); + } + + public async Task> GetBooksAsync(int page, int pageSize) + { + var books = await _libraryRepository.GetBooksAsync(page, pageSize); + return books.Select(book => book.Map()); + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Service/Mappers/AuthorMapper.cs b/src/GitHubActionsDemo.Service/Mappers/AuthorMapper.cs new file mode 100644 index 0000000..2b1d83e --- /dev/null +++ b/src/GitHubActionsDemo.Service/Mappers/AuthorMapper.cs @@ -0,0 +1,29 @@ + +using GitHubActionsDemo.Persistance.Models; +using GitHubActionsDemo.Service.Models; + +namespace GitHubActionsDemo.Service.Mappers; + +public static class AuthorMapper +{ + public static NewAuthorDb Map(this NewAuthor author) + { + return new NewAuthorDb( + author.FirstName, + author.LastName, + DateTime.UtcNow, + DateTime.UtcNow + ); + } + + public static Author Map(this AuthorDb author) + { + return new Author( + author.AuthorId, + author.FirstName, + author.LastName, + author.DateCreated, + author.DateModified + ); + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Service/Mappers/BookMapper.cs b/src/GitHubActionsDemo.Service/Mappers/BookMapper.cs new file mode 100644 index 0000000..41970aa --- /dev/null +++ b/src/GitHubActionsDemo.Service/Mappers/BookMapper.cs @@ -0,0 +1,32 @@ +using GitHubActionsDemo.Persistance.Models; +using GitHubActionsDemo.Service.Models; + +namespace GitHubActionsDemo.Service.Mappers; + +public static class BookMapper +{ + public static NewBookDb Map(this NewBook book) + { + return new NewBookDb( + book.Title, + book.AuthorId, + book.Isbn, + book.DatePublished, + DateTime.UtcNow, + DateTime.UtcNow + ); + } + + public static Book Map(this BookDb book) + { + return new Book( + book.BookId, + book.Title, + book.Author.Map(), + book.Isbn, + book.DatePublished, + book.DateCreated, + book.DateModified + ); + } +} \ No newline at end of file diff --git a/src/GitHubActionsDemo.Service/Models/Author.cs b/src/GitHubActionsDemo.Service/Models/Author.cs new file mode 100644 index 0000000..a8d0335 --- /dev/null +++ b/src/GitHubActionsDemo.Service/Models/Author.cs @@ -0,0 +1,25 @@ +namespace GitHubActionsDemo.Service.Models; + +public class Author +{ + public Author( + int authorId, + string firstName, + string lastName, + DateTime dateCreated, + DateTime dateUpdated + ) + { + AuthorId = authorId; + FirstName = firstName; + LastName = lastName; + DateCreated = dateCreated; + DateModified = dateUpdated; + } + + public int AuthorId { get; } + public string FirstName { get; } + public string LastName { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Service/Models/Book.cs b/src/GitHubActionsDemo.Service/Models/Book.cs new file mode 100644 index 0000000..d334c29 --- /dev/null +++ b/src/GitHubActionsDemo.Service/Models/Book.cs @@ -0,0 +1,31 @@ +namespace GitHubActionsDemo.Service.Models; + +public class Book +{ + public Book( + int bookId, + string title, + Author author, + string isbn, + DateOnly datePublished, + DateTime dateCreated, + DateTime dateModified + ) + { + BookId = bookId; + Title = title; + Author = author; + Isbn = isbn; + DatePublished = datePublished; + DateCreated = dateCreated; + DateModified = dateModified; + } + + public int BookId { get; } + public string Title { get; } + public Author Author { get; } + public string Isbn { get; } + public DateOnly DatePublished { get; } + public DateTime DateCreated { get; } + public DateTime DateModified { get; } +} diff --git a/src/GitHubActionsDemo.Service/Models/NewAuthor.cs b/src/GitHubActionsDemo.Service/Models/NewAuthor.cs new file mode 100644 index 0000000..ef0af5c --- /dev/null +++ b/src/GitHubActionsDemo.Service/Models/NewAuthor.cs @@ -0,0 +1,16 @@ +namespace GitHubActionsDemo.Service.Models; + +public class NewAuthor +{ + public NewAuthor( + string firstName, + string lastName + ) + { + FirstName = firstName; + LastName = lastName; + } + + public string FirstName { get; } + public string LastName { get; } +} diff --git a/src/GitHubActionsDemo.Service/Models/NewBook.cs b/src/GitHubActionsDemo.Service/Models/NewBook.cs new file mode 100644 index 0000000..1679f5f --- /dev/null +++ b/src/GitHubActionsDemo.Service/Models/NewBook.cs @@ -0,0 +1,22 @@ +namespace GitHubActionsDemo.Service.Models; + +public class NewBook +{ + public NewBook( + string title, + int authorId, + string isbn, + DateOnly datePublished + ) + { + Title = title; + AuthorId = authorId; + Isbn = isbn; + DatePublished = datePublished; + } + + public string Title { get; } + public int AuthorId { get; } + public string Isbn { get; } + public DateOnly DatePublished { get; } +} \ No newline at end of file