-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
72 additions
and
15 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 |
---|---|---|
@@ -1,12 +1,32 @@ | ||
module Emulsion.ContentProxy.ContentStorage | ||
|
||
open Emulsion.Database | ||
open Emulsion.Database.DataStorage | ||
open Emulsion.Database.Models | ||
open Emulsion.Database.QueryableEx | ||
|
||
type MessageIdentity = { | ||
ChatUserName: string | ||
MessageId: int64 | ||
FileId: string | ||
} | ||
|
||
let getOrCreateMessageRecord (context: EmulsionDbContext) (id: MessageIdentity): Async<TelegramContent> = | ||
failwithf "TODO" | ||
let getOrCreateMessageRecord (context: EmulsionDbContext) (id: MessageIdentity): Async<TelegramContent> = async { | ||
let! existingItem = | ||
query { | ||
for content in context.TelegramContents do | ||
where (content.MessageId = id.MessageId && content.FileId = id.FileId) | ||
tryExactlyOneAsync | ||
} | ||
match existingItem with | ||
| None -> | ||
let newItem = { | ||
Id = 0L | ||
ChatUsername = id.ChatUserName | ||
MessageId = id.MessageId | ||
FileId = id.FileId | ||
} | ||
do! addAsync context.TelegramContents newItem | ||
return newItem | ||
| Some item -> return item | ||
} |
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
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
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
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
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,19 @@ | ||
module Emulsion.Database.QueryableEx | ||
|
||
open System.Linq | ||
|
||
open Microsoft.EntityFrameworkCore | ||
open Microsoft.FSharp.Linq | ||
|
||
type QueryBuilder with | ||
[<CustomOperation("tryExactlyOneAsync")>] | ||
member _.TryExactlyOneAsync<'T, 'Q>(source: QuerySource<'T, 'Q>): Async<'T option> = async { | ||
let source = source.Source :?> IQueryable<'T> | ||
let! ct = Async.CancellationToken | ||
let! item = Async.AwaitTask(EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(source, ct)) | ||
|
||
// We cannot use Option.ofObj here since not every entity type can be marked with AllowNullLiteral. | ||
match box item with | ||
| null -> return None | ||
| _ -> return Some item | ||
} |
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 @@ | ||
module Emulsion.Tests.ContentProxy.ContentStorageTests | ||
|
||
open Xunit | ||
|
||
[<Fact>] | ||
let ``getOrCreateMessageRecord returns a new record``() = | ||
Assert.True false | ||
|
||
[<Fact>] | ||
let ``getOrCreateMessageRecord returns an existing record``() = | ||
Assert.True false |
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
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