Skip to content

Commit eb31a6c

Browse files
committed
Added documentation to the PortfolioEntryService
1 parent 626cb56 commit eb31a6c

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

Services/Services/MarketOrderService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ MarketOrder CreateMarketOrder(decimal filledPrice, decimal fee, decimal size,
2828
bool DeleteMarketOrder(MarketOrder order);
2929

3030
/// <summary>
31-
/// Updates the given order in the repository. An order with the same ID in the repository is replaced with the one
31+
/// Updates the given order in the repository. The order with the same ID in the repository is replaced with the one
3232
/// passed.
3333
/// </summary>
3434
/// <param name="order">Updated order</param>

Services/Services/PortfolioEntryService.cs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,98 @@ namespace Services
88
{
99
public interface IPortfolioEntryService
1010
{
11+
/// <summary>
12+
/// Creates a new portfolio entry and adds it to a repository
13+
/// </summary>
14+
/// <param name="symbol">Cryptocurrency symbol</param>
15+
/// <param name="portfolioId">ID of the portfolio the entry should belong to</param>
16+
/// <returns>Created instance of the `PortfolioEntry` class</returns>
1117
PortfolioEntry CreatePortfolioEntry(string symbol, int portfolioId);
1218

19+
/// <summary>
20+
/// Deletes the given portfolio entry from a repository
21+
/// </summary>
22+
/// <param name="entry">Entry to be deleted</param>
23+
/// <returns>A flag indicating whether the entry was deleted</returns>
1324
bool DeletePortfolioEntry(PortfolioEntry entry);
1425

26+
/// <summary>
27+
///
28+
/// </summary>
29+
/// <param name="portfolioId"></param>
30+
/// <returns></returns>
1531
int DeletePortfolioEntries(int portfolioId);
1632

17-
bool UpdatePortfolio(PortfolioEntry entry);
33+
/// <summary>
34+
/// Updates the given entry in the repository. The entry with the same ID in the repository is replaced with the one.
35+
/// </summary>
36+
/// <param name="entry">Updated entry to be stored in the repository</param>
37+
/// <returns>A flag indicating whether the portfolio entry was updated</returns>
38+
bool UpdatePortfolioEntry(PortfolioEntry entry);
1839

40+
/// <summary>
41+
/// Loads and returns a portfolio entry from the database using the given ID.
42+
/// </summary>
43+
/// <param name="id">ID of the portfolio entry to be loaded</param>
44+
/// <returns>Found portfolio entry or `null`</returns>
1945
PortfolioEntry GetPortfolioEntry(int id);
2046

47+
/// <summary>
48+
/// Returns all portfolio entries that belong to the portfolio identified by the given ID
49+
/// </summary>
50+
/// <param name="portfolioId">ID of the portfolio whose entries should be found</param>
51+
/// <returns>A list of all entries that belong to the given portfolio</returns>
2152
List<PortfolioEntry> GetPortfolioEntries(int portfolioId);
2253
}
2354

2455
public class PortfolioEntryServiceImpl : IPortfolioEntryService
2556
{
26-
private IPortfolioEntryRepository _portfolioEntryRepository;
27-
private IMarketOrderService _marketOrderService;
57+
// dependency on the portfolio entry repository
58+
private readonly IPortfolioEntryRepository _portfolioEntryRepository;
59+
60+
// dependency on the market order repository
61+
private readonly IMarketOrderService _marketOrderService;
2862

2963
public PortfolioEntryServiceImpl(IPortfolioEntryRepository portfolioEntryRepository, IMarketOrderService marketOrderService)
3064
{
3165
_portfolioEntryRepository = portfolioEntryRepository;
3266
_marketOrderService = marketOrderService;
3367
}
3468

35-
3669
public PortfolioEntry CreatePortfolioEntry(string symbol, int portfolioId)
3770
{
71+
// create a new instance of the `PortfolioEntry` class
3872
var portfolioEntry = new PortfolioEntry(symbol, portfolioId);
39-
portfolioEntry = portfolioEntry with {Id = _portfolioEntryRepository.Add(portfolioEntry)};
40-
return portfolioEntry;
73+
74+
// add it to the repository and return it with the generated ID
75+
return portfolioEntry with {Id = _portfolioEntryRepository.Add(portfolioEntry)};
4176
}
4277

4378
public bool DeletePortfolioEntry(PortfolioEntry entry)
4479
{
80+
// when deleting a portfolio entry make sure to delete all of its orders
4581
_marketOrderService.DeletePortfolioEntryOrders(entry.Id);
82+
83+
// finally delete the portfolio entry
4684
return _portfolioEntryRepository.Delete(entry);
4785
}
4886

49-
public bool UpdatePortfolio(PortfolioEntry entry) => _portfolioEntryRepository.Update(entry);
87+
public bool UpdatePortfolioEntry(PortfolioEntry entry) => _portfolioEntryRepository.Update(entry);
5088

5189
public PortfolioEntry GetPortfolioEntry(int id) => _portfolioEntryRepository.Get(id);
5290

5391
public List<PortfolioEntry> GetPortfolioEntries(int portfolioId) => _portfolioEntryRepository.GetAllByPortfolioId(portfolioId);
5492

5593
public int DeletePortfolioEntries(int portfolioId)
5694
{
95+
// iterate over all entries of the given portfolio
5796
foreach (var portfolioEntry in GetPortfolioEntries(portfolioId))
5897
{
98+
// delete all orders of each iterated portfolio entry
5999
_marketOrderService.DeletePortfolioEntryOrders(portfolioEntry.Id);
60100
}
61-
101+
102+
// finally delete entries of the portfolio
62103
return _portfolioEntryRepository.DeletePortfolioEntries(portfolioId);
63104
}
64105
}

Tests/Unit/Service/PortfolioEntryServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void Update_CallsRepository()
8686
var service = new PortfolioEntryServiceImpl(repositoryMock.Object, marketOrderServiceMock.Object);
8787

8888
// act
89-
var updated = service.UpdatePortfolio(entryToBeUpdated);
89+
var updated = service.UpdatePortfolioEntry(entryToBeUpdated);
9090

9191
// assert
9292
Assert.True(updated);

0 commit comments

Comments
 (0)