49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using Back.Program.Common.Data;
|
|
using Back.Program.Common.Model;
|
|
using Back.Program.Models.Entities;
|
|
using Back.Program.Repositories.V1.Interfaces;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Back.Program.Repositories.V1
|
|
{
|
|
public class UserRepository: IUserRepository
|
|
{
|
|
private readonly ILogger<UserRepository> _logger;
|
|
private readonly AppDbContext _context;
|
|
|
|
public UserRepository(ILogger<UserRepository> logger,AppDbContext context) {
|
|
_logger = logger;
|
|
_context = context;
|
|
}
|
|
|
|
public Task<Login?> FindLogin(string accType, string snsId)
|
|
{
|
|
return _context.Login.FirstOrDefaultAsync(l => l.sns_type == accType && l.sns_id == snsId);
|
|
}
|
|
|
|
public Task<User?> FindUser(string uid)
|
|
{
|
|
return _context.User.FirstOrDefaultAsync(u => u.uid == uid);
|
|
}
|
|
|
|
public Task<RefreshToken?> FindRefreshToken(string uid)
|
|
{
|
|
return _context.RefreshToken.FirstOrDefaultAsync(r => r.uid == uid);
|
|
}
|
|
|
|
public Task<List<AcademyName>> FindAcademies(string uid)
|
|
{
|
|
var academyList = _context.UserAcademy
|
|
.Join(_context.Academy, ua => ua.uid, a => a.uid, (ua, a) => new { ua, a })
|
|
.Where(s => s.ua.uid == uid)
|
|
.Select(s => new AcademyName { bid = s.a.bid, name = s.a.business_name })
|
|
.ToListAsync();
|
|
return academyList;
|
|
}
|
|
|
|
public async Task<bool> SaveChanges()
|
|
{
|
|
return await _context.SaveChangesAsync() > 0;
|
|
}
|
|
}
|
|
} |