초기커밋
This commit is contained in:
61
UGQDataAccess/Repository/QuestAcceptedRepository.cs
Normal file
61
UGQDataAccess/Repository/QuestAcceptedRepository.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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 QuestAcceptedRepository : BaseRepository<QuestAcceptedEntity>
|
||||
{
|
||||
private const string CollectionName = "QuestAccepted";
|
||||
|
||||
public QuestAcceptedRepository(IMongoClient mongoClient, IOptions<UGQDatabaseSettings> settings) :
|
||||
base(mongoClient, settings.Value.DatabaseName, CollectionName)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<QuestAcceptedEntity>> getAll()
|
||||
{
|
||||
return await Collection.Find(Builders<QuestAcceptedEntity>.Filter.Empty).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ServerErrorCode> insert(long questId, long revision, string author, UGQAcceptReason reason, string userGuid)
|
||||
{
|
||||
var entity = new QuestAcceptedEntity
|
||||
{
|
||||
QuestId = questId,
|
||||
Revision = revision,
|
||||
Author = author,
|
||||
UserGuid = userGuid,
|
||||
Reason = reason,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
await Collection.InsertOneAsync(entity);
|
||||
return ServerErrorCode.Success;
|
||||
}
|
||||
|
||||
public async Task<QuestAcceptedEntity?> setAuthor(string id, string author)
|
||||
{
|
||||
var filterBuilder = Builders<QuestAcceptedEntity>.Filter;
|
||||
|
||||
var filter = filterBuilder.Eq(x => x.Id, id);
|
||||
|
||||
var update = Builders<QuestAcceptedEntity>.Update
|
||||
.Set(x => x.Author, author);
|
||||
|
||||
var options = new FindOneAndUpdateOptions<QuestAcceptedEntity>
|
||||
{
|
||||
ReturnDocument = ReturnDocument.After,
|
||||
};
|
||||
|
||||
return await Collection.FindOneAndUpdateAsync(filter, update, options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user