85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using Back.Program.Common.Data;
|
|
using Back.Program.Models.Entities;
|
|
using Back.Program.Repositories.V1.Interfaces;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Back.Program.Repositories.V1;
|
|
|
|
public class PushRepository: IPushRepository
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public PushRepository(AppDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
|
|
public async Task<bool> FindAcademy(string bid)
|
|
{
|
|
return await _context.Academy.AnyAsync(a => a.bid == bid);
|
|
}
|
|
|
|
public async Task<List<DBPayload>> FindPushList(string bid, string? pid, string? category)
|
|
{
|
|
var pushQuery = _context.DBPayload.Where(p => p.bid == bid);
|
|
if (pid != null)
|
|
pushQuery = pushQuery.Where(p => p.pid == pid);
|
|
if (category != null)
|
|
pushQuery = pushQuery.Where(p=>p.category == category);
|
|
return await pushQuery.ToListAsync();
|
|
|
|
}
|
|
|
|
public async Task<DBPayload?> FindPushPayload(string bid, string pid)
|
|
{
|
|
return await _context.DBPayload.FirstOrDefaultAsync(p => p.bid == bid && p.pid == pid);
|
|
}
|
|
|
|
public async Task<bool> FindUserAcademy(string uid, string bid)
|
|
{
|
|
return await _context.UserAcademy.AnyAsync(ua => ua.uid == uid && ua.bid == bid);
|
|
}
|
|
|
|
public async Task<int> CountBadge(string uid)
|
|
{
|
|
return await _context.PushCabinet.CountAsync(c => c.uid == uid && c.check_yn == false);
|
|
}
|
|
|
|
public async Task<string?> FindPushToken(string uid)
|
|
{
|
|
return await _context.User
|
|
.Where(u => u.uid == uid)
|
|
.Select(u => u.push_token)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<PushCabinet?> FindPushCabinet(int id)
|
|
{
|
|
return await _context.PushCabinet.FirstOrDefaultAsync(c => c.id == id);
|
|
}
|
|
|
|
public async Task<List<PushCabinet>> FindPushCabinet(string uid, int size)
|
|
{
|
|
return await _context.PushCabinet.Where(c => c.uid == uid)
|
|
.OrderBy(c => c.send_date)
|
|
.Take(size)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<PushCabinet>> FindPushCabinet(int id, int size)
|
|
{
|
|
var sort = await _context.PushCabinet
|
|
.Where(p=> p.id == id)
|
|
.Select(p => p.send_date)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (sort == default) return new List<PushCabinet>();
|
|
|
|
return await _context.PushCabinet
|
|
.Where(c => c.send_date > sort)
|
|
.OrderBy(c => c.send_date)
|
|
.Take(size)
|
|
.ToListAsync();
|
|
}
|
|
} |