mirror of
https://github.com/bitwarden/server.git
synced 2026-02-15 13:23:26 +08:00
refactor api models for other cipher types
This commit is contained in:
39
src/Core/Models/Api/SecureNoteDataModel.cs
Normal file
39
src/Core/Models/Api/SecureNoteDataModel.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class SecureNoteDataModel : CipherDataModel
|
||||
{
|
||||
public SecureNoteDataModel() { }
|
||||
|
||||
public SecureNoteDataModel(CipherRequestModel cipher)
|
||||
{
|
||||
Name = cipher.Name;
|
||||
Notes = cipher.Notes;
|
||||
Fields = cipher.Fields;
|
||||
|
||||
Type = cipher.SecureNote.Type;
|
||||
}
|
||||
|
||||
public SecureNoteDataModel(Cipher cipher)
|
||||
{
|
||||
if(cipher.Type != CipherType.SecureNote)
|
||||
{
|
||||
throw new ArgumentException("Cipher is not correct type.");
|
||||
}
|
||||
|
||||
var data = JsonConvert.DeserializeObject<SecureNoteDataModel>(cipher.Data);
|
||||
|
||||
Name = data.Name;
|
||||
Notes = data.Notes;
|
||||
Fields = data.Fields;
|
||||
|
||||
Type = data.Type;
|
||||
}
|
||||
|
||||
public SecureNoteType Type { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user