1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-22 21:51:22 +01:00

sync API to get all info in 1 call

This commit is contained in:
Kyle Spearrin 2017-09-20 12:00:33 -04:00
parent 327e192258
commit 3fdf2eb4ad
2 changed files with 80 additions and 0 deletions

View 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;
}
}
}

View 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; }
}
}