Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: .NET

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
- name: Change Directory
run: cd Tyche
- name: Restore dependencies
run: dotnet restore Tyche/Tyche.sln
- name: Build
run: dotnet build Tyche/Tyche.sln --no-restore
- name: Test
run: dotnet test Tyche/Tyche.sln --no-build --verbosity normal
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
# Tyche
Deck sorter project: a simple project that implements a RESTful API service for sorting a deck of cards by certain parameters
<h1 align="center">Tyche</h1>

<p align="center">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" >
<img src="https://img.shields.io/badge/made%20by-includingByMeAndMyself-red.svg" >
<img src="https://img.shields.io/github/issues/silent-lad/VueSolitaire.svg">
</p>


<h2>Описание:</h2>
<p>Простой проект, реализующий сервис RESTful API для сортировки колоды карт по определенным параметрам.</p>
<p>Этот проект состоит из серверной части, которая представляет из себя монолитный REST web API проект, включает:</p>
<ul>
<li>Tyche.API</li>
<li>Tyche.BusinessLogic</li>
<li>Tyche.DataAccess.MsSql</li>
<li>Tyche.Domain</li>
</ul>
<p>И из клиентской части, которая представляет из себя консольное приложение с простым интерфейсом взаимодествия:</p>
<ul>
<li>Client.CLI</li>
</ul>
<p>Основной функционал приложения:</p>

```
1 - Создать именованную колоду карт;
2 - Получить созданную колоду карт, выбранную по названию колоды;
3 - Получить список названий созданных колод карт;
4 - Получить все созданные колоды карт;
5 - Удалить все созданные колоды карт;
6 - Удалить созданную колоду карт, выбранную по названию колоды;
7 - Перетасовать колоду карт, выбранную по названию колоды.
```
<h2>Как запускать:</h2>
<p>Строка подключения располагается в <strong>Tyche.API/appsettings.json</strong> (Можно заменить на свою строку подключения)</p>

```
"DeckContext": "Data Source=(LocalDb)\\MSSQLLocalDB;Database=Deck_DB;Trusted_Connection=True;MultipleActiveResultSets=true"
```

<p>Для успешного запуска приложения необходимо выполнить команду на выбор:</p>
<ul>
<li>Для консоли диспетчера пакетов:</li>

```
Update-Database
```
<li>Для окна командной строки:</li>

```
dotnet ef database update
```
</ul>

<h2>Используемые технологии:</h2>
<p>Серверная и клиентская часть выполненны на <strong>c# .NET Core 5, ASP Web API</strong><p>
<p>Для хранения данных используется <strong>LocalDb</strong><p>
<p>Для работы с базой данных используется ORM <strong>entity framework core 5</strong><p>
13 changes: 13 additions & 0 deletions Tyche/Client.CLI/Client.CLI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.SignalR.Client" Version="2.4.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
248 changes: 248 additions & 0 deletions Tyche/Client.CLI/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
using Client.CLI.Infrastructure;
using Client.CLI.Interfaces;
using System;


namespace Client.CLI
{
internal partial class Client
{
private IDeckHttpClient _deckHttpClient;
private const int WIDTH_CONSOLE = 120;
private const int HIGHT_CONSOLE = 30;

public Client(IDeckHttpClient deckHttpClient)
{
_deckHttpClient = deckHttpClient;
Console.SetWindowSize(WIDTH_CONSOLE, HIGHT_CONSOLE);

}

internal void Start()
{
Console.Title= "Tyche Client";
Console.WriteLine("Client started");

var isUserContinue = true;
string userAnswer;

do
{
Console.Clear();

PrintLine();
PrintMenu();
PrintLine();

Console.Write("\n\tSelect a menu item: ");

userAnswer = Console.ReadLine();

Console.Clear();

switch (userAnswer)
{
case "1":
CreateNamedDeckAsync();
break;
case "2":
GetDeckByNameAsync();
break;
case "3":
GetCreatedDecksNamesAsync();
break;
case "4":
GetDecksAsync();
break;
case "5":
DeleteDecksAsync();
break;
case "6":
DeleteDeckByNameAsync();
break;
case "7":
ShuffleDeckByNameAsync();
break;
case "8":
break;
default :
continue;
}

Console.ForegroundColor = ConsoleColor.Red;
Console.Write("\n\tAre you sure you want to quit? (y/n): ");
userAnswer = Console.ReadLine();
Console.ResetColor();

isUserContinue = userAnswer.ToLower() == "n";

} while (isUserContinue);
}

public void CreateNamedDeckAsync()
{
var mesg = "\tEnter Decks name: ";
PrintLineGreen(mesg);

var name = Console.ReadLine();

Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\tDecks Type:" +
"\r\n\t\"52\" if you want create StandartDeck = 52 cards " +
"\r\n\t\"36\" if you want create SmallDeck = 36 cards");
Console.Write("\r\n\tEnter Decks Type: ");
Console.ResetColor();
var type = Console.ReadLine();

var deckType = type.ToDeckType();

var response = _deckHttpClient.CreateNamedDeckAsync(name, deckType);

if(response.Result != null)
Console.WriteLine("\r\n\t" + response.Result);
}

public void GetCreatedDecksNamesAsync()
{
Console.WriteLine();

var response = _deckHttpClient.GetCreatedDecksNamesAsync();
var count = 1;

if(response.Result != null)
{
var mesg = "\r\n\tNames of deck(s):";
PrintGreen(mesg);

foreach (var name in response.Result)
{
Console.WriteLine($"\r\n\t{count}) " + name);
count++;
}
}
else
{
Console.WriteLine("\r\n\tNo decks of cards created");
}
}

public void GetDeckByNameAsync()
{
var mesg = "\tEnter Decks name: ";
PrintLineGreen(mesg);

var name = Console.ReadLine();

var response = _deckHttpClient.GetDeckByNameAsync(name);
if (response.Result != null)
{
response.Result.ShowDeck();
}
else
{
Console.WriteLine($"\r\n\tNo deck of cards whit name {name} created");
}
}

public void GetDecksAsync()
{
var response = _deckHttpClient.GetDecksAsync();

if (response.Result != null)
{
foreach (var deck in response.Result)
{
deck.ShowDeck();
}
}
else
{
Console.WriteLine($"\r\n\tHave no decks of cards");
}
}

public void DeleteDeckByNameAsync()
{
var mesg = "\tEnter Decks name: ";
PrintLineGreen(mesg);
var name = Console.ReadLine();

var response = _deckHttpClient.DeleteDeckByNameAsync(name);

if (response.Result != null)
Console.WriteLine("\r\n\t" + response.Result);
}

public void DeleteDecksAsync()
{
var response = _deckHttpClient.DeleteDecksAsync();
if (response.Result != null)
Console.WriteLine("\r\n\t" + response.Result);
}

public void ShuffleDeckByNameAsync()
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\tEnter Decks name: ");
Console.ResetColor();

var name = Console.ReadLine();

Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\tShuffle Option:" +
"\r\n\t\"1\" if you want to shuffle a deck of cards" +
"\r\n\t\"2\" if you want to shuffle the deck of cards in order");
Console.Write("\r\n\tEnter Shuffle Option: ");
Console.ResetColor();
var type = Console.ReadLine();

var shuffleType = type.ToShuffleOption();

var response = _deckHttpClient.ShuffleDeckByNameAsync(shuffleType, name);

if (response.Result != null)
Console.WriteLine("\r\n\t" + response.Result);
}

private static void PrintLineGreen(string mesg)
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(mesg);
Console.ResetColor();
}

private static void PrintGreen(string mesg)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\r\n\tNames of deck(s):");
Console.ResetColor();
}

private static void PrintLine()
{
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Cyan;
Console.WriteLine(new string(' ', WIDTH_CONSOLE));
Console.ResetColor();
Console.WriteLine();
}

private static void PrintMenu()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t1 - Create named deck;" +
"\n\t2 - Getting a deck of cards by name;" +
"\n\t3 - Get list of deck names;" +
"\n\t4 - Getting all decks of cards;" +
"\n\t5 - Deleting all deck of cards;" +
"\n\t6 - Deleting deck of cards by name;" +
"\n\t7 - Shuffle named deck in the selected way;" +
"\n\t8 - Exit;");
Console.ResetColor();
}
}
}
Loading