diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2023-02-25 13:15:44 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2023-02-25 13:15:44 +0100 |
| commit | 900bb5e845c3ad44defbd427cae3d44a4a43321f (patch) | |
| tree | df3d96a93771884add571e82336c29fc3d9c7a1c /code/api/src/Models/Misc | |
| download | greatoffice-900bb5e845c3ad44defbd427cae3d44a4a43321f.tar.xz greatoffice-900bb5e845c3ad44defbd427cae3d44a4a43321f.zip | |
feat: Initial commit
Diffstat (limited to 'code/api/src/Models/Misc')
| -rw-r--r-- | code/api/src/Models/Misc/ApiSpecDocument.cs | 9 | ||||
| -rw-r--r-- | code/api/src/Models/Misc/AppConfiguration.cs | 118 | ||||
| -rw-r--r-- | code/api/src/Models/Misc/AppPath.cs | 23 | ||||
| -rw-r--r-- | code/api/src/Models/Misc/KnownProblemModel.cs | 26 | ||||
| -rw-r--r-- | code/api/src/Models/Misc/LoggedInUserModel.cs | 8 | ||||
| -rw-r--r-- | code/api/src/Models/Misc/RequestTimeZoneInfo.cs | 8 |
6 files changed, 192 insertions, 0 deletions
diff --git a/code/api/src/Models/Misc/ApiSpecDocument.cs b/code/api/src/Models/Misc/ApiSpecDocument.cs new file mode 100644 index 0000000..1c7d936 --- /dev/null +++ b/code/api/src/Models/Misc/ApiSpecDocument.cs @@ -0,0 +1,9 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class ApiSpecDocument +{ + public string VersionName { get; set; } + public string SwaggerPath { get; set; } + public ApiVersion Version { get; set; } + public OpenApiInfo OpenApiInfo { get; set; } +} diff --git a/code/api/src/Models/Misc/AppConfiguration.cs b/code/api/src/Models/Misc/AppConfiguration.cs new file mode 100644 index 0000000..31e5726 --- /dev/null +++ b/code/api/src/Models/Misc/AppConfiguration.cs @@ -0,0 +1,118 @@ +using System.Security.Cryptography.X509Certificates; + +namespace IOL.GreatOffice.Api.Data.Models; + +public class AppConfiguration +{ + /// <summary> + /// An reachable ip address or url that points to a postgres database. + /// </summary> + public string DB_HOST { get; set; } + + /// <summary> + /// The port number to use with DB_HOST to point to the postgres database. + /// </summary> + public string DB_PORT { get; set; } + + /// <summary> + /// The database user to authenticate against postgres with. + /// </summary> + public string DB_USER { get; set; } + + /// <summary> + /// The password for the database user to authenticate against postgres with. + /// </summary> + public string DB_PASSWORD { get; set; } + + /// <summary> + /// The name of the main app database. + /// </summary> + public string DB_NAME { get; set; } + + /// <summary> + /// An reachable ip address or url that points to a postgres(quartz) database. + /// </summary> + public string QUARTZ_DB_HOST { get; set; } + + /// <summary> + /// The port number to use with QUARTZ_DB_HOST to point to the postgres(quartz) database. + /// </summary> + public string QUARTZ_DB_PORT { get; set; } + + /// <summary> + /// The database user to authenticate against postgres(quartz) with. + /// </summary> + public string QUARTZ_DB_USER { get; set; } + + /// <summary> + /// The password for the database user to authenticate against postgres(quartz) with. + /// </summary> + public string QUARTZ_DB_PASSWORD { get; set; } + + /// <summary> + /// The name of the quartz database. + /// </summary> + public string QUARTZ_DB_NAME { get; set; } + + /// <summary> + /// API key to use when pushing logs to SEQ + /// </summary> + public string SEQ_API_KEY { get; set; } + + /// <summary> + /// Url pointing to the seq instance that processes server logs + /// </summary> + public string SEQ_API_URL { get; set; } + + /// <summary> + /// A token used when sending email via Postmakr + /// </summary> + public string POSTMARK_TOKEN { get; set; } + + /// <summary> + /// The address to send emails from, needs to be setup as a sender in postmark + /// </summary> + public string EMAIL_FROM_ADDRESS { get; set; } + + /// <summary> + /// The absolute url to the frontend app + /// </summary> + public string CANONICAL_FRONTEND_URL { get; set; } + + /// <summary> + /// The absolute url to the backend api + /// </summary> + public string CANONICAL_BACKEND_URL { get; set; } + + /// <summary> + /// A random string used to encrypt/decrypt for general purposes + /// </summary> + public string APP_AES_KEY { get; set; } + + /// <summary> + /// A base64 string containing a passwordless pfx cert + /// </summary> + public string APP_CERT { get; set; } + + public X509Certificate2 CERT1() => new(Convert.FromBase64String(APP_CERT)); + + public object GetPublicVersion() { + return new { + DB_HOST, + DB_PORT, + DB_USER, + DB_PASSWORD = DB_PASSWORD.Obfuscate() ?? "", + QUARTZ_DB_HOST, + QUARTZ_DB_PORT, + QUARTZ_DB_USER, + QUARTZ_DB_PASSWORD = QUARTZ_DB_PASSWORD.Obfuscate() ?? "", + SEQ_API_KEY = SEQ_API_KEY.Obfuscate() ?? "", + SEQ_API_URL, + POSTMARK_TOKEN = POSTMARK_TOKEN.Obfuscate() ?? "", + EMAIL_FROM_ADDRESS, + APP_AES_KEY = APP_AES_KEY.Obfuscate() ?? "", + CERT1 = CERT1().PublicKey.Oid.FriendlyName, + CANONICAL_FRONTEND_URL + }; + } +}
\ No newline at end of file diff --git a/code/api/src/Models/Misc/AppPath.cs b/code/api/src/Models/Misc/AppPath.cs new file mode 100644 index 0000000..e47e48c --- /dev/null +++ b/code/api/src/Models/Misc/AppPath.cs @@ -0,0 +1,23 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public sealed record AppPath +{ + public string HostPath { get; init; } + public string WebPath { get; init; } + + public string GetHostPathForFilename(string filename, string fallback = "") { + if (filename.IsNullOrWhiteSpace()) { + return fallback; + } + + return Path.Combine(HostPath, filename); + } + + public string GetWebPathForFilename(string filename, string fallback = "") { + if (filename.IsNullOrWhiteSpace()) { + return fallback; + } + + return Path.Combine(WebPath, filename); + } +} diff --git a/code/api/src/Models/Misc/KnownProblemModel.cs b/code/api/src/Models/Misc/KnownProblemModel.cs new file mode 100644 index 0000000..9acc85c --- /dev/null +++ b/code/api/src/Models/Misc/KnownProblemModel.cs @@ -0,0 +1,26 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class KnownProblemModel +{ + public KnownProblemModel(string title = default, string subtitle = default, Dictionary<string, string[]> errors = default) { + Title = title; + Subtitle = subtitle; + Errors = errors ?? new(); + } + + public string Title { get; set; } + public string Subtitle { get; set; } + public Dictionary<string, string[]> Errors { get; set; } + public string TraceId { get; set; } + + public void AddError(string field, string errorText) { + if (!Errors.ContainsKey(field)) { + Errors.Add(field, new[] {errorText}); + } else { + var currentErrors = Errors[field]; + var newErrors = currentErrors.Concat(new[] {errorText}); + Errors.Remove(field); + Errors.Add(field, newErrors.ToArray()); + } + } +}
\ No newline at end of file diff --git a/code/api/src/Models/Misc/LoggedInUserModel.cs b/code/api/src/Models/Misc/LoggedInUserModel.cs new file mode 100644 index 0000000..541d4a5 --- /dev/null +++ b/code/api/src/Models/Misc/LoggedInUserModel.cs @@ -0,0 +1,8 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class LoggedInUserModel +{ + public Guid Id { get; set; } + public string Username { get; set; } + public Guid TenantId { get; set; } +}
\ No newline at end of file diff --git a/code/api/src/Models/Misc/RequestTimeZoneInfo.cs b/code/api/src/Models/Misc/RequestTimeZoneInfo.cs new file mode 100644 index 0000000..4c5aa13 --- /dev/null +++ b/code/api/src/Models/Misc/RequestTimeZoneInfo.cs @@ -0,0 +1,8 @@ +namespace IOL.GreatOffice.Api.Data.Models; + +public class RequestTimeZoneInfo +{ + public TimeZoneInfo TimeZoneInfo { get; set; } + public int Offset { get; set; } + public DateTime LocalDateTime { get; set; } +}
\ No newline at end of file |
