Skip to content

Commit

Permalink
Refactor Entitys
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Mar 14, 2023
1 parent 11966ae commit 1b20480
Show file tree
Hide file tree
Showing 44 changed files with 2,333 additions and 643 deletions.
10 changes: 5 additions & 5 deletions Endpoint/AbstractEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal async Task<T[]> GetCollection(string baseUrl, Filter? filter = null)


if (httpClient == null)
httpClient = new HttpClient();
httpClient = HttpClientTools.CreateHttpCLient();


List<T> res= new List<T>();
Expand Down Expand Up @@ -169,7 +169,7 @@ private async Task<Response> PerformGetRequest(string url)
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url))
{
if (httpClient == null)
httpClient = new HttpClient();
httpClient = HttpClientTools.CreateHttpCLient();
fillHeader(requestMessage);
var response = await httpClient.SendAsyncLimited(requestMessage);

Expand All @@ -190,7 +190,7 @@ private async Task<Response> PerformPostRequest(string url, T item)
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, url))
{
if (httpClient == null)
httpClient = new HttpClient();
httpClient = HttpClientTools.CreateHttpCLient();
fillHeader(requestMessage);
requestMessage.Content = new StringContent(JsonSerializer.Serialize(item, serializeOptions));
var response = await httpClient.SendAsyncLimited(requestMessage);
Expand All @@ -212,7 +212,7 @@ private async Task<Response> PerformPutRequest(string url, T item)
using (var requestMessage = new HttpRequestMessage(HttpMethod.Put, url))
{
if (httpClient == null)
httpClient = new HttpClient();
httpClient = HttpClientTools.CreateHttpCLient();
fillHeader(requestMessage);
requestMessage.Content = new StringContent(JsonSerializer.Serialize(item, serializeOptions));
var response = await httpClient.SendAsyncLimited(requestMessage);
Expand All @@ -234,7 +234,7 @@ private async Task PerformDeleteRequest(string url)
using (var requestMessage = new HttpRequestMessage(HttpMethod.Delete, url))
{
if (httpClient == null)
httpClient = new HttpClient();
httpClient = HttpClientTools.CreateHttpCLient();
fillHeader(requestMessage);
var response = await httpClient.SendAsyncLimited(requestMessage);

Expand Down
21 changes: 20 additions & 1 deletion Entity/AbstractEntity.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
namespace RentmanSharp.Entity
using System.Text.Json.Serialization;

namespace RentmanSharp.Entity
{
public abstract class AbstractEntity : IEntity
{
[JsonPropertyName("id")]
public uint? ID { get; set; }
[JsonPropertyName("created")]
public DateTime? Created { get; set; }
[JsonPropertyName("modified")]
public DateTime? Modified { get; set; }
[JsonPropertyName("creator")]
public string? Creator { get; set; }
[JsonPropertyName("displayname")]
public string? DisplayName { get; set; }
[JsonPropertyName("updateHash")]
public string? updateHash { get; set; }

[JsonConstructor]
protected AbstractEntity(uint? id, DateTime? created, DateTime? modified, string? creator, string? displayName, string? updateHash)
{
ID = id;
Created = created;
Modified = modified;
Creator = creator;
DisplayName = displayName;
this.updateHash = updateHash;
}

public override string ToString()
{
return $"{ID}\t{DisplayName}";
Expand Down
26 changes: 21 additions & 5 deletions Entity/Accessorie .cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
namespace RentmanSharp.Entity
using System.Text.Json.Serialization;

namespace RentmanSharp.Entity
{
public class Accessorie : AbstractEntity
{
public string? Parent_Equipment { get; set; }
public string? Equipment { get; set; }
public int Quantity { get; set; }
public bool Automatic { get; set; }
[JsonPropertyName("parent_equipment")]
public string? Parent_Equipment { get; }
[JsonPropertyName("equipment")]
public string? Equipment { get; }
[JsonPropertyName("quantity")]
public int Quantity { get; }
[JsonPropertyName("automatic")]
public bool Automatic { get; }

[JsonConstructor]
public Accessorie(uint? id, DateTime? created, DateTime? modified, string? creator, string? displayName,
string? updateHash, string? parent_Equipment, string? equipment, int quantity, bool automatic) : base(id, created, modified, creator, displayName, updateHash)
{
Parent_Equipment = parent_Equipment;
Equipment = equipment;
Quantity = quantity;
Automatic = automatic;
}

public override string ToString()
{
Expand Down
71 changes: 55 additions & 16 deletions Entity/Appointment.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
using RentmanSharp.Converter;
using System.Drawing;
using System.Drawing;
using System.Text.Json.Serialization;
using System.Xml.Linq;

namespace RentmanSharp.Entity
{
public class Appointment : AbstractEntity
{
public string? Name { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
[JsonPropertyName("name")]
public string? Name { get; }
[JsonPropertyName("start")]
public DateTime Start { get; }
[JsonPropertyName("end")]
public DateTime End { get; }

[JsonPropertyName("color")]
[JsonConverter(typeof(Converter.ColorConverter))]
public Color? Color { get; set; }
public bool? Is_Plannable { get; set; }
public ERecurrenceIntervalUnit? Recurrence_Interval_Unit { get; set; }
public string? Recurrence_Enddate { get; set; }
public int? Recurrence_Interval { get; set; }
public string? Synchronization_Id { get; set; }
public string? Synchronisation_Uri { get; set; }
public string? Remark { get; set; }
public bool? Is_Public { get; set; }
public string? Location { get; set; }
public int? Recurrent_Group { get; set; }
public Color? Color { get; }
[JsonPropertyName("is_plannable")]
public bool? Is_Plannable { get; }
[JsonPropertyName("recurrence_interval_unit")]
public ERecurrenceIntervalUnit? Recurrence_Interval_Unit { get; }
[JsonPropertyName("recurrence_enddate")]
public string? Recurrence_Enddate { get; }
[JsonPropertyName("recurrence_interval")]
public int? Recurrence_Interval { get; }
[JsonPropertyName("synchronization_id")]
public string? Synchronization_Id { get; }
[JsonPropertyName("synchronisation_uri")]
public string? Synchronisation_Uri { get; }
[JsonPropertyName("remark")]
public string? Remark { get; }
[JsonPropertyName("is_public")]
public bool? Is_Public { get; }
[JsonPropertyName("location")]
public string? Location { get; }
[JsonPropertyName("recurrent_group")]
public int? Recurrent_Group { get; }

[JsonConstructor]
public Appointment(uint? id, DateTime? created, DateTime? modified, string? creator, string? displayName,
string? updateHash, string? name, DateTime start, DateTime end, Color? color,
bool? is_Plannable, ERecurrenceIntervalUnit? recurrence_Interval_Unit,
string? recurrence_Enddate, int? recurrence_Interval, string? synchronization_Id,
string? synchronisation_Uri, string? remark, bool? is_Public, string? location,
int? recurrent_Group) : base(id, created, modified, creator, displayName, updateHash)
{
Name = name;
Start = start;
End = end;
Color = color;
Is_Plannable = is_Plannable;
Recurrence_Interval_Unit = recurrence_Interval_Unit;
Recurrence_Enddate = recurrence_Enddate;
Recurrence_Interval = recurrence_Interval;
Synchronization_Id = synchronization_Id;
Synchronisation_Uri = synchronisation_Uri;
Remark = remark;
Is_Public = is_Public;
Location = location;
Recurrent_Group = recurrent_Group;
}

public override string ToString()
{
Expand Down
18 changes: 15 additions & 3 deletions Entity/AppointmentCrewItem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
namespace RentmanSharp.Entity
using System.Text.Json.Serialization;

namespace RentmanSharp.Entity
{
public class AppointmentCrewItem : AbstractEntity
{
public string? Appointment { get; set; }
public string? Crew { get; set; }
[JsonPropertyName("appointment")]
public string? Appointment { get; }
[JsonPropertyName("crew")]
public string? Crew { get; }

[JsonConstructor]
public AppointmentCrewItem(uint? id, DateTime? created, DateTime? modified, string? creator, string? displayName,
string? updateHash, string? appointment, string? crew) : base(id, created, modified, creator, displayName, updateHash)
{
Appointment = appointment;
Crew = crew;
}

public override string ToString()
{
Expand Down
Loading

0 comments on commit 1b20480

Please sign in to comment.