mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 22:35:17 -04:00
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs.Device;
|
||||
using API.Extensions;
|
||||
using API.DTOs.Device.ClientDevice;
|
||||
using API.DTOs.Device.EmailDevice;
|
||||
using API.DTOs.Progress;
|
||||
using API.Services;
|
||||
using API.SignalR;
|
||||
using AutoMapper;
|
||||
using Kavita.Common;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace API.Controllers;
|
||||
@@ -22,20 +26,20 @@ public class DeviceController : BaseApiController
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IDeviceService _deviceService;
|
||||
private readonly IEmailService _emailService;
|
||||
private readonly IEventHub _eventHub;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IClientDeviceService _clientDeviceService;
|
||||
|
||||
public DeviceController(IUnitOfWork unitOfWork, IDeviceService deviceService,
|
||||
IEmailService emailService, IEventHub eventHub, ILocalizationService localizationService, IMapper mapper)
|
||||
public DeviceController(IUnitOfWork unitOfWork, IDeviceService deviceService,IEventHub eventHub,
|
||||
ILocalizationService localizationService, IMapper mapper, IClientDeviceService clientDeviceService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_deviceService = deviceService;
|
||||
_emailService = emailService;
|
||||
_eventHub = eventHub;
|
||||
_localizationService = localizationService;
|
||||
_mapper = mapper;
|
||||
_clientDeviceService = clientDeviceService;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,21 +49,21 @@ public class DeviceController : BaseApiController
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("create")]
|
||||
public async Task<ActionResult<DeviceDto>> CreateOrUpdateDevice(CreateDeviceDto dto)
|
||||
public async Task<ActionResult<EmailDeviceDto>> CreateOrUpdateDevice(CreateEmailDeviceDto dto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Devices);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(Username!, AppUserIncludes.Devices);
|
||||
if (user == null) return Unauthorized();
|
||||
try
|
||||
{
|
||||
var device = await _deviceService.Create(dto, user);
|
||||
if (device == null)
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-device-create"));
|
||||
return BadRequest(await _localizationService.Translate(UserId, "generic-device-create"));
|
||||
|
||||
return Ok(_mapper.Map<DeviceDto>(device));
|
||||
return Ok(_mapper.Map<EmailDeviceDto>(device));
|
||||
}
|
||||
catch (KavitaException ex)
|
||||
{
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), ex.Message));
|
||||
return BadRequest(await _localizationService.Translate(UserId, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,15 +73,15 @@ public class DeviceController : BaseApiController
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("update")]
|
||||
public async Task<ActionResult<DeviceDto>> UpdateDevice(UpdateDeviceDto dto)
|
||||
public async Task<ActionResult<EmailDeviceDto>> UpdateDevice(UpdateEmailDeviceDto dto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Devices);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(Username!, AppUserIncludes.Devices);
|
||||
if (user == null) return Unauthorized();
|
||||
var device = await _deviceService.Update(dto, user);
|
||||
|
||||
if (device == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-device-update"));
|
||||
if (device == null) return BadRequest(await _localizationService.Translate(UserId, "generic-device-update"));
|
||||
|
||||
return Ok(_mapper.Map<DeviceDto>(device));
|
||||
return Ok(_mapper.Map<EmailDeviceDto>(device));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,18 +92,18 @@ public class DeviceController : BaseApiController
|
||||
[HttpDelete]
|
||||
public async Task<ActionResult> DeleteDevice(int deviceId)
|
||||
{
|
||||
if (deviceId <= 0) return BadRequest(await _localizationService.Translate(User.GetUserId(), "device-doesnt-exist"));
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Devices);
|
||||
if (deviceId <= 0) return BadRequest(await _localizationService.Translate(UserId, "device-doesnt-exist"));
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(Username!, AppUserIncludes.Devices);
|
||||
if (user == null) return Unauthorized();
|
||||
if (await _deviceService.Delete(user, deviceId)) return Ok();
|
||||
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-device-delete"));
|
||||
return BadRequest(await _localizationService.Translate(UserId, "generic-device-delete"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<DeviceDto>>> GetDevices()
|
||||
public async Task<ActionResult<IEnumerable<EmailDeviceDto>>> GetDevices()
|
||||
{
|
||||
return Ok(await _unitOfWork.DeviceRepository.GetDevicesForUserAsync(User.GetUserId()));
|
||||
return Ok(await _unitOfWork.DeviceRepository.GetDevicesForUserAsync(UserId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,9 +112,9 @@ public class DeviceController : BaseApiController
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("send-to")]
|
||||
public async Task<ActionResult> SendToDevice(SendToDeviceDto dto)
|
||||
public async Task<ActionResult> SendToDevice(SendToEmailDeviceDto dto)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var userId = UserId;
|
||||
if (dto.ChapterIds.Any(i => i < 0)) return BadRequest(await _localizationService.Translate(userId, "greater-0", "ChapterIds"));
|
||||
if (dto.DeviceId < 0) return BadRequest(await _localizationService.Translate(userId, "greater-0", "DeviceId"));
|
||||
|
||||
@@ -151,9 +155,9 @@ public class DeviceController : BaseApiController
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("send-series-to")]
|
||||
public async Task<ActionResult> SendSeriesToDevice(SendSeriesToDeviceDto dto)
|
||||
public async Task<ActionResult> SendSeriesToDevice(SendSeriesToEmailDeviceDto dto)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var userId = UserId;
|
||||
if (dto.SeriesId <= 0) return BadRequest(await _localizationService.Translate(userId, "greater-0", "SeriesId"));
|
||||
if (dto.DeviceId < 0) return BadRequest(await _localizationService.Translate(userId, "greater-0", "DeviceId"));
|
||||
|
||||
@@ -189,6 +193,58 @@ public class DeviceController : BaseApiController
|
||||
return BadRequest(await _localizationService.Translate(userId, "generic-send-to"));
|
||||
}
|
||||
|
||||
#region Client Devices
|
||||
/// <summary>
|
||||
/// Get my client devices
|
||||
/// </summary>
|
||||
/// <param name="includeInactive"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("client/devices")]
|
||||
public async Task<ActionResult<List<ClientDeviceDto>>> GetMyClientDevices(bool includeInactive = false)
|
||||
{
|
||||
return Ok(await _clientDeviceService.GetUserDeviceDtosAsync(UserId, includeInactive));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get All user client devices
|
||||
/// </summary>
|
||||
/// <param name="includeInactive"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("client/all-devices")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
public async Task<ActionResult<List<ClientDeviceDto>>> GetAllClientDevices(bool includeInactive = false)
|
||||
{
|
||||
return Ok(await _clientDeviceService.GetAllUserDeviceDtos(includeInactive));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Removes the client device from DB
|
||||
/// </summary>
|
||||
/// <param name="clientDeviceId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("client/device")]
|
||||
public async Task<ActionResult<bool>> DeleteClientDevice(int clientDeviceId)
|
||||
{
|
||||
return Ok(await _clientDeviceService.DeleteDeviceAsync(UserId, clientDeviceId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the friendly name of the Device
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("client/update-name")]
|
||||
public async Task<ActionResult> UpdateClientDeviceName(UpdateClientDeviceNameDto dto)
|
||||
{
|
||||
await _clientDeviceService.UpdateFriendlyNameAsync(UserId, dto);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion Client Devices
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user