using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Newtonsoft.Json; using ServerCore; using ServerBase; namespace ServerCommon; public class BuildingRentalHistoryAttrib : AttribBase { [JsonProperty] public int BuildingMetaId { get; set; } [JsonProperty("floor")] public int Floor { get; set; } = 0; [JsonProperty("rentee_user_guid")] public string RenteeUserGuid { get; set; } = string.Empty; [JsonProperty("rental_time")] public DateTime RentalTime { get; set; } = new(); [JsonProperty("rental_period")] public int RentalPeriod { get; set; } = 0; public BuildingRentalHistoryAttrib() : base(typeof(BuildingRentalHistoryAttrib).Name, false) { } } //============================================================================================= // PK(Partition Key) : "building#building_meta_id" // SK(Sort Key) : "rental_history#timestamp" // DocType : BuildingRentalHistoryDoc // BuildingAttrib : {} // ... //============================================================================================= public class BuildingRentalHistoryDoc : DynamoDbDocBase { private static string getPrefixOfPK() { return "building#"; } public static string getPrefixOfSK() { return "rental_history#"; } public BuildingRentalHistoryDoc() : base(typeof(BuildingRentalHistoryAttrib).Name) { appendAttribWrapperAll(); } public BuildingRentalHistoryDoc(int buildingMetaId, Timestamp timestamp) : base(typeof(BuildingRentalHistoryAttrib).Name) { setCombinationKeyForPK(buildingMetaId.ToString()); setCombinationKeyForSK(timestamp.ToString()); appendAttribWrapperAll(); fillUpPrimaryKey(onMakePK(), onMakeSK()); } private void appendAttribWrapperAll() { appendAttribWrapper(new AttribWrapper()); } protected override string onGetPrefixOfPK() { return getPrefixOfPK(); } protected override string onGetPrefixOfSK() { return getPrefixOfSK(); } protected override string onMakeSK() { return $"{onGetPrefixOfSK()}{getCombinationKeyForSK()}"; } protected override ServerErrorCode onCheckAndSetSK(string sortKey) { getPrimaryKey().fillUpSK(sortKey); return ServerErrorCode.Success; } }