Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from Oskarowski/dev-task-1-wk
Browse files Browse the repository at this point in the history
Task 1 - attempt 1
  • Loading branch information
Oskarowski committed Apr 15, 2024
2 parents 8435c99 + c00ac80 commit 9f9457c
Show file tree
Hide file tree
Showing 31 changed files with 1,136 additions and 157 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ FodyWeavers.xsd




.vscode/
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
.vscode/settings.json
.vscode/tasks.json
.vscode/launch.json
.vscode/extensions.json
.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/
Expand Down
42 changes: 42 additions & 0 deletions Library.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataLayer", "Library\DataLayer\DataLayer.csproj", "{37F35CAD-0E16-44DE-B1EC-B8806B87AF27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Library\Tests\Tests.csproj", "{E482E32E-3CA7-46DD-83C9-B094E0AD8BA3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Library", "Library", "{B858A003-F5DD-4F95-99D9-5A7560A0B8CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogicLayer", "Library\LogicLayer\LogicLayer.csproj", "{34D82E95-A0C6-4C12-8BB0-6836280E2491}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{37F35CAD-0E16-44DE-B1EC-B8806B87AF27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37F35CAD-0E16-44DE-B1EC-B8806B87AF27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37F35CAD-0E16-44DE-B1EC-B8806B87AF27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37F35CAD-0E16-44DE-B1EC-B8806B87AF27}.Release|Any CPU.Build.0 = Release|Any CPU
{E482E32E-3CA7-46DD-83C9-B094E0AD8BA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E482E32E-3CA7-46DD-83C9-B094E0AD8BA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E482E32E-3CA7-46DD-83C9-B094E0AD8BA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E482E32E-3CA7-46DD-83C9-B094E0AD8BA3}.Release|Any CPU.Build.0 = Release|Any CPU
{34D82E95-A0C6-4C12-8BB0-6836280E2491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34D82E95-A0C6-4C12-8BB0-6836280E2491}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34D82E95-A0C6-4C12-8BB0-6836280E2491}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34D82E95-A0C6-4C12-8BB0-6836280E2491}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B8DC2F37-8FC7-433C-BA78-56CAE077B47B}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{34D82E95-A0C6-4C12-8BB0-6836280E2491} = {B858A003-F5DD-4F95-99D9-5A7560A0B8CF}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions Library/DataLayer/API/IBook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DataLayer.API
{
public interface IBook : IProduct
{
string Author { get; set; }
string Publisher { get; set; }
int Pages { get; set; }
DateTime PublicationDate { get; set; }
}
}
13 changes: 13 additions & 0 deletions Library/DataLayer/API/IDataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace DataLayer.API
{
public interface IDataContext
{
public List<IUser> Users { get; set; }

public List<IProduct> Products { get; set; }

public List<IEvent> Events { get; set; }

public List<IState> States { get; set; }
}
}
7 changes: 7 additions & 0 deletions Library/DataLayer/API/IDataFiller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DataLayer.API
{
public interface IDataFiller
{
void Fill(IDataContext context);
}
}
48 changes: 48 additions & 0 deletions Library/DataLayer/API/IDataRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using DataLayer.Implementations;

namespace DataLayer.API
{
public interface IDataRepository
{
static IDataRepository CreateDataRepository(IDataContext dataContext)
{
return new DataRepository(dataContext);
}

#region User
void AddUser(IUser user);
IUser GetUser(string guid);
List<IUser> GetAllUsers();
void RemoveUser(string guid);
bool DoesUserExist(string guid);
void UpdateUser(IUser updateUser);
#endregion

#region Product
void AddProduct(IProduct product);
IProduct GetProduct(string guid);
List<IProduct> GetAllProducts();
IProduct GetProductByState(string stateGuid);
bool DoesProductExist(string guid);

void RemoveProduct(string guid);
#endregion

#region Event
void AddEvent(IEvent @event);
IEvent GetEvent(string guid);
List<IEvent> GetAllEvents();
List<IEvent> GetEventsByUser(string userGuid);
List<IEvent> GetEventsByProduct(string productGuid);
List<IEvent> GetEventsByState(string stateGuid);
void RemoveEvent(string guid);
#endregion

#region State
void AddState(IState state);
IState GetState(string guid);
List<IState> GetAllStates();
void RemoveState(string guid);
#endregion
}
}
10 changes: 10 additions & 0 deletions Library/DataLayer/API/IEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DataLayer.API
{
public interface IEvent
{
string Guid { get; }
IUser User { get; }
IState State { get; }
DateTime CreatedAt { get; }
}
}
9 changes: 9 additions & 0 deletions Library/DataLayer/API/IProduct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DataLayer.API
{
public interface IProduct
{
string Guid { get; }
string Name { get; set; }
double Price { get; set; }
}
}
10 changes: 10 additions & 0 deletions Library/DataLayer/API/IState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DataLayer.API
{
public interface IState
{
IProduct Product { get; set; }
int Quantity { get; set; }
DateTime LastUpdatedDate { get; }
string Guid { get; }
}
}
16 changes: 16 additions & 0 deletions Library/DataLayer/API/IUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace DataLayer.API
{
public interface IUser
{
// guid, because is more commonly used in contexts of the Microsoft ecosystem
string Guid { get; }
string FirstName { get; set; }
string LastName { get; set; }
string Email { get; set; }
double Balance { get; set; }
// stick to E.164 standard?
int PhoneNumber { get; set; }
// string Role { get; set; }
Dictionary<string, IProduct> ProductsDic { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
</Project>
25 changes: 25 additions & 0 deletions Library/DataLayer/Implementations/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using DataLayer.API;

namespace DataLayer.Implementations
{
public class Book : IBook
{
public Book(string name, double price, string author, string publisher, int pages, DateTime publicationDate)
{
Guid = System.Guid.NewGuid().ToString();
Name = name;
Price = price;
Author = author;
Publisher = publisher;
Pages = pages;
PublicationDate = publicationDate;
}
public string Guid { get; }
public string Name { get; set; }
public double Price { get; set; }
public string Author { get; set; }
public string Publisher { get; set; }
public int Pages { get; set; }
public DateTime PublicationDate { get; set; }
}
}
21 changes: 21 additions & 0 deletions Library/DataLayer/Implementations/DataContex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using DataLayer.API;

namespace DataLayer.Implementations
{
public class DataContext : IDataContext
{
public List<IUser> Users { get; set; }
public List<IProduct> Products { get; set; }
public List<IEvent> Events { get; set; }
public List<IState> States { get; set; }

public DataContext()
{
Users = new List<IUser>();
Products = new List<IProduct>();
Events = new List<IEvent>();
States = new List<IState>();
}

}
}
37 changes: 37 additions & 0 deletions Library/DataLayer/Implementations/DataFillers/PresetFiller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using DataLayer.API;
using DataLayer.Implementations.Events;

namespace DataLayer.Implementations
{
public class PresetFiller : IDataFiller
{
public void Fill(IDataContext context)
{
context.Users.Add(new User("John", "Doe", "johndoe@email", 100, 123456789, null));
context.Users.Add(new User("Jane", "Doe", "janedoe@email", 200, 111111111, null));
context.Users.Add(new User("Alice", "Smith", "alicesmith@email", 300, 121212121, null));
context.Users.Add(new User("Bob", "Smith", "bobsmith@email", 400, 987654321, null));
context.Users.Add(new User("Charlie", "Brown", "charliebrown@email", 500, 999999999, null));

context.Products.Add(new Book("Old Man and the Sea", 10, "Ernest Hemingway", "Charles Sons", 300, new DateTime(1952, 1, 1)));
context.Products.Add(new Book("The Great Gatsby", 20, "F. Scott Fitzgerald", "Charles Sons", 400, new DateTime(1925, 1, 1)));
context.Products.Add(new Book("To Kill a Mockingbird", 30, "Harper Lee", "Charles Sons", 500, new DateTime(1960, 1, 1)));
context.Products.Add(new Book("1984", 40, "George Orwell", "Charles Sons", 600, new DateTime(1949, 1, 1)));
context.Products.Add(new Book("Brave New World", 50, "Aldous Huxley", "Charles Sons", 700, new DateTime(1932, 1, 1)));

context.States.Add(new State(context.Products[0], 5));
context.States.Add(new State(context.Products[1], 5));
context.States.Add(new State(context.Products[2], 5));
context.States.Add(new State(context.Products[3], 5));
context.States.Add(new State(context.Products[4], 5));

context.Events.Add(new Borrow(context.Users[0], context.States[0]));
context.Events.Add(new Borrow(context.Users[1], context.States[1]));
context.Events.Add(new Borrow(context.Users[3], context.States[3]));
context.Events.Add(new Return(context.Users[0], context.States[0]));
context.Events.Add(new Return(context.Users[1], context.States[1]));
context.Events.Add(new Return(context.Users[3], context.States[3]));
context.Events.Add(new Delivery(context.Users[4], context.States[4], 10));
}
}
}
Loading

0 comments on commit 9f9457c

Please sign in to comment.