Skip to content

Commit

Permalink
update resource changes to use either Edit or Create change where rel…
Browse files Browse the repository at this point in the history
…evant. Update db model snapshot test
  • Loading branch information
hahn-kev committed Jun 5, 2024
1 parent 911149e commit e7b004c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
34 changes: 34 additions & 0 deletions src/Crdt.Tests/DbContextTests.VerifyModel.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,40 @@
Relational:TableName: Snapshots
Relational:ViewName:
Relational:ViewSchema:
EntityType: LocalResource
Properties:
Id (Guid) Required PK AfterSave:Throw ValueGenerated.OnAdd
LocalPath (string) Required
Keys:
Id PK
Annotations:
DiscriminatorProperty:
Relational:FunctionName:
Relational:Schema:
Relational:SqlQuery:
Relational:TableName: LocalResource
Relational:ViewName:
Relational:ViewSchema:
EntityType: RemoteResource
Properties:
Id (Guid) Required PK AfterSave:Throw ValueGenerated.OnAdd
DeletedAt (DateTimeOffset?)
RemoteId (string)
SnapshotId (no field, Guid?) Shadow FK Index
Keys:
Id PK
Foreign keys:
RemoteResource {'SnapshotId'} -> ObjectSnapshot {'Id'} Unique SetNull
Indexes:
SnapshotId Unique
Annotations:
DiscriminatorProperty:
Relational:FunctionName:
Relational:Schema:
Relational:SqlQuery:
Relational:TableName: RemoteResource
Relational:ViewName:
Relational:ViewSchema:
EntityType: Definition
Properties:
Id (Guid) Required PK AfterSave:Throw ValueGenerated.OnAdd
Expand Down
15 changes: 4 additions & 11 deletions src/Crdt/Resource/CreateRemoteResourceChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@

namespace Crdt.Resource;

public class CreateRemoteResourceChange(Guid resourceId, string remoteId) : Change<RemoteResource>(resourceId), IPolyType
public class CreateRemoteResourceChange(Guid resourceId, string remoteId) : CreateChange<RemoteResource>(resourceId), IPolyType
{
public string RemoteId { get; set; } = remoteId;

public override IObjectBase NewEntity(Commit commit)
public override ValueTask<IObjectBase> NewEntity(Commit commit, ChangeContext context)
{
return new RemoteResource
return ValueTask.FromResult<IObjectBase>(new RemoteResource
{
Id = EntityId,
RemoteId = RemoteId
};
}

public override ValueTask ApplyChange(RemoteResource entity, ChangeContext context)
{
entity.RemoteId = RemoteId;
return ValueTask.CompletedTask;
});
}

public static string TypeName => "create:remote-resource";
Expand Down
13 changes: 4 additions & 9 deletions src/Crdt/Resource/CreateRemoteResourcePendingUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@

namespace Crdt.Resource;

public class CreateRemoteResourcePendingUploadChange: Change<RemoteResource>, IPolyType
public class CreateRemoteResourcePendingUploadChange: CreateChange<RemoteResource>, IPolyType
{
public CreateRemoteResourcePendingUploadChange(Guid resourceId) : base(resourceId)
{
}

public override IObjectBase NewEntity(Commit commit)
public override ValueTask<IObjectBase> NewEntity(Commit commit, ChangeContext context)
{
return new RemoteResource
return ValueTask.FromResult<IObjectBase>(new RemoteResource
{
Id = EntityId
};
}

public override ValueTask ApplyChange(RemoteResource entity, ChangeContext context)
{
return ValueTask.CompletedTask;
});
}

public static string TypeName => "create:pendingUpload";
Expand Down
11 changes: 1 addition & 10 deletions src/Crdt/Resource/RemoteResourceUploadedChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@ namespace Crdt.Resource;
/// </summary>
/// <param name="entityId"></param>
/// <param name="remoteId"></param>
public class RemoteResourceUploadedChange(Guid entityId, string remoteId) : Change<RemoteResource>(entityId), IPolyType
public class RemoteResourceUploadedChange(Guid entityId, string remoteId) : EditChange<RemoteResource>(entityId), IPolyType
{
public string RemoteId { get; set; } = remoteId;
public static string TypeName => "uploaded:RemoteResource";

public override IObjectBase NewEntity(Commit commit)
{
return new RemoteResource
{
Id = EntityId,
RemoteId = RemoteId
};
}

public override ValueTask ApplyChange(RemoteResource entity, ChangeContext context)
{
entity.RemoteId = RemoteId;
Expand Down

0 comments on commit e7b004c

Please sign in to comment.