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