Skip to content

Commit

Permalink
Basic database implementation (#5)
Browse files Browse the repository at this point in the history
The database will allow for better flexibility and extensibility in maintaining varies types of art that are requested. This features a basic implementation of adding new orders to it but you can't yet search or delete. In the future, you will also be able to export these orders as Json files for use as a receipt or import into someone else's implementation of artm.

Other features include automated category selection and hashing based on former to determine the appropriate to add. The hashing is meant to not only verify information but also allow for accurate searching and pave the way for the raffling system, see issue #1.
  • Loading branch information
tonytins committed Jul 30, 2019
1 parent 1318fc7 commit e62c1e5
Show file tree
Hide file tree
Showing 25 changed files with 724 additions and 225 deletions.
6 changes: 6 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@

[Usage](docs/Usage.md) | [To-do](TODO.md)

A command line application for storing art request, commission, and YCH information. The application is a work in progress but contribution is welcomed.
Art Manager (``artm``) is a command line application for storing art request, commission, and YCH information. The application is a work in progress but contribution is welcomed.

## Prerequisites

- [.NET Core 3.0 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.0)
- Preview 6 or above
- SDKs
- [.NET Core 2.1](https://dotnet.microsoft.com/download/dotnet-core/2.1)
- [.NET Core 3.0 Preview 7+](https://dotnet.microsoft.com/download/dotnet-core/2.1) for unit tests
- IDEs or Text Editors
- Rider
- VSCode
- VS2019 16.2 (recommended)
- 16.3 for unit tests

## Platforms

See the [platforms](Docs/Platforms.md) page.
See the [platforms](Docs/Platforms.md) page.

## Developer Note

The unit tests are written in VB.NET. While Art Manager is being developed for production purposes, the unit tests were written in VB.NET in order to better understand the language without having to starting from scratch with a new project.
4 changes: 0 additions & 4 deletions Src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.{fs,fsx,fsi}]
indent_style = space
indent_size = 4

# VB and C# files
[*.{vb,cs}]
# avoid this. unless absolutely necessary
Expand Down
22 changes: 22 additions & 0 deletions Src/ArtManager.CLI/ArtManager.CLI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>artm</AssemblyName>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>0.2</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntryPoint" Version="1.2.3" />
<PackageReference Include="LiteDB" Version="4.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.11" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArtManager\ArtManager.csproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions Src/ArtManager.CLI/ArtManager.CLI.licenseheader
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
// Licensed under the GNU GPL v3 license. See LICENSE file in the project
// root for full license information.
13 changes: 13 additions & 0 deletions Src/ArtManager.CLI/ArtmConsts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
// Licensed under the GNU GPL v3 license. See LICENSE file in the project
// root for full license information.
namespace ArtManager.CLI
{
struct ArtmConsts
{
public const string APPNAME = "Art Manager";
public const string DBERR = "Failed to connect to database";
public const string DBFILE = "artm.db";
public const string DBCOL = "art";
}
}
39 changes: 34 additions & 5 deletions Src/ArtManager/CliArgs.cs → Src/ArtManager.CLI/CliArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
// root for full license information.
using EntryPoint;

namespace ArtManager
namespace ArtManager.CLI
{
class BaseArgs : BaseCliArguments
class GlobalArgs : BaseCliArguments
{
public BaseArgs() : base("Art Manager") { }
public GlobalArgs() : base(ArtmConsts.APPNAME) { }

[Option("debug", 'D')]
public bool Debug { get; set; }

}

class BaseArgs : GlobalArgs
{
/// <summary>
/// Artwork name
/// </summary>
Expand Down Expand Up @@ -49,14 +53,39 @@ class BaseArgs : BaseCliArguments
class YchArgs : PayArgs
{
[Required]
[OptionParameter("ticket", 't')]
[OptionParameter("tickets", 't')]
public int Ticket { get; set; }

[Required]
[OptionParameter("slot", 's')]
[OptionParameter("slots", 's')]
public int Slot { get; set; }
}

class RaffleArgs : GlobalArgs
{

/// <summary>
/// Artwork name
/// </summary>
[Required]
[OptionParameter("name", 'n')]
public string Name { get; set; }

/// <summary>
/// Maximum number of slots
/// </summary>
[Required]
[OptionParameter("tickets", 't')]
public int Tickets { get; set; }

/// <summary>
/// Maximum number of slots
/// </summary>
[Required]
[OptionParameter("slots", 's')]
public int Slots { get; set; }
}

/// <summary>
/// Commission arguments extend the request by adding
/// price and payment options.
Expand Down
116 changes: 116 additions & 0 deletions Src/ArtManager.CLI/CliCmd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
// Licensed under the GNU GPL v3 license. See LICENSE file in the project
// root for full license information.
using System;
using System.Diagnostics;
using System.IO;
using ArtManager.Models;
using EntryPoint;

namespace ArtManager.CLI
{
class CliCmd : BaseCliCommands
{
Art _art;
Order _order;

[DefaultCommand]
[Command("list")]
public void ListAll(string[] args)
{
if (File.Exists(ArtmConsts.DBFILE))
{
_order = new Order();
_order.DbListAll();
}
else
{
Console.WriteLine(ArtmConsts.DBERR);
}
}

[Command("req")]
public void Request(string[] args)
{
var cli = Cli.Parse<BaseArgs>(args);
_art = new Art()
{
Name = cli.Name,
Custmer = new Customer
{
Name = cli.Customer,
Contact = cli.Contact,
},
Description = cli.Description,
};
_order = new Order(_art);
_order.DBInsert();

if (cli.Debug)
_order.DbListAll();
}

[Command("com")]
public void Commission(string[] args)
{
var cli = Cli.Parse<PayArgs>(args);
_art = new Art()
{
Name = cli.Name,
Custmer = new Customer
{
Name = cli.Customer,
Contact = cli.Contact,
Payment = cli.Payment,
},
Price = cli.Price,
Description = cli.Description,
};
_order = new Order(_art);
_order.DBInsert();

if (cli.Debug)
_order.DbListAll();
}

[Command("ych")]
public void YCH(string[] args)
{
var cli = Cli.Parse<YchArgs>(args);
_art = new Art()
{
Name = cli.Name,
Custmer = new Customer
{
Name = cli.Customer,
Contact = cli.Contact,
Payment = cli.Payment,
},
Price = cli.Price,
Slot = cli.Slot,
Ticket = cli.Ticket
};
_order = new Order(_art);
_order.DBInsert();

if (cli.Debug || Debugger.IsAttached)
_order.DbListAll();
}

[Command("raf")]
public void Raffle(string[] args)
{
_order = new Order();
_order.DBRaffle(args);
}

public override void OnHelpInvoked(string helpText)
{
var monero = "44xZM7FSdJ9TpYK99Y2e4JYyprRWR3fKxJWsw4jEFL6CWtWQG35qWAPDTPDuAGy1v74bL2arKP2Eq7GVPfsWTZVs7MhKhf4";
var about = "A command line application used for storing request, commission, and YCH information.";
Console.WriteLine($"## About ##{Environment.NewLine}{about}{Environment.NewLine}");
Console.WriteLine($"{Environment.NewLine}## Donate ##{Environment.NewLine}Ko-Fi: ko-fi.com/antonwilc0x{Environment.NewLine}Monero: {monero}");
Console.WriteLine($"{Environment.NewLine}{helpText}");
}
}
}
4 changes: 2 additions & 2 deletions Src/ArtManager/Dockerfile → Src/ArtManager.CLI/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/runtime:2.1-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-buster AS build
WORKDIR /src
COPY ["ArtManager/ArtManager.csproj", "ArtManager/"]
RUN dotnet restore "ArtManager/ArtManager.csproj"
Expand Down
92 changes: 92 additions & 0 deletions Src/ArtManager.CLI/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) Anthony Wilcox and contributors. All rights reserved.
// Licensed under the GNU GPL v3 license. See LICENSE file in the project
// root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using ArtManager.Models;
using LiteDB;

namespace ArtManager.CLI
{
class Order
{
Art Art { get; set; }

public bool IsDebug { get; set; }

readonly List<Art> _arts = new List<Art>();

public Order() { }

public Order(Art order)
{
Art = order;
}

public void DBInsert()
{
try
{
using (var db = new LiteDatabase(ArtmConsts.DBFILE))
{
var art = db.GetCollection<Art>(ArtmConsts.DBCOL);
art.Insert(Art);
}
}
catch (Exception err)
{
throw new Exception(err.Message);
}
}

public void DBRaffle(string[] args)
{
/*
var cli = Cli.Parse<RaffleArgs>(args);
var rand = new Random();
var tickets = rand.Next(cli.Tickets);
var slots = rand.Next(cli.Slots);
*/

if (IsDebug)
{

}
else
{
throw new NotImplementedException();
}
}

public void DbListAll()
{
try
{
using (var db = new LiteDatabase(ArtmConsts.DBFILE))
{
var art = db.GetCollection<Art>(ArtmConsts.DBCOL);
art.EnsureIndex(x => x.Hash);
var query = art.Include(x => x.Hash)
.Include(x => x.Custmer)
.Include(x => x.Name)
.FindAll();

foreach (var q in query)
_arts.Add(q);

var json = ArtUtils.AsJson(_arts);

if (IsDebug)
Console.WriteLine(json);
else if (Debugger.IsAttached)
Debug.WriteLine(json);
}
}
catch (Exception err)
{
throw new Exception(err.Message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// root for full license information.
using EntryPoint;

namespace ArtManager
namespace ArtManager.CLI
{
class Program
{
Expand Down
Loading

0 comments on commit e62c1e5

Please sign in to comment.