Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0e99972
Project Setup
FeedMyData Oct 5, 2026
dfe3fbf
Update CodingSession and starting with the DB
FeedMyData Oct 5, 2026
939d9ae
Adding base CRUD SQL commands and Menu
FeedMyData Oct 5, 2026
dedd1c2
fixing typo in UserInterface switch
FeedMyData Oct 5, 2026
a707857
CreateDB() with dapper synthax
FeedMyData Oct 5, 2026
502c08f
New menu Item AddItemStartNow for easy UI
FeedMyData Oct 5, 2026
0e5b112
Active coding session
FeedMyData Oct 6, 2026
eee6ddf
LiveSession Done and files organisation
FeedMyData Oct 6, 2026
d8b19e8
Create Query.cs
FeedMyData Oct 7, 2026
c1fe85e
Repository: remove Enum & create Parameter
FeedMyData Oct 7, 2026
46f0d29
Fixing TextPrompt for activity
FeedMyData Oct 7, 2026
6b3ad4f
ViewAll function
FeedMyData Oct 7, 2026
7f65d69
Fixing Int64 issue with dapper
FeedMyData Oct 7, 2026
4e6f546
Seeding data WIP
FeedMyData Oct 7, 2026
cca8b42
Better Conversions between DateTime and String
FeedMyData Oct 7, 2026
c957430
Add a previous session
FeedMyData Oct 8, 2026
ddea4b2
Query CountRows()
FeedMyData Oct 9, 2026
839e66d
NoEntriesFound() method
FeedMyData Oct 9, 2026
f1e8e28
Add queries to filter
FeedMyData Oct 9, 2026
ef241a4
Functions to edit Coding Session Model
FeedMyData Oct 9, 2026
47b1528
Defining Hour automatically for easier search
FeedMyData Oct 9, 2026
2228e6d
DisplayData() for CodingSession
FeedMyData Oct 9, 2026
b7a8cbb
Choices Prompt for Editing and Removing
FeedMyData Oct 9, 2026
7812fa7
Filter Search function now working
FeedMyData Oct 9, 2026
a3b4fa1
fixing stopwatch format issue again
FeedMyData Oct 9, 2026
b421a4e
Query RowFromID()
FeedMyData Oct 9, 2026
446c304
Prompt SelectMultiString()
FeedMyData Oct 9, 2026
f2731c1
Fixing Math issue while converting int to hhmm
FeedMyData Oct 9, 2026
a2c6126
New helpers in TimeFormatter
FeedMyData Oct 9, 2026
5a13878
Renaming functions + missing lines in last commit
FeedMyData Oct 9, 2026
ca4b18a
Update TimeFormater.cs
FeedMyData Oct 9, 2026
f69233a
Update CodingSession.cs
FeedMyData Oct 9, 2026
4840022
Feature: Edit an entry
FeedMyData Oct 9, 2026
26a9a4a
DeleteItem()
FeedMyData Oct 11, 2026
fda5f33
Cleaning UI and files
FeedMyData Oct 11, 2026
a04dc2e
small bug fixes
FeedMyData Oct 11, 2026
d6bf2f3
Autofill activity
FeedMyData Oct 12, 2026
2945987
Update Query.cs
FeedMyData Oct 12, 2026
62b66e5
Database Error Handling
FeedMyData Oct 12, 2026
dd6880a
Handling empty TableData()
FeedMyData Oct 12, 2026
fad0059
Reorganizing menu
FeedMyData Oct 12, 2026
3938503
Update EnumExtensions.cs
FeedMyData Oct 12, 2026
cea1fe1
Update ChoicesPrompt.cs
FeedMyData Oct 12, 2026
65e5724
Renaming Repository to Database
FeedMyData Oct 12, 2026
47b046d
Add README for Console Coding Tracker application
FeedMyData Oct 13, 2026
a12d9d5
Added appsettings.json
FeedMyData Oct 13, 2026
a948c17
Readme.md update
FeedMyData Oct 13, 2026
8b9d68a
Adding .gitignore and removing generated build files
FeedMyData Oct 14, 2026
c15dfd5
Removing database
FeedMyData Oct 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .codacy.yml

This file was deleted.

8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*.userosscache
*.sln.docstates


# Vs Code debug config files
launch.json
tasks.json

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

Expand Down Expand Up @@ -399,7 +404,6 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
.idea/

##
## Visual studio for Mac
Expand Down Expand Up @@ -476,5 +480,3 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk
/MathGame2
/CodingTracker.TomDonegan/TextFile1.txt
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net10.0/CodingTracker.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "externalTerminal"
}

]
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dotnet",
"task": "build",
"group": "build",
"problemMatcher": [],
"label": "build"
}
]
}
20 changes: 20 additions & 0 deletions CodingTracker/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build",
"program": "${workspaceFolder}/bin/Debug/net10.0/CodingTracker.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "externalTerminal"
}

]
}
24 changes: 24 additions & 0 deletions CodingTracker/CodingTracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.89" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.12" />
<PackageReference Include="Spectre.Console" Version="0.57.2" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
106 changes: 106 additions & 0 deletions CodingTracker/Data/Database.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using CodingSession;
using Dapper;
using Microsoft.Data.Sqlite;

namespace CodingTracker;

internal class Database
{
private static string ConnectionString;

internal static void Configure(string connectionString)
{
ConnectionString = connectionString;
}

internal static T Execute<T>(Func<SqliteConnection, T> action)
{
try
{
using var connection = new SqliteConnection(ConnectionString);
return action(connection);
}
catch (SqliteException ex)
{
throw new InvalidOperationException("Database access failed.", ex);
}
}

internal static void CreateDB()
{
bool tableExisted;

using (var connection = new SqliteConnection(ConnectionString))
{
const string existsSql =
$@"SELECT EXISTS (SELECT name
FROM sqlite_master
WHERE type = 'table'
AND name = 'coding_tracker')";

tableExisted = connection.ExecuteScalar<bool>(existsSql);

string createSql =
$@"CREATE TABLE IF NOT EXISTS coding_tracker(
id INTEGER PRIMARY KEY AUTOINCREMENT,
activity TEXT,
startTime TEXT,
endTime TEXT,
duration INTEGER)";

connection.Execute(createSql);
}

if (!tableExisted)
DebugTool.SeedData();
}

internal static void Add(string activity, string startTime, string endTime, int duration)
{
string sql = @$"INSERT INTO coding_tracker
(activity, startTime, endTime, duration)
VALUES (@activity, @startTime, @endTime, @duration)";

Execute(connection => connection.Execute(sql, new
{
activity = activity,
startTime = startTime,
endTime = endTime,
duration = duration
}));
}

internal static void ConvertAndAdd(string activity, DateTime startTime, DateTime endTime, TimeSpan duration)
{
string startTimeDB = TimeFormatter.ConvertDateForDb(startTime);
string endTimeDB = TimeFormatter.ConvertDateForDb(endTime);
int durationDB = TimeFormatter.MinutesToInt(duration);

Add(activity, startTimeDB, endTimeDB, durationDB);
}

internal static void Delete(CodingSession entry)
{
string sql = @$"DELETE FROM coding_tracker WHERE id = @id";
Execute(connection => connection.Execute(sql, new { id = entry.Id }));
}

internal static void UpdateRow(CodingSession entry)
{
string sql = @$"UPDATE coding_tracker
SET activity = @activity,
startTime = @startTime,
endTime = @endTime,
duration = @duration
WHERE id = @id";

Execute(connection => connection.Execute(sql, new
{
activity = entry.Activity,
startTime = entry.StartTime,
endTime = entry.EndTime,
duration = entry.Duration,
id = entry.Id
}));
}
}
48 changes: 48 additions & 0 deletions CodingTracker/Data/Query.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Dapper;
using Microsoft.Data.Sqlite;
using static CodingTracker.Database;

namespace CodingTracker;

internal class Query
{
internal static List<CodingSession> ViewAll()
{
string sql = @$"SELECT * FROM coding_tracker ORDER BY startTime DESC";
return Execute(connection => connection.Query<CodingSession>(sql).ToList());
}

internal static int CountRows()
{
string sql = @$"SELECT COUNT(*) FROM coding_tracker";
return Execute(connection => Convert.ToInt32(connection.ExecuteScalar(sql)));
}

internal static int RowFromID(int id)
{
string sql = @$"SELECT * FROM coding_tracker WHERE id = @id";
return Execute(connection => Convert.ToInt32(connection.ExecuteScalar(sql, new { id })));
}

internal static List<CodingSession> FilterByActivity(string filter)
{
string sql = @$"SELECT * FROM coding_tracker WHERE activity LIKE @filter ORDER BY startTime DESC";
return Execute(connection => connection.Query<CodingSession>(sql, new { filter = $"%{filter}%" }).ToList());
}

internal static List<CodingSession> FilterByDate(string startDate, string endDate)
{
string sql = @$"SELECT * FROM coding_tracker
WHERE startTime BETWEEN @startDate AND @endDate
ORDER BY startTime DESC";
return Execute(connection => connection.Query<CodingSession>(sql, new { startDate = startDate, endDate = endDate }).ToList());
}

internal static string LastActivity()
{
string sql = @$"SELECT activity FROM coding_tracker
ORDER BY id DESC
LIMIT 1";
return Execute(connection => Convert.ToString(connection.ExecuteScalar(sql)));
}
}
30 changes: 30 additions & 0 deletions CodingTracker/Enums/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Reflection;
using System.ComponentModel.DataAnnotations;
using static CodingTracker.Enums;

namespace CodingTracker;

public static class EnumExtensions
{
public static string GetDisplayName(this Enum value)
{
var member = value.GetType().GetMember(value.ToString())[0];

return member
.GetCustomAttribute<DisplayAttribute>()?
.GetName()
?? value.ToString();
}

internal static List<string> GetEditableColumn()
{
List<string> choices = new();

foreach (string columnName in Enum.GetNames<Column>())
{
if (columnName != Column.id.ToString() && columnName != Column.duration.ToString())
choices.Add(((Column)Enum.Parse(typeof(Column), columnName)).GetDisplayName());
}
return choices;
}
}
45 changes: 45 additions & 0 deletions CodingTracker/Enums/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.ComponentModel.DataAnnotations;

namespace CodingTracker;

internal class Enums
{
internal enum Column
{
[Display(Name = "ID")]
id,

[Display(Name = "Activity")]
activity,

[Display(Name = "Start time")]
startTime,

[Display(Name = "End time")]
endTime,

[Display(Name = "Duration")]
duration
}

internal enum MenuChoice
{
[Display(Name = "View entries")]
viewItems,

[Display(Name = "[green]Start[/] a session [green]now[/]")]
addItemStartNow,

[Display(Name = "[green]Add[/] a previous session")]
addItem,

[Display(Name = "[blue]Edit[/] an entry")]
editItem,

[Display(Name = "[red]Delete[/] an entry")]
deleteItem,

[Display(Name = "Exit")]
exit,
}
}
Loading