mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
// ==========================================================================
|
|
// MongoSchemaRepository_SnapshotStore.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using MongoDB.Driver;
|
|
using Squidex.Domain.Apps.Entities.Schemas.State;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.MongoDb;
|
|
using Squidex.Infrastructure.States;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
|
|
{
|
|
public sealed partial class MongoSchemaRepository : ISnapshotStore<SchemaState, Guid>
|
|
{
|
|
public async Task<(SchemaState Value, long Version)> ReadAsync(Guid key)
|
|
{
|
|
var existing =
|
|
await Collection.Find(x => x.Id == key)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (existing != null)
|
|
{
|
|
return (existing.State, existing.Version);
|
|
}
|
|
|
|
return (null, EtagVersion.NotFound);
|
|
}
|
|
|
|
public Task WriteAsync(Guid key, SchemaState value, long oldVersion, long newVersion)
|
|
{
|
|
return Collection.UpsertVersionedAsync(key, oldVersion, newVersion, u => u
|
|
.Set(x => x.State, value)
|
|
.Set(x => x.AppId, value.AppId)
|
|
.Set(x => x.Name, value.Name)
|
|
.Set(x => x.IsDeleted, value.IsDeleted));
|
|
}
|
|
}
|
|
}
|
|
|