From b32ce16dc89c203ad8e66467a7b59d6edbe2666b Mon Sep 17 00:00:00 2001
From: csc530 <77406318+csc530@users.noreply.github.com>
Date: Thu, 1 Aug 2024 12:26:59 -0400
Subject: [PATCH] add edit skill command
---
.run/edit skill.run.xml | 20 ++++
Resumer/Program.cs | 95 ++++++++++---------
Resumer/cli/commands/edit/EditSkillCommand.cs | 41 ++++++++
3 files changed, 110 insertions(+), 46 deletions(-)
create mode 100644 .run/edit skill.run.xml
create mode 100644 Resumer/cli/commands/edit/EditSkillCommand.cs
diff --git a/.run/edit skill.run.xml b/.run/edit skill.run.xml
new file mode 100644
index 0000000..b79d7ff
--- /dev/null
+++ b/.run/edit skill.run.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Resumer/Program.cs b/Resumer/Program.cs
index a10edb2..8d520c0 100644
--- a/Resumer/Program.cs
+++ b/Resumer/Program.cs
@@ -105,6 +105,9 @@ public static void AppConfiguration(IConfigurator config)
.WithAlias("school")
.WithAlias("degree")
.WithDescription("edit an education's details");
+ edit.AddCommand("skill")
+ .WithAlias("s")
+ .WithDescription("edit a skill's details");
});
config.AddBranch("delete", delete =>
@@ -147,52 +150,52 @@ public static void AppConfiguration(IConfigurator config)
config.AddBranch("get", get =>
- {
- get.SetDescription("get job information from database");
- get.AddCommand("config")
- .WithAlias("configuration")
- .WithAlias("conf")
- .WithAlias("setting")
- .WithDescription("get app's current configuration settings")
- .WithAlias("settings");
- get.AddCommand("skill")
- .WithAlias("s")
- .WithDescription("list skills")
- .WithAlias("skills");
- get.AddCommand("company")
- .WithAlias("c")
- .WithDescription("list companies")
- .WithAlias("companies")
- .WithDescription("list companies you've worked for");
- get.AddCommand("job")
- .WithAlias("jobs")
- .WithDescription("list jobs")
- .WithAlias("j");
- get.AddCommand("profile")
- .WithAlias("user")
- .WithAlias("u")
- .WithAlias("users")
- .WithDescription("list user profiles")
- .WithAlias("profiles");
- get.AddCommand("project")
- .WithDescription("list projects")
- .WithAlias("p")
- .WithAlias("projects");
- get.AddCommand("template")
- .WithAlias("t")
- .WithAlias("templates")
- .WithDescription("list typst templates");
- get.AddCommand("education")
- .WithAlias("edu")
- .WithAlias("educations")
- .WithAlias("schools")
- .WithAlias("school")
- .WithAlias("degree")
- .WithDescription("list education");
- })
- .WithAlias("g")
- .WithAlias("list")
- .WithAlias("ls");
+ {
+ get.SetDescription("get job information from database");
+ get.AddCommand("config")
+ .WithAlias("configuration")
+ .WithAlias("conf")
+ .WithAlias("setting")
+ .WithDescription("get app's current configuration settings")
+ .WithAlias("settings");
+ get.AddCommand("skill")
+ .WithAlias("s")
+ .WithDescription("list skills")
+ .WithAlias("skills");
+ get.AddCommand("company")
+ .WithAlias("c")
+ .WithDescription("list companies")
+ .WithAlias("companies")
+ .WithDescription("list companies you've worked for");
+ get.AddCommand("job")
+ .WithAlias("jobs")
+ .WithDescription("list jobs")
+ .WithAlias("j");
+ get.AddCommand("profile")
+ .WithAlias("user")
+ .WithAlias("u")
+ .WithAlias("users")
+ .WithDescription("list user profiles")
+ .WithAlias("profiles");
+ get.AddCommand("project")
+ .WithDescription("list projects")
+ .WithAlias("p")
+ .WithAlias("projects");
+ get.AddCommand("template")
+ .WithAlias("t")
+ .WithAlias("templates")
+ .WithDescription("list typst templates");
+ get.AddCommand("education")
+ .WithAlias("edu")
+ .WithAlias("educations")
+ .WithAlias("schools")
+ .WithAlias("school")
+ .WithAlias("degree")
+ .WithDescription("list education");
+ })
+ .WithAlias("g")
+ .WithAlias("list")
+ .WithAlias("ls");
}
public static string TempPath { get; } = Path.GetTempPath() + "resumer" + Path.DirectorySeparatorChar;
diff --git a/Resumer/cli/commands/edit/EditSkillCommand.cs b/Resumer/cli/commands/edit/EditSkillCommand.cs
new file mode 100644
index 0000000..010df66
--- /dev/null
+++ b/Resumer/cli/commands/edit/EditSkillCommand.cs
@@ -0,0 +1,41 @@
+using Resumer.models;
+using Spectre.Console;
+using Spectre.Console.Cli;
+using Command = Spectre.Console.Cli.Command;
+
+namespace Resumer.cli.commands.edit;
+
+public class EditSkillCommand: Command
+{
+ public override int Execute(CommandContext context)
+ {
+ var db = new ResumeContext();
+
+ var skill = AnsiConsole.Prompt(new SelectionPrompt()
+ .Title("Select skill to edit")
+ .AddChoices(db.Skills.OrderBy(s => s.Name))
+ .WrapAround()
+ .PageSize(10)
+ );
+ db.Skills.Update(skill);
+ AnsiConsole.WriteLine($"Editing: {skill}");
+
+ var name = AnsiConsole.Prompt(new TextPrompt("Name:").DefaultValue(skill.Name));
+ var type = AnsiConsole.Prompt(new TextPrompt("Type (hard/soft):").DefaultValue(skill.Type));
+
+
+ // because skill.name is the PK and it's not a [foreign key assoc.](https://stackoverflow.com/questions/5281974/code-first-independent-associations-vs-foreign-key-associations/5282275#5282275)
+ // tl;dr remove and insert to update 🙄
+ if(!skill.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
+ {
+ db.Skills.Remove(skill);
+ db.Skills.Add(new Skill(name, type));
+ }
+ else
+ skill.Type = type;
+
+ db.SaveChanges();
+
+ return CommandOutput.Success("Skill updated successfully");
+ }
+}
\ No newline at end of file