Skip to content

Commit

Permalink
Add DAL (#2)
Browse files Browse the repository at this point in the history
* Add Message.DAL
  • Loading branch information
atrakic authored Jun 8, 2024
1 parent ec1364e commit d8111bb
Show file tree
Hide file tree
Showing 24 changed files with 205 additions and 44 deletions.
24 changes: 24 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Echo.OpenAPI.sln
README.md
build.bat
build.sh
src/Echo.OpenAPI/.gitignore
src/Echo.OpenAPI/Attributes/ValidateModelStateAttribute.cs
src/Echo.OpenAPI/Authentication/ApiAuthentication.cs
src/Echo.OpenAPI/Controllers/DefaultApi.cs
src/Echo.OpenAPI/Converters/CustomEnumConverter.cs
src/Echo.OpenAPI/Dockerfile
src/Echo.OpenAPI/Echo.OpenAPI.csproj
src/Echo.OpenAPI/Filters/BasePathFilter.cs
src/Echo.OpenAPI/Filters/GeneratePathParamsValidationFilter.cs
src/Echo.OpenAPI/Formatters/InputFormatterStream.cs
src/Echo.OpenAPI/Models/Message.cs
src/Echo.OpenAPI/OpenApi/TypeExtensions.cs
src/Echo.OpenAPI/Program.cs
src/Echo.OpenAPI/Properties/launchSettings.json
src/Echo.OpenAPI/Startup.cs
src/Echo.OpenAPI/appsettings.Development.json
src/Echo.OpenAPI/appsettings.json
src/Echo.OpenAPI/wwwroot/README.md
src/Echo.OpenAPI/wwwroot/index.html
src/Echo.OpenAPI/wwwroot/openapi-original.json
1 change: 1 addition & 0 deletions .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.7.0-SNAPSHOT
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand Down
41 changes: 26 additions & 15 deletions Echo.OpenAPI.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Echo.OpenAPI", "src\Echo.OpenAPI\Echo.OpenAPI.csproj", "{28CA127C-200D-4F9B-8AF4-2B1D44D71727}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Echo.OpenAPI", "src\Echo.OpenAPI\Echo.OpenAPI.csproj", "B433BA76-6344-4E1C-B1EA-36CDEABF4A10"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E4A267D8-60B6-4DF9-B444-391FD167AA15}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Message.DAL", "src\Message.DAL\Message.DAL.csproj", "{7A8F3A68-CE1F-4525-9E23-B692181962DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28CA127C-200D-4F9B-8AF4-2B1D44D71727}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
B433BA76-6344-4E1C-B1EA-36CDEABF4A10.Debug|Any CPU.ActiveCfg = Debug|Any CPU
B433BA76-6344-4E1C-B1EA-36CDEABF4A10.Debug|Any CPU.Build.0 = Debug|Any CPU
B433BA76-6344-4E1C-B1EA-36CDEABF4A10.Release|Any CPU.ActiveCfg = Release|Any CPU
B433BA76-6344-4E1C-B1EA-36CDEABF4A10.Release|Any CPU.Build.0 = Release|Any CPU
{7A8F3A68-CE1F-4525-9E23-B692181962DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A8F3A68-CE1F-4525-9E23-B692181962DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A8F3A68-CE1F-4525-9E23-B692181962DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A8F3A68-CE1F-4525-9E23-B692181962DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7A8F3A68-CE1F-4525-9E23-B692181962DA} = {E4A267D8-60B6-4DF9-B444-391FD167AA15}
EndGlobalSection
EndGlobal
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@

all:
all: generate
dotnet sln add src/Message.DAL/Message.DAL.csproj
dotnet restore
dotnet build --configuration Release --no-restore
dotnet test --no-restore --verbosity normal

generate:
./scripts/generate.sh

HELP_ARGS ?= config-help -g aspnetcore

help: ### make help HELP_ARGS=help
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/aspnetcore.md
## docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli config-help -g aspnetcore

aspnetCoreVersion: 6.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ docker run --rm -e CSHARP_POST_PROCESS_FILE=${CSHARP_POST_PROCESS_FILE} -v "${PW
-o /local/"$out"

dos2unix $(find . -type f -exec grep -I -q . {} \; -print)
pre-commit run -a
#pre-commit run -a
2 changes: 1 addition & 1 deletion src/Echo.OpenAPI/Attributes/ValidateModelStateAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Echo.OpenAPI/Authentication/ApiAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down
10 changes: 5 additions & 5 deletions src/Echo.OpenAPI/Controllers/DefaultApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -21,13 +21,13 @@
using Echo.OpenAPI.Models;

namespace Echo.OpenAPI.Controllers
{
{
/// <summary>
///
///
/// </summary>
[ApiController]
public class DefaultApiController : ControllerBase
{
{
/// <summary>
/// Search messages
/// </summary>
Expand All @@ -45,7 +45,7 @@ public virtual IActionResult MessagesGet([FromQuery (Name = "query")]string quer
// return StatusCode(200, default(List<Message>));
string exampleJson = null;
exampleJson = "[ {\n \"id\" : 0,\n \"message\" : \"message\"\n}, {\n \"id\" : 0,\n \"message\" : \"message\"\n} ]";

var example = exampleJson != null
? JsonConvert.DeserializeObject<List<Message>>(exampleJson)
: default(List<Message>);
Expand Down
2 changes: 1 addition & 1 deletion src/Echo.OpenAPI/Converters/CustomEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down
2 changes: 1 addition & 1 deletion src/Echo.OpenAPI/Echo.OpenAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Version>1.0.0</Version>
<AssemblyName>Echo.OpenAPI</AssemblyName>
<PackageId>Echo.OpenAPI</PackageId>
<UserSecretsId>ca94f13f-76ed-41d9-9e2e-c217f7caf605</UserSecretsId>
<UserSecretsId>ded5b03c-cac0-4ceb-966d-61f53ab7e86c</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Echo.OpenAPI/Filters/BasePathFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Echo.OpenAPI/Formatters/InputFormatterStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down Expand Up @@ -42,4 +42,4 @@ protected override bool CanReadType(Type type)
return false;
}
}
}
}
14 changes: 7 additions & 7 deletions src/Echo.OpenAPI/Models/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -19,9 +19,9 @@
using Echo.OpenAPI.Converters;

namespace Echo.OpenAPI.Models
{
{
/// <summary>
///
///
/// </summary>
[DataContract]
public partial class Message : IEquatable<Message>
Expand Down Expand Up @@ -85,12 +85,12 @@ public bool Equals(Message other)
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;

return
return
(
Id == other.Id ||

Id.Equals(other.Id)
) &&
) &&
(
VarMessage == other.VarMessage ||
VarMessage != null &&
Expand All @@ -108,7 +108,7 @@ public override int GetHashCode()
{
var hashCode = 41;
// Suitable nullity checks etc, of course :)

hashCode = hashCode * 59 + Id.GetHashCode();
if (VarMessage != null)
hashCode = hashCode * 59 + VarMessage.GetHashCode();
Expand Down
4 changes: 2 additions & 2 deletions src/Echo.OpenAPI/OpenApi/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down Expand Up @@ -58,4 +58,4 @@ public static string FullNameSansTypeParameters(this Type type)
return (chopIndex == -1) ? fullName : fullName.Substring(0, chopIndex);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Echo.OpenAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61788",
"sslPort": 44301
Expand Down
4 changes: 2 additions & 2 deletions src/Echo.OpenAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A simple API to store and retrieve messages.
*
* The version of the OpenAPI document: 0.0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down Expand Up @@ -71,7 +71,7 @@ public void ConfigureServices(IServiceCollection services)
.AddSwaggerGen(c =>
{
c.EnableAnnotations(enableAnnotationsForInheritance: true, enableAnnotationsForPolymorphism: true);

c.SwaggerDoc("0.0.1", new OpenApiInfo
{
Title = "Echo API",
Expand Down
19 changes: 19 additions & 0 deletions src/Message.DAL/IMessageRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Message.Model;

namespace Message.DAL
{
public interface IMessageRepository
{
MessageItem? GetItem(int id);

IEnumerable<MessageItem> GetItems();

void AddItem(MessageItem item);

void UpdateItem(MessageItem item);

void RemoveItem(MessageItem item);

void SaveChanges();
}
}
13 changes: 13 additions & 0 deletions src/Message.DAL/Message.DAL.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.6" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/Message.DAL/MessageDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Message.Model;

using Microsoft.EntityFrameworkCore;
using System;

namespace Message.DAL
{
public class MessageDbContext : DbContext
{
public MessageDbContext(DbContextOptions<MessageDbContext> options) : base(options)
{
}

public DbSet<MessageItem> Items { get; set; }
}
}
Loading

0 comments on commit d8111bb

Please sign in to comment.