mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
Folder APIs to new tables
This commit is contained in:
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class FolderDataModel
|
||||
{
|
||||
public FolderDataModel() { }
|
||||
|
||||
public FolderDataModel(FolderRequestModel folder)
|
||||
{
|
||||
Name = folder.Name;
|
||||
}
|
||||
|
||||
public FolderDataModel(CipherRequestModel cipher)
|
||||
{
|
||||
Name = cipher.Name;
|
||||
}
|
||||
|
||||
public FolderDataModel(Cipher cipher)
|
||||
{
|
||||
if(cipher.Type != Core.Enums.CipherType.Folder)
|
||||
{
|
||||
throw new ArgumentException("Cipher is not correct type.");
|
||||
}
|
||||
|
||||
var data = JsonConvert.DeserializeObject<FolderDataModel>(cipher.Data);
|
||||
|
||||
Name = data.Name;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -13,19 +13,17 @@ namespace Bit.Core.Models.Api
|
||||
[StringLength(300)]
|
||||
public string Name { get; set; }
|
||||
|
||||
public Cipher ToCipher(Guid userId)
|
||||
public Folder ToFolder(Guid userId)
|
||||
{
|
||||
return ToCipher(new Cipher
|
||||
return ToFolder(new Folder
|
||||
{
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
|
||||
public Cipher ToCipher(Cipher existingFolder)
|
||||
public Folder ToFolder(Folder existingFolder)
|
||||
{
|
||||
existingFolder.Data = JsonConvert.SerializeObject(new FolderDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
existingFolder.Type = Core.Enums.CipherType.Folder;
|
||||
|
||||
existingFolder.Name = Name;
|
||||
return existingFolder;
|
||||
}
|
||||
}
|
||||
|
@ -5,24 +5,17 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class FolderResponseModel : ResponseModel
|
||||
{
|
||||
public FolderResponseModel(Cipher cipher, Guid userId)
|
||||
public FolderResponseModel(Folder folder)
|
||||
: base("folder")
|
||||
{
|
||||
if(cipher == null)
|
||||
if(folder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipher));
|
||||
throw new ArgumentNullException(nameof(folder));
|
||||
}
|
||||
|
||||
if(cipher.Type != Core.Enums.CipherType.Folder)
|
||||
{
|
||||
throw new ArgumentException(nameof(cipher.Type));
|
||||
}
|
||||
|
||||
var data = new FolderDataModel(cipher);
|
||||
|
||||
Id = cipher.Id.ToString();
|
||||
Name = data.Name;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
Id = folder.Id.ToString();
|
||||
Name = folder.Name;
|
||||
RevisionDate = folder.RevisionDate;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
|
Reference in New Issue
Block a user