Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/nuget/dotnet-reportgenerator-gl…
Browse files Browse the repository at this point in the history
…obaltool-5.1.21
  • Loading branch information
lucasteles authored Dec 26, 2023
2 parents 3addea5 + f20a206 commit 5d2567b
Show file tree
Hide file tree
Showing 27 changed files with 1,157 additions and 2,190 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,37 @@ jobs:
PreReleaseTag: ${{ steps.gitversion.outputs.PreReleaseTag }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
uses: gittools/actions/gitversion/setup@v0.10.2
with:
versionSpec: 5.x
versionSpec: 5.x

- name: Determine Version
uses: gittools/actions/gitversion/execute@v0.9.15
uses: gittools/actions/gitversion/execute@v0.10.2
id: gitversion

- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v2
with:
global-json-file: global.json
global-json-file: global.json

- name: Test
run: dotnet test

- name: Build and Pack NuGet package
run: dotnet pack FSharp.MinimalApi/ --configuration Release --include-symbols -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ./Package
run: |
dotnet pack FSharp.MinimalApi/ --configuration Release --include-symbols -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ./Package
dotnet pack FSharp.MinimalApi.Swagger/ --configuration Release --include-symbols -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ./Package
dotnet pack FSharp.MinimalApi.Interop/ --configuration Release --include-symbols -p:Version='${{ steps.gitversion.outputs.SemVer }}' --output ./Package
- name: Upload lib NuGet package artifact to GitHub
uses: actions/upload-artifact@v2
Expand Down
10 changes: 7 additions & 3 deletions BasicApi/AppDbContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ module private EntityConfig =
user.Property(fun u -> u.Id).HasConversion((fun (UserId id) -> id), UserId)
|> ignore

user
.Property(fun u -> u.Email)
.HasConversion((fun (Email email) -> email), Email)
|> ignore

user.HasData(
{ Id = Guid.NewGuid() |> UserId
Name = "Ryu"
Email = "[email protected]" }
Email = Email "[email protected]" }
)
|> ignore


let blog (builder: ModelBuilder) =
let blog = builder.Entity<Blog>()
blog.HasKey(fun u -> u.Id :> obj) |> ignore
Expand All @@ -41,7 +45,7 @@ module private EntityConfig =
post.HasOne<Blog>().WithMany().HasForeignKey(fun u -> u.BlogId :> obj) |> ignore
post.HasKey(fun u -> u.Id :> obj) |> ignore

type AppDbContext(options) =
type MyDbContext(options) =
inherit DbContext(options)
member this.Users = this.Set<User>()
member this.Posts = this.Set<BlogPost>()
Expand Down
3 changes: 2 additions & 1 deletion BasicApi/BasicApi.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FSharp.MinimalApi.Swagger\FSharp.MinimalApi.Swagger.fsproj" />
<ProjectReference Include="..\FSharp.MinimalApi\FSharp.MinimalApi.fsproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.SystemTextJson" Version="1.1.23" />
<PackageReference Include="FSharp.TypeConverter" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
Expand Down
59 changes: 46 additions & 13 deletions BasicApi/Models.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

open System

type UserId = UserId of Guid
type UnionValue =
| ANumber of int
| AString of string
| Nothing

type UserId =
| UserId of Guid

member this.Value = let (UserId value) = this in value


type Email = Email of string

[<CLIMutable>]
type User =
{ Id: UserId
Name: string
Email: string }
Email: Email }

type BlogId = BlogId of Guid

Expand All @@ -28,18 +39,36 @@ type BlogPost =
BlogId: BlogId }

[<CLIMutable>]
type NewUser =
{ Name: string
Email: string }
type NewUser = { Name: string; Email: string }

static member validate(info: NewUser) =
let problems =
[ nameof info.Email,
[| if String.IsNullOrWhiteSpace info.Email then
"Empty email"
[<CLIMutable>]
type MyCustomSettings =
{ MagicNumber: int option
Enabled: bool
Email: Email }

if not <| info.Email.Contains "@" then
"Invalid email" |]
module Email =
let value (Email email) = email

let create (emailStr: string) =
let errors =
[| if String.IsNullOrWhiteSpace emailStr then
"Empty email"

if not <| emailStr.Contains "@" then
"Invalid email" |]

if errors |> Array.isEmpty then
emailStr.ToLower().Trim() |> Email |> Ok
else
errors |> Error

module NewUser =
let parseUser (info: NewUser) =
let problems =
[ match Email.create info.Email with
| Error errors -> nameof info.Email, errors
| Ok e -> ()

nameof info.Name,
[| if String.IsNullOrWhiteSpace info.Name then
Expand All @@ -50,5 +79,9 @@ type NewUser =
problems
|> List.filter (fun (_, errs) -> errs.Length > 0)
|> function
| [] -> Ok()
| [] ->
{ Id = Guid.NewGuid() |> UserId
Name = info.Name
Email = Email info.Email }
|> Ok
| errors -> errors |> dict |> Error
Loading

0 comments on commit 5d2567b

Please sign in to comment.