62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Options;
|
|
using MongoDB.Driver;
|
|
using SharpCompress.Common;
|
|
using UGQDatabase.Models;
|
|
using UGQDataAccess.Settings;
|
|
using ServerCommon.UGQ;
|
|
|
|
namespace UGQDataAccess.Repository;
|
|
|
|
public class QuestAbortedRepository : BaseRepository<QuestAbortedEntity>
|
|
{
|
|
private const string CollectionName = "QuestAborted";
|
|
|
|
public QuestAbortedRepository(IMongoClient mongoClient, IOptions<UGQDatabaseSettings> settings) :
|
|
base(mongoClient, settings.Value.DatabaseName, CollectionName)
|
|
{
|
|
}
|
|
|
|
public async Task<List<QuestAbortedEntity>> getAll()
|
|
{
|
|
return await Collection.Find(Builders<QuestAbortedEntity>.Filter.Empty).ToListAsync();
|
|
}
|
|
|
|
public async Task<ServerErrorCode> insert(long questId, long revision, string author, UGQAbortReason reason, string userGuid)
|
|
{
|
|
var entity = new QuestAbortedEntity
|
|
{
|
|
QuestId = questId,
|
|
Revision = revision,
|
|
Author = author,
|
|
UserGuid = userGuid,
|
|
Reason = reason,
|
|
CreatedAt = DateTime.UtcNow,
|
|
};
|
|
|
|
await Collection.InsertOneAsync(entity);
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
public async Task<QuestAbortedEntity?> setAuthor(string id, string author)
|
|
{
|
|
var filterBuilder = Builders<QuestAbortedEntity>.Filter;
|
|
|
|
var filter = filterBuilder.Eq(x => x.Id, id);
|
|
|
|
var update = Builders<QuestAbortedEntity>.Update
|
|
.Set(x => x.Author, author);
|
|
|
|
var options = new FindOneAndUpdateOptions<QuestAbortedEntity>
|
|
{
|
|
ReturnDocument = ReturnDocument.After,
|
|
};
|
|
|
|
return await Collection.FindOneAndUpdateAsync(filter, update, options);
|
|
}
|
|
}
|