Skip to content

Commit

Permalink
Added Qodana
Browse files Browse the repository at this point in the history
• Added Qodana code check from JetBrains
• fixed results of Qodana check
  • Loading branch information
androidseb25 committed Apr 23, 2024
1 parent 9cccbb3 commit d31854b
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 324 deletions.
42 changes: 17 additions & 25 deletions Controller/DeviceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ namespace iGotify_Notification_Assist.Controller;
[Route("[controller]")]
public class DeviceController : ControllerBase
{
private readonly ILogger<DeviceController> _logger;

public DeviceController(ILogger<DeviceController> logger)
{
_logger = logger;
}

/// <summary>
/// Add device token to the TXT for sending the push notificcation
/// </summary>
Expand All @@ -24,17 +17,17 @@ public DeviceController(ILogger<DeviceController> logger)
[HttpPost]
public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)
{
string result = "";
bool resultBool = false;
string result;
bool resultBool;

Console.WriteLine($"ClientToken: {deviceModel.ClientToken}");
Console.WriteLine($"DeviceToken: {deviceModel.DeviceToken}");
Console.WriteLine($"GotifyUrl: {deviceModel.GotifyUrl}");
Console.WriteLine($"DeviceToken: {DeviceModel.DeviceToken}");
Console.WriteLine($"GotifyUrl: {DeviceModel.GotifyUrl}");

if (
deviceModel.ClientToken!.Length == 0 || deviceModel.ClientToken == "string" ||
deviceModel.DeviceToken!.Length == 0 || deviceModel.DeviceToken.Length < 60 || deviceModel.DeviceToken == "string" ||
deviceModel.GotifyUrl!.Length == 0 || deviceModel.GotifyUrl == "string"
deviceModel.ClientToken.Length == 0 || deviceModel.ClientToken == "string" ||
DeviceModel.DeviceToken.Length == 0 || DeviceModel.DeviceToken.Length < 60 || DeviceModel.DeviceToken == "string" ||
DeviceModel.GotifyUrl.Length == 0 || DeviceModel.GotifyUrl == "string"
)
{
result = "Fehler beim hinzugefügen des Gerätes!";
Expand All @@ -44,8 +37,8 @@ public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)

if (await deviceModel.Insert())
{
GotifySocketService gss = GotifySocketService.getInstance();
gss.StartWSThread(deviceModel.GotifyUrl, deviceModel.ClientToken);
GotifySocketService.getInstance();
GotifySocketService.StartWsThread(DeviceModel.GotifyUrl, deviceModel.ClientToken);
result = "Gerät erfolgreich hinzugefügt";
resultBool = true;
} else {
Expand All @@ -64,8 +57,8 @@ public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)
[HttpDelete]
public async Task<IActionResult> DeleteDevcice(string token)
{
string result = "";
bool resultBool = false;
string result;
bool resultBool;

Console.WriteLine($"Delete Token: {token}");
if (token.Length == 0 || token == "string")
Expand All @@ -75,15 +68,14 @@ public async Task<IActionResult> DeleteDevcice(string token)
return Ok(new { Message = result, Successful = resultBool });
}

DeviceModel deviceModel = new DeviceModel();
deviceModel.ClientToken = token;
Users usr = await DatabaseService.GetUser(token);
var deviceModel = new DeviceModel { ClientToken = token };
var usr = await DatabaseService.GetUser(token);
if (await deviceModel.Delete())
{
if (usr.Uid > 0)
{
GotifySocketService gss = GotifySocketService.getInstance();
gss.KillWsThread(usr.ClientToken);
GotifySocketService.getInstance();
GotifySocketService.KillWsThread(usr.ClientToken);
}

result = "Gerät erfolgreich gelöscht";
Expand All @@ -99,9 +91,9 @@ public async Task<IActionResult> DeleteDevcice(string token)
[HttpGet("Test/{deviceToken}")]
public async Task<IActionResult> Test(string deviceToken)
{
SecNtfy ntfy = new SecNtfy(Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app");
var ntfy = new SecNtfy(Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app");
if (deviceToken.Length > 0)
_ = await ntfy.SendNotification(deviceToken, "Test", "Test Nachricht", false, "", 0);
_ = await ntfy.SendNotification(deviceToken, "Test", "Test Nachricht");
Console.WriteLine(ntfy.encTitle);

return Ok();
Expand Down
16 changes: 3 additions & 13 deletions Controller/VersionController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Reflection;
using System.Security.Cryptography;
using iGotify_Notification_Assist.Helpers;
using iGotify_Notification_Assist.Models;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -10,23 +8,15 @@ namespace iGotify_Notification_Assist.Controller;
[Route("[controller]")]
public class VersionController : ControllerBase
{
private readonly ILogger<DeviceController> _logger;

public VersionController(ILogger<DeviceController> logger)
{
_logger = logger;
}

/// <summary>
/// Get the current version of the container
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult GetVersion()
{
ServerVersion sv = new ServerVersion();
sv.version = Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "";
DateTime buildDate = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;
var sv = new ServerVersion { version = Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "" };
var buildDate = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;
sv.buildDate = buildDate.ToString("yyyy-MM-dd'T'HH:mm:ss");
sv.commit = Programms.StartUpCommit;
return Ok(sv);
Expand All @@ -35,5 +25,5 @@ public IActionResult GetVersion()

public static class Programms
{
public static string? StartUpCommit = Guid.NewGuid().ToString().Replace("-", "");
public static readonly string? StartUpCommit = Guid.NewGuid().ToString().Replace("-", "");
}
39 changes: 0 additions & 39 deletions Helpers/MsgCrypto.cs

This file was deleted.

21 changes: 10 additions & 11 deletions Models/DeviceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ namespace iGotify_Notification_Assist.Models;

public class DeviceModel
{
public DeviceModel() { }

public string ClientToken { get; set; } = "";
public string DeviceToken { get; set; } = "";
public string GotifyUrl { get; set; } = "";
public string ClientToken { get; init; } = "";
public static string DeviceToken => "";
public static string GotifyUrl => "";

/// <summary>
/// Add device token to txt file
Expand All @@ -28,28 +26,29 @@ public async Task<bool> Insert()
/// <returns></returns>
public async Task<bool> Delete()
{
return await DatabaseService.DeleteUser(this.ClientToken);
return await DatabaseService.DeleteUser(ClientToken);
}

/// <summary>
/// Send the passed notification from the gotify instance that was passed via WebSocket
/// </summary>
/// <param name="iGotifyMessage"></param>
/// <param name="clientToken"></param>
public async Task SendNotifications(GotifyMessage iGotifyMessage, string clientToken)
{
string? title = iGotifyMessage.title;
string? msg = iGotifyMessage.message;
string imageUrl = "";
var title = iGotifyMessage.title;
var msg = iGotifyMessage.message;
const string imageUrl = "";


Users usr = await DatabaseService.GetUser(clientToken);
var usr = await DatabaseService.GetUser(clientToken);

if (usr.Uid == 0)
{
Console.WriteLine("THERE'S SOMETHING WRONG HERE? NO USER FOUND");
}

SecNtfy ntfy = new SecNtfy(Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app");
var ntfy = new SecNtfy(Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app");
_ = ntfy.SendNotification(usr.DeviceToken, title, msg, iGotifyMessage.priority == 10, imageUrl, iGotifyMessage.priority);
}
}
6 changes: 3 additions & 3 deletions Models/GotifyMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ public class GotifyMessage
public int appid { get; set; }
public string? date { get; set; }
public int id { get; set; }
public string? message { get; set; }
public int priority { get; set; }
public string message => "";
public int priority => 0;
public GotifyExtras? extras { get; set; }
public string? title { get; set; }
public string title => "";
}

public class GotifyExtras
Expand Down
6 changes: 3 additions & 3 deletions Models/ServerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace iGotify_Notification_Assist.Models;

public class ServerVersion
{
public string? version { get; set; }
public string? commit { get; set; }
public string? buildDate { get; set; }
public string? version { get; set; } = "";

Check warning on line 5 in Models/ServerVersion.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'version.get' is never used
public string? commit { get; set; } = "";

Check warning on line 6 in Models/ServerVersion.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'commit.get' is never used
public string? buildDate { get; set; } = "";

Check warning on line 7 in Models/ServerVersion.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'buildDate.get' is never used
}
8 changes: 4 additions & 4 deletions Models/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace iGotify_Notification_Assist.Models;

public class Users
{
public int Uid { get; set; }
public string ClientToken { get; set; } = "";
public string DeviceToken { get; set; } = "";
public string GotifyUrl { get; set; } = "";
public int Uid { get; init; }
public string ClientToken { get; init; } = "";
public string DeviceToken { get; init; } = "";
public string GotifyUrl { get; init; } = "";
}
3 changes: 0 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

using System.Net.WebSockets;
using iGotify_Notification_Assist;
using iGotify_Notification_Assist.Services;
using Microsoft.OpenApi.Models;

Expand Down
Loading

0 comments on commit d31854b

Please sign in to comment.