-
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example odata API to recreate #3198
- Loading branch information
1 parent
d1b9e68
commit 47b8f18
Showing
9 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,30 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/azds.yaml | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md | ||
!**/.gitignore | ||
!.git/HEAD | ||
!.git/config | ||
!.git/packed-refs | ||
!.git/refs/heads/** |
This file contains 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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.2.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Marten\Marten.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
17 changes: 17 additions & 0 deletions
17
src/AspNetODataWithMarten/Controllers/WeatherForecastController.cs
This file contains 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,17 @@ | ||
using Marten; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OData.Query; | ||
using Microsoft.AspNetCore.OData.Routing.Controllers; | ||
|
||
namespace AspNetODataWithMarten.Controllers; | ||
|
||
[Route("/weatherforecast")] | ||
public class WeatherForecastController : ODataController | ||
{ | ||
[HttpGet] | ||
[EnableQuery] | ||
public IActionResult Get([FromServices] IDocumentSession session ) | ||
{ | ||
return Ok(session.Query<WeatherForecast>()); | ||
} | ||
} |
This file contains 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,24 @@ | ||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||
USER app | ||
WORKDIR /app | ||
EXPOSE 5045 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
ARG BUILD_CONFIGURATION=Release | ||
WORKDIR /src | ||
COPY ["AspNetODataWithMarten/AspNetODataWithMarten.csproj", "AspNetODataWithMarten/"] | ||
RUN dotnet restore "./AspNetODataWithMarten/AspNetODataWithMarten.csproj" | ||
COPY . . | ||
WORKDIR "/src/AspNetODataWithMarten" | ||
RUN dotnet build "./AspNetODataWithMarten.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
||
FROM build AS publish | ||
ARG BUILD_CONFIGURATION=Release | ||
RUN dotnet publish "./AspNetODataWithMarten.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "AspNetODataWithMarten.dll"] |
This file contains 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,38 @@ | ||
using Marten; | ||
using Microsoft.AspNetCore.OData; | ||
using Microsoft.OData.ModelBuilder; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddMarten((options) => | ||
{ | ||
options.Connection(Environment.GetEnvironmentVariable("POSTGRES_CONNECTION_STRING")); | ||
options.RegisterDocumentType<WeatherForecast>(); | ||
options.DatabaseSchemaName = "public"; | ||
}); | ||
|
||
builder.Services.AddControllers().AddOData(options => | ||
{ | ||
var entityBuilder = new ODataModelBuilder(); | ||
|
||
entityBuilder.EntityType<WeatherForecast>().HasKey(t => t.Id); | ||
entityBuilder.EntitySet<WeatherForecast>("WeatherForecast"); | ||
|
||
options.EnableQueryFeatures().AddRouteComponents("odata", entityBuilder.GetEdmModel()); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); | ||
|
||
public record WeatherForecast() | ||
{ | ||
public Guid Id { get; init; } | ||
public DateOnly Date { get; init; } | ||
public int Temperature { get; init; } | ||
public string? Summary { get; init; } | ||
public decimal? Humidity { get; init; } | ||
} |
This file contains 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,14 @@ | ||
{ | ||
"profiles": { | ||
"Container (Dockerfile)": { | ||
"commandName": "Docker", | ||
"launchBrowser": fa, | ||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", | ||
"environmentVariables": { | ||
"ASPNETCORE_HTTP_PORTS": "8080" | ||
}, | ||
"publishAllPorts": true | ||
} | ||
}, | ||
"$schema": "http://json.schemastore.org/launchsettings.json" | ||
} |
This file contains 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,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectVersion>2.1</ProjectVersion> | ||
<DockerTargetOS>Linux</DockerTargetOS> | ||
<DockerPublishLocally>False</DockerPublishLocally> | ||
<ProjectGuid>0f9f373e-a47a-4028-aaeb-04e2fe4e7f24</ProjectGuid> | ||
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction> | ||
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/weatherforecast</DockerServiceUrl> | ||
<DockerServiceName>aspnetodatawithmarten</DockerServiceName> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="docker-compose.yml" /> | ||
<None Include=".dockerignore" /> | ||
</ItemGroup> | ||
</Project> |
This file contains 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,23 @@ | ||
version: '3.4' | ||
|
||
services: | ||
aspnetodatawithmarten: | ||
build: | ||
context: . | ||
dockerfile: AspNetODataWithMarten/Dockerfile | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
ASPNETCORE_ENVIRONMENT: "Development" | ||
ASPNETCORE_HTTP_PORTS: 8080 | ||
POSTGRES_CONNECTION_STRING: "Host=postgres;Port=5432;Database=weatherforecast;Username=postgres;password=Password123!" | ||
depends_on: | ||
- postgres | ||
|
||
postgres: | ||
image: postgres | ||
environment: | ||
POSTGRES_DB: "weatherforecast" | ||
POSTGRES_PASSWORD: "Password123!" | ||
ports: | ||
- "5432:5432" |
This file contains 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,11 @@ | ||
{ | ||
"profiles": { | ||
"Docker Compose": { | ||
"commandName": "DockerCompose", | ||
"commandVersion": "1.0", | ||
"serviceActions": { | ||
"aspnetodatawithmarten": "StartDebugging" | ||
} | ||
} | ||
} | ||
} |