Skip to content

Commit 3d4206b

Browse files
committed
Added documentation summaries to MarketOrderService and PortfolioEntryService
Added documentation to the PortfolioService
1 parent eb31a6c commit 3d4206b

File tree

3 files changed

+59
-21
lines changed

3 files changed

+59
-21
lines changed

Services/Services/MarketOrderService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Services
77
{
8+
/// <summary>
9+
/// A service that is responsible for managing market orders and storing them to a persistent repository.
10+
/// </summary>
811
public interface IMarketOrderService
912
{
1013
/// <summary>

Services/Services/PortfolioEntryService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Services
88
{
9+
/// <summary>
10+
/// A service that is responsible for managing portfolio entries and storing them to a persistent repository.
11+
/// </summary>
912
public interface IPortfolioEntryService
1013
{
1114
/// <summary>

Services/Services/PortfolioService.cs

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,87 @@
66

77
namespace Services
88
{
9+
/// <summary>
10+
/// A service that is responsible for managing portfolios and storing them to a persistent repository.
11+
/// </summary>
912
public interface IPortfolioService
1013
{
14+
/// <summary>
15+
/// Creates a new portfolio and stores it to a repository
16+
/// </summary>
17+
/// <param name="name">Name of the portfolio</param>
18+
/// <param name="description">Description of the portfolio</param>
19+
/// <param name="currency">Currency to be used within the portfolio</param>
20+
/// <returns>A created instance of the `Portfolio` class</returns>
1121
Portfolio CreatePortfolio(string name, string description, Currency currency);
22+
23+
/// <summary>
24+
/// Deletes the given portfolio from the repository
25+
/// </summary>
26+
/// <param name="portfolio">Portfolio to be deleted from the repository</param>
27+
/// <returns>A flag indicating whether the portfolio was deleted</returns>
1228
bool DeletePortfolio(Portfolio portfolio);
29+
30+
/// <summary>
31+
/// Updates the given portfolio in the repository. The portfolio with the same ID in the repository is replaced with the one.
32+
/// </summary>
33+
/// <param name="portfolio">Updated portfolio to be stored in the repository</param>
34+
/// <returns>A flag indicating whether the portfolio was updated</returns>
1335
bool UpdatePortfolio(Portfolio portfolio);
36+
37+
/// <summary>
38+
/// Loads and returns a portfolio specified by the given ID from the repository.
39+
/// </summary>
40+
/// <param name="id">ID of the portfolio to be loaded from the repository</param>
41+
/// <returns>An instance of the `Portfolio` class that was loaded from the repository</returns>
1442
Portfolio GetPortfolio(int id);
43+
44+
/// <summary>
45+
/// Returns a list of all portfolios present in the repository
46+
/// </summary>
47+
/// <returns>List of all portfolios present in the repository</returns>
1548
List<Portfolio> GetPortfolios();
1649
}
1750

1851
public class PortfolioServiceImpl : IPortfolioService
1952
{
20-
private IPortfolioRepository _portfolioRepository;
21-
private IPortfolioEntryService _portfolioEntryService;
53+
// dependency on the portfolio repository
54+
private readonly IPortfolioRepository _portfolioRepository;
55+
56+
// dependency on the portfolio entry service (in order to be able to delete entries when deleting a portfolio)
57+
private readonly IPortfolioEntryService _portfolioEntryService;
2258

23-
public PortfolioServiceImpl(IPortfolioRepository portfolioRepository, IPortfolioEntryService portfolioEntryService)
59+
public PortfolioServiceImpl(IPortfolioRepository portfolioRepository,
60+
IPortfolioEntryService portfolioEntryService)
2461
{
25-
this._portfolioRepository = portfolioRepository;
26-
this._portfolioEntryService = portfolioEntryService;
62+
_portfolioRepository = portfolioRepository;
63+
_portfolioEntryService = portfolioEntryService;
2764
}
2865

2966
public Portfolio CreatePortfolio(string name, string description, Currency currency)
3067
{
31-
var potfolio = new Portfolio(name, description, currency);
32-
var id = _portfolioRepository.Add(potfolio);
33-
return potfolio with
68+
// create a new `Portfolio` class instance
69+
var portfolio = new Portfolio(name, description, currency);
70+
return portfolio with
3471
{
35-
Id = id
72+
Id = _portfolioRepository.Add(portfolio)
3673
};
3774
}
3875

3976
public bool DeletePortfolio(Portfolio portfolio)
4077
{
78+
// first, delete all portfolio entries that belong to the portfolio being deleted
4179
_portfolioEntryService.DeletePortfolioEntries(portfolio.Id);
80+
81+
// then finally delete the given portfolio
4282
return _portfolioRepository.Delete(portfolio);
4383
}
4484

45-
public bool UpdatePortfolio(Portfolio portfolio)
46-
{
47-
return _portfolioRepository.Update(portfolio);
48-
}
85+
public bool UpdatePortfolio(Portfolio portfolio) => _portfolioRepository.Update(portfolio);
4986

50-
public Portfolio GetPortfolio(int id)
51-
{
52-
return _portfolioRepository.Get(id);
53-
}
87+
public Portfolio GetPortfolio(int id) => _portfolioRepository.Get(id);
5488

55-
public List<Portfolio> GetPortfolios()
56-
{
57-
return _portfolioRepository.GetAll();
58-
}
89+
public List<Portfolio> GetPortfolios() => _portfolioRepository.GetAll();
90+
5991
}
6092
}

0 commit comments

Comments
 (0)