mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 14:38:15 -05:00
sync API to get all info in 1 call
This commit is contained in:
parent
327e192258
commit
3fdf2eb4ad
49
src/Api/Controllers/SyncController.cs
Normal file
49
src/Api/Controllers/SyncController.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Bit.Core.Models.Api;
|
||||||
|
using Bit.Core.Services;
|
||||||
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core;
|
||||||
|
using Bit.Core.Enums;
|
||||||
|
|
||||||
|
namespace Bit.Api.Controllers
|
||||||
|
{
|
||||||
|
[Route("sync")]
|
||||||
|
[Authorize("Application")]
|
||||||
|
public class SyncController : Controller
|
||||||
|
{
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
private readonly IFolderRepository _folderRepository;
|
||||||
|
private readonly ICipherRepository _cipherRepository;
|
||||||
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
|
public SyncController(
|
||||||
|
IUserService userService,
|
||||||
|
IFolderRepository folderRepository,
|
||||||
|
ICipherRepository cipherRepository,
|
||||||
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
|
GlobalSettings globalSettings)
|
||||||
|
{
|
||||||
|
_userService = userService;
|
||||||
|
_folderRepository = folderRepository;
|
||||||
|
_cipherRepository = cipherRepository;
|
||||||
|
_organizationUserRepository = organizationUserRepository;
|
||||||
|
_globalSettings = globalSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("")]
|
||||||
|
public async Task<SyncResponseModel> Get()
|
||||||
|
{
|
||||||
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||||
|
var organizationUserDetails = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id,
|
||||||
|
OrganizationUserStatusType.Confirmed);
|
||||||
|
var folders = await _folderRepository.GetManyByUserIdAsync(user.Id);
|
||||||
|
var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id);
|
||||||
|
var response = new SyncResponseModel(_globalSettings, user, organizationUserDetails, folders, ciphers);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
src/Core/Models/Api/Response/SyncResponseModel.cs
Normal file
31
src/Core/Models/Api/Response/SyncResponseModel.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Bit.Core.Models.Data;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using Core.Models.Data;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api
|
||||||
|
{
|
||||||
|
public class SyncResponseModel : ResponseModel
|
||||||
|
{
|
||||||
|
public SyncResponseModel(
|
||||||
|
GlobalSettings globalSettings,
|
||||||
|
User user,
|
||||||
|
IEnumerable<OrganizationUserOrganizationDetails> organizationUserDetails,
|
||||||
|
IEnumerable<Folder> folders,
|
||||||
|
IEnumerable<CipherDetails> ciphers)
|
||||||
|
: base("sync")
|
||||||
|
{
|
||||||
|
Profile = new ProfileResponseModel(user, organizationUserDetails);
|
||||||
|
Folders = folders.Select(f => new FolderResponseModel(f));
|
||||||
|
Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings));
|
||||||
|
Domains = new DomainsResponseModel(user, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProfileResponseModel Profile { get; set; }
|
||||||
|
public IEnumerable<FolderResponseModel> Folders { get; set; }
|
||||||
|
public IEnumerable<CipherResponseModel> Ciphers { get; set; }
|
||||||
|
public DomainsResponseModel Domains { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user