초기커밋
This commit is contained in:
67
UGQDataAccess/Repository/LikeRepository.cs
Normal file
67
UGQDataAccess/Repository/LikeRepository.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
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 LikeRepository : BaseRepository<LikeEntity>
|
||||
{
|
||||
private const string CollectionName = "Like";
|
||||
|
||||
public LikeRepository(IMongoClient mongoClient, IOptions<UGQDatabaseSettings> settings) :
|
||||
base(mongoClient, settings.Value.DatabaseName, CollectionName)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<LikeEntity?> get(long questId, string userGuid)
|
||||
{
|
||||
var builder = Builders<LikeEntity>.Filter;
|
||||
var filter = builder.Eq(x => x.QuestId, questId) &
|
||||
builder.Eq(x => x.UserGuid, userGuid);
|
||||
|
||||
LikeEntity? entity = await (await Collection.FindAsync(filter)).FirstOrDefaultAsync();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<ServerErrorCode> insert(long questId, long revision, string userGuid)
|
||||
{
|
||||
var builder = Builders<LikeEntity>.Filter;
|
||||
var filter = builder.Eq(x => x.QuestId, questId) &
|
||||
builder.Eq(x => x.UserGuid, userGuid);
|
||||
|
||||
var update = Builders<LikeEntity>.Update
|
||||
.SetOnInsert(x => x.QuestId, questId)
|
||||
.SetOnInsert(x => x.UserGuid, userGuid)
|
||||
.SetOnInsert(x => x.CreatedAt, DateTime.UtcNow);
|
||||
|
||||
var option = new UpdateOptions
|
||||
{
|
||||
IsUpsert = true,
|
||||
};
|
||||
|
||||
var result = await Collection.UpdateOneAsync(filter, update, option);
|
||||
return ServerErrorCode.Success;
|
||||
}
|
||||
|
||||
public async Task<ServerErrorCode> delete(long questId, long revision, string userGuid)
|
||||
{
|
||||
var builder = Builders<LikeEntity>.Filter;
|
||||
var filter = builder.Eq(x => x.QuestId, questId) &
|
||||
builder.Eq(x => x.UserGuid, userGuid);
|
||||
|
||||
var result = await Collection.DeleteOneAsync(filter);
|
||||
if (result.DeletedCount == 0)
|
||||
return ServerErrorCode.UgqNullEntity;
|
||||
|
||||
return ServerErrorCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user