Skip to content

Commit

Permalink
Edit/Delete Progress Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostp13409 committed Oct 30, 2024
1 parent cd2d47f commit d8e54fa
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 19 deletions.
9 changes: 9 additions & 0 deletions app-test/CommandLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public void TestParseWorkItem()
Assert.Equal(Verb.List, verb);
}

[Fact]
public void TestParseProgress()
{
string[] args = { "progress", "list" };
(Noun noun, Verb verb) = parser.Parse(args);
Assert.Equal(Noun.WorkItem, noun);
Assert.Equal(Verb.List, verb);
}

[Fact]
public void TestCommandLineArgs()
{
Expand Down
1 change: 1 addition & 0 deletions app-test/app-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConsoleTables" Version="2.6.2" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
Expand Down
1 change: 1 addition & 0 deletions app/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum Noun
{
Credits, // Represents the "credits" noun.
WorkItem, // Represents work item
Progress, // Represents Progerss item
Invalid // Represents an invalid noun.
}

Expand Down
7 changes: 4 additions & 3 deletions app/Credits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
It was created to fulfill #16
*/

using ConsoleTables;
using Lms;

class Credits : ICommand {
Expand Down Expand Up @@ -96,11 +97,11 @@ public String[] GetCredits() {
}

public void DisplayCredits() {
Console.WriteLine("Credits");
Console.WriteLine("-------");
ConsoleTable creditTable = new ConsoleTable("Credits");
foreach (string credit in GetCredits()) {
Console.WriteLine(credit);
creditTable.AddRow(credit);
}
creditTable.Write(Format.Minimal);
}

public void Execute(Verb verb) {
Expand Down
16 changes: 13 additions & 3 deletions app/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Lms;


// DB Context for Handling Database

// DB Drivers
public enum DbDriver
{
Sqlite,
Expand All @@ -13,18 +17,23 @@ public enum DbDriver
Memory
};


// Custom DBContext that implements base DBContext class
public class LmsDbContext : Microsoft.EntityFrameworkCore.DbContext
{

// DB Sets (Tables in Database)
public DbSet<Models.Progress> Progresses { get; set; }
public DbSet<Models.WorkItem> WorkItems { get; set; }
public DbSet<Block> Blockers { get; set; }

// set database to SQLite
public DbDriver Driver { get; private set; } = DbDriver.Sqlite;


// Connection String for database connection
public string DbPath { get; private set; } = "Data Source=lms.db";


// Cunstructors
public LmsDbContext()
{

Expand All @@ -46,12 +55,13 @@ public LmsDbContext(DbDriver driver, string dbPath = "lms")
this.DbPath = dbPath;
}

// Overriding OnConfigring Method to manage Database connections
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
switch (Driver)
{
case DbDriver.Sqlite:
optionsBuilder.UseSqlite(DbPath);
optionsBuilder.UseSqlite(DbPath); // Connect DBContext to SQLite Database with connection string(DbPath)
break;
case DbDriver.Postgres:
throw new NotImplementedException();
Expand Down
6 changes: 5 additions & 1 deletion app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
return 400;
}


// Initialize DBContext
var dbContext = new LmsDbContext();

switch (noun)
Expand All @@ -35,6 +35,10 @@
WorkItem work_item = new WorkItem(dbContext);
work_item.Execute(verb, command_args);
return 200;
case Noun.Progress:
Progress progress = new Progress(dbContext);
progress.Execute(verb, command_args);
return 200;
default:
Console.WriteLine(
$"""
Expand Down
11 changes: 6 additions & 5 deletions app/Progress.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ConsoleTables;
using lms.models;
using Lms;
using Microsoft.EntityFrameworkCore.Metadata.Builders;



Expand Down Expand Up @@ -61,14 +63,13 @@ public void Execute(Verb verb)
switch (verb) {
case Verb.List:
var progresses = GetProgresses();
Console.WriteLine("------------------------------");
Console.WriteLine("| id | Description | WorkItem | CreatedAt |");
ConsoleTable itemTable = new ConsoleTable("ID", "Description", "WorkItem", "CreatedAt");
progresses.ToList().ForEach(
(p) => {
Console.WriteLine($"| w{p.Id} | {p.Description} | {p.WorkItem.Id} | {p.CreatedAt:yyyy-MM-dd} |");
itemTable.AddRow(p.Id, p.Description, p.WorkItem.Id, p.CreatedAt.ToString("yyyy-MM-dd"));

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (linux-bionic-arm64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (linux-musl-arm64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Dereference of a possibly null reference.

Check warning on line 69 in app/Progress.cs

View workflow job for this annotation

GitHub Actions / build (linux-musl-x64)

Dereference of a possibly null reference.
}
);
Console.WriteLine("------------------------------");
itemTable.Write();
break;
default:
throw new ArgumentException("Invalid Verb");
Expand Down Expand Up @@ -100,7 +101,7 @@ public void Execute(Verb verb)



// Overloaded Execute Function with additional Arguments (Ex. Delete, Edit, Create) -> -> lms Progress Delete 0, lms Progress Edit 3
// Overloaded Execute Function with additional Arguments (Ex. Delete, Edit, Create) -> lms Progress Delete 0, lms Progress Edit 3
public void Execute(Verb verb, string[] command_args)
{
switch (verb)
Expand Down
27 changes: 23 additions & 4 deletions app/WorkItem.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using ConsoleTables;
using lms.models;
using Lms;

class WorkItem : ICommand {

// DBContext for Database Interactions (Add, Update, Remove, SaveChanges)

private LmsDbContext db;

// Constructor - Set DB
public WorkItem(LmsDbContext db) {
this.db = db;
}


// Command Documentation for CLI Application

// Main Command Documentation
public string GetHelp() {
return $"""
WorkItem
Expand All @@ -23,6 +32,8 @@ public string GetHelp() {
""";
}

// Individual Commands with their Description

public string GetHelp(Verb verb)
{
switch (verb) {
Expand All @@ -44,25 +55,28 @@ public string GetHelp(Verb verb)
return db.WorkItems.AsEnumerable();
}


// Execute Function without additional Arguments (Ex. List) -> lms Progress List
public void Execute(Verb verb)
{
switch (verb) {
case Verb.List:
var work_items = GetWorkItems();
Console.WriteLine("------------------------------");
Console.WriteLine("| id | Title | CreatedAt | DueAt | Description |");
ConsoleTable itemTable = new ConsoleTable("ID", "Title", "CreatedAt", "DueAt");
work_items.ToList().ForEach(
(wi) => {
Console.WriteLine($"| w{wi.Id} | {wi.Title} | {wi.CreatedAt:yyyy-MM-dd} | {wi.DueAt:yyyy-MM-dd} |");
itemTable.AddRow(wi.Id, wi.Title, wi.CreatedAt.ToString("yyyy-MM-dd"), wi.DueAt.Value.ToString("yyyy-MM-dd"));

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (linux-bionic-arm64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (linux-musl-arm64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Nullable value type may be null.

Check warning on line 68 in app/WorkItem.cs

View workflow job for this annotation

GitHub Actions / build (linux-musl-x64)

Nullable value type may be null.
}
);
Console.WriteLine("------------------------------");
itemTable.Write();
break;
default:
throw new ArgumentException("Invalid Verb");
}
}


// Create new WorkItem
public Lms.Models.WorkItem Create(string title, string? due_at) {
DateTime? parsed_due_at;

Expand All @@ -83,6 +97,8 @@ public Lms.Models.WorkItem Create(string title, string? due_at) {
return result;
}


// Overloaded Execute Function with additional Arguments (Ex. Delete, Edit, Create) -> lms WorkItem Delete 0, lms WorkItem Edit 3
public void Execute(Verb verb, string[] command_args)
{
switch (verb)
Expand Down Expand Up @@ -142,6 +158,7 @@ public void Execute(Verb verb, string[] command_args)
}
}

// Edit WorkItem
public Lms.Models.WorkItem Edit(string id, string field, string value) {
int parsed_id = -1;

Expand Down Expand Up @@ -186,6 +203,8 @@ public Lms.Models.WorkItem Edit(string id, string field, string value) {

return result;
}

// Delete WorkItem by Id
public Lms.Models.WorkItem Delete(string id) {
int parsed_id;
if (!int.TryParse(id, out parsed_id)) {
Expand Down
1 change: 1 addition & 0 deletions app/app.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>app-test</_Parameter1>
</AssemblyAttribute>
<PackageReference Include="ConsoleTables" Version="2.6.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
1 change: 0 additions & 1 deletion app/models/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class Block : Item
{
// Fields


// Id and Created At Implemented in Items
public string? Description { get; set; }

Expand Down
2 changes: 0 additions & 2 deletions app/models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ public enum Field
public int Id { get; set; }

public DateTime CreatedAt { get; } = DateTime.Now;


}
}

0 comments on commit d8e54fa

Please sign in to comment.