-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Device model with MyThing model
The commit represents a significant refactoring in favor of an abstracted 'MyThing' model replacing the previous 'Device' model. All instances and usages of 'Device' have been removed and replaced with 'MyThing', going as far as to change endpoint routes and update tests to match the changes. Events and handlers have also been updated to match MyThing's functionality.
- Loading branch information
Showing
5 changed files
with
130 additions
and
78 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
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
using Marten; | ||
|
||
namespace SimpleWebApi8; | ||
|
||
public static class ThingHandlers | ||
{ | ||
public static async Task<MyThing?> CreateMyThing(DocumentStore store) | ||
{ | ||
var thingId = Guid.NewGuid(); | ||
|
||
await using var session = store.LightweightSession(); | ||
var myThingInitialized = new MyThingInitialized | ||
{ | ||
Name = "My Thing", | ||
Description = "This is my thing", | ||
Tags = ["tag1", "tag2"], | ||
Picture = [], // replace with your picture bytes | ||
Place = "My place" | ||
}; | ||
|
||
session.Events.StartStream<MyThing>(thingId, myThingInitialized); | ||
await session.SaveChangesAsync(); | ||
|
||
return session.Events.AggregateStream<MyThing>(thingId); | ||
} | ||
|
||
public static async Task<MyThing?> GetMyThingById(Guid myThingId, DocumentStore store) | ||
{ | ||
await using var session = store.LightweightSession(); | ||
return session.Events.AggregateStream<MyThing>(myThingId); | ||
} | ||
} |