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

Task 1 - attempt 1 #6

Merged
merged 25 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1324b63
rm task 0 leftovers
Oskarowski Mar 30, 2024
1294cb8
init DataLayer in Library business process
Oskarowski Mar 30, 2024
2d38771
add few business process interfaces
Oskarowski Mar 30, 2024
092cd7b
add business process API implementations
Oskarowski Mar 30, 2024
a659599
add tests to existing data layer implementations
Oskarowski Mar 30, 2024
393ef46
add remaining business process APIs their implementations and tests
Soplicow Mar 30, 2024
4b9327c
Fixed IStatus and Status naming
Soplicow Apr 3, 2024
d2d1c38
names
Soplicow Apr 3, 2024
892ebd6
Merge branch 'dev-task-1-ok' of https://github.com/Oskarowski/tul-it-…
Soplicow Apr 5, 2024
0df8f84
Added GUIDs to remaining classes, created Borrow and Return, Started …
Soplicow Apr 6, 2024
f9d0bf2
Add Event and State implementations in DataRepository, changes in Dat…
Soplicow Apr 12, 2024
cc4edab
Add GetProductByState, GetEventsByUser, GetEventsByProduct, and GetEv…
Soplicow Apr 14, 2024
936611b
Added LogicLayer to solution, fixed existing tests
Soplicow Apr 14, 2024
18ff2bd
Fixed namespace errors as well as naming and compilation errors
Soplicow Apr 14, 2024
a4d1e4f
Added some tests for DataService.cs
Soplicow Apr 14, 2024
d23b49c
Gitignore update
Soplicow Apr 14, 2024
6ec6387
Removed .vscode files (they should have never been there)
Soplicow Apr 14, 2024
c22ab14
add new methods on User with proper tests
Oskarowski Apr 14, 2024
41dfa00
add regions and reorder to match interface
Oskarowski Apr 14, 2024
b2a17aa
hope it will prevent tracking of .vscode
Oskarowski Apr 14, 2024
b6ce82f
refactor State and it's tests
Oskarowski Apr 14, 2024
c5aed69
refactoring the code of the Event class and its consequences
Oskarowski Apr 14, 2024
110fac4
add method DoesProductExist
Oskarowski Apr 14, 2024
1452871
refactor business logic, test also
Oskarowski Apr 14, 2024
c00ac80
Fixed RandomFiller multiple unwanted events being created
Soplicow Apr 15, 2024
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
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