From 4abe7718eb0a3e117c06b1cabd1977b53f4ca259 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Sat, 8 Oct 2022 23:38:51 +0200 Subject: [PATCH] (feature): user collection init --- db/DML/user.json | 61 +++++++++++++++++++++ webapi/Core/DomainObjects/Contact.cs | 16 +++--- webapi/Core/DomainObjects/Documents/User.cs | 26 ++++----- webapi/Core/DomainObjects/Passwords.cs | 25 +++++++++ webapi/Core/Enumerations/ContactTypes.cs | 11 ++++ webapi/DataProviders/Mappings.cs | 10 ++++ 6 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 db/DML/user.json create mode 100644 webapi/Core/DomainObjects/Passwords.cs create mode 100644 webapi/Core/Enumerations/ContactTypes.cs diff --git a/db/DML/user.json b/db/DML/user.json new file mode 100644 index 0000000..e67c98e --- /dev/null +++ b/db/DML/user.json @@ -0,0 +1,61 @@ +[ + { + "_id": "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60", + "sites": [ + "404c8232-9048-4519-bfba-6e78dc7005ca" + ], + "created": { + "$date": "2022-01-01T00:00:00.000Z" + }, + "nickaName": "hailstrike", + "passwords": { + "pwHash": "", + "pwSalt": "", + "created": { + "$date": "2022-01-01T00:00:00.000Z" + }, + "expiration": { + "$date": "2023-01-01T00:00:00.000Z" + }, + "expired": [ + { + "pwHash": "", + "pwSalt": "", + "created": { + "$date": "2022-01-01T00:00:00.000Z" + }, + "expiration": { + "$date": "2023-01-01T00:00:00.000Z" + } + } + ] + }, + "name": "John", + "lastName": "Doe", + "contacts": [ + { + "type": 0, + "value": "john.doe@maks-it.com", + "confirmed": false + }, + { + "type": 1, + "value": "+39000000", + "confirmed": false + } + ], + "tokens": [], + "billingAddress": { + "street": "", + "city": "", + "postCode": "", + "country": "" + }, + "shippingAddress": { + "street": "", + "city": "", + "postCode": "", + "country": "" + } + } +] diff --git a/webapi/Core/DomainObjects/Contact.cs b/webapi/Core/DomainObjects/Contact.cs index dbfdc66..e9f7827 100644 --- a/webapi/Core/DomainObjects/Contact.cs +++ b/webapi/Core/DomainObjects/Contact.cs @@ -1,12 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Core.Abstractions.DomainObjects; +using Core.Enumerations; namespace Core.DomainObjects { - public class Contact { + public class Contact : DomainObjectBase { + public ContactTypes ContactType { get; set; } public string Value { get; set; } - public bool IsConfirmed { get; set; } + public bool Confirmed { get; set; } + + public override int GetHashCode() { + throw new NotImplementedException(); + } } } diff --git a/webapi/Core/DomainObjects/Documents/User.cs b/webapi/Core/DomainObjects/Documents/User.cs index f260d81..94b55f8 100644 --- a/webapi/Core/DomainObjects/Documents/User.cs +++ b/webapi/Core/DomainObjects/Documents/User.cs @@ -1,31 +1,27 @@ -using Core.Abstractions; -using Core.Abstractions.DomainObjects; -using Core.DomainObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Core.Abstractions.DomainObjects; namespace Core.DomainObjects { - public class User : DomainObjectDocumentBase { + + public List Sites { get; set; } + + public DateTime Created { get; set; } + public string NickName { get; set; } - public string Hash { get; set; } - public string Salt { get; set; } + public Passwords Passwords { get; set; } public string Name { get; set; } public string LastName { get; set; } - public Contact Email { get; set; } - public Contact Mobile { get; set; } - + public List Contacts { get; set; } + public Address BillingAddress { get; set; } + public Address ShippingAddress { get; set; } - // manage whitelisted tokens as salted hash + public List Tokens { get; set; } public override int GetHashCode() { throw new NotImplementedException(); diff --git a/webapi/Core/DomainObjects/Passwords.cs b/webapi/Core/DomainObjects/Passwords.cs new file mode 100644 index 0000000..96248ae --- /dev/null +++ b/webapi/Core/DomainObjects/Passwords.cs @@ -0,0 +1,25 @@ +using Core.Abstractions.DomainObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Core.DomainObjects { + public class Passwords : DomainObjectBase { + + public string PwHash { get; set; } + + public string PwSalt { get; set; } + + public DateTime Created { get; set; } + + public DateTime? Expiration { get; set; } + + public List Expired { get; set; } + + public override int GetHashCode() { + throw new NotImplementedException(); + } + } +} diff --git a/webapi/Core/Enumerations/ContactTypes.cs b/webapi/Core/Enumerations/ContactTypes.cs new file mode 100644 index 0000000..549ea52 --- /dev/null +++ b/webapi/Core/Enumerations/ContactTypes.cs @@ -0,0 +1,11 @@ +using Core.Abstractions; + +namespace Core.Enumerations { + public class ContactTypes : Enumeration { + + public static ContactTypes Email = new(0, "email"); + public static ContactTypes Mobile = new(1, "mobile"); + + private ContactTypes(int id, string displayName) : base (id, displayName) {} + } +} diff --git a/webapi/DataProviders/Mappings.cs b/webapi/DataProviders/Mappings.cs index d5f097d..28794d8 100644 --- a/webapi/DataProviders/Mappings.cs +++ b/webapi/DataProviders/Mappings.cs @@ -86,6 +86,9 @@ namespace DataProviders { if (!BsonClassMap.IsClassMapRegistered(typeof(Contact))) { BsonClassMap.RegisterClassMap(cm => { cm.AutoMap(); + + cm.GetMemberMap(c => c.ContactType) + .SetSerializer(new EnumerationSerializer()); }); } @@ -140,6 +143,13 @@ namespace DataProviders { }); } + if (!BsonClassMap.IsClassMapRegistered(typeof(Passwords))) { + BsonClassMap.RegisterClassMap(cm => { + cm.AutoMap(); + }); + } + + if (!BsonClassMap.IsClassMapRegistered(typeof(Route))) { BsonClassMap.RegisterClassMap(cm => { cm.AutoMap();