Skip to content

Commit 2415e1e

Browse files
committed
Add interface method and implementation for retrieving the notes of a particular category.
1 parent 2bad95b commit 2415e1e

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/Core/Application/Services/INoteTaker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ public interface INoteTaker
2323
// Work with categorized notes
2424
CategoryDto TakeCategorizedNote(Guid categoryId, NewNoteMessage newNoteMessage);
2525
CategoryDto RemoveCategorizedNote(Guid categoryId, Guid noteId);
26+
IList<NoteDto> ListCategorizedNotes(Guid categoryId);
2627
}
2728
}

src/Infrastructure.Server/NoteTaker.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,20 @@ public CategoryDto TakeCategorizedNote(Guid categoryId, NewNoteMessage newNoteMe
163163
throw new ArgumentNullException(nameof(newNoteMessage));
164164
}
165165

166-
var category = _categoryRepository.Get(categoryId);
167-
if (null == category) throw new NotFoundException("Category not found.");
168-
169-
category = _categoryFactory.Build(
170-
category,
171-
_noteFactory,
172-
_subscriberFactory
173-
);
166+
var category = GetCategory(categoryId);
174167

175168
category.AddNote(newNoteMessage.Text);
176169
category = _categoryRepository.Save(category);
177170

178171
return _mapper.Map<CategoryDto>(category);
179172
}
180173

174+
public IList<NoteDto> ListCategorizedNotes(Guid categoryId)
175+
{
176+
var category = GetCategory(categoryId);
177+
return _mapper.Map<IList<NoteDto>>(category.Notes);
178+
}
179+
181180
private ICategory GetDefaultCategory()
182181
{
183182
var defaultCategoryName = "default";
@@ -200,5 +199,19 @@ private ICategory GetDefaultCategory()
200199

201200
return category;
202201
}
202+
203+
private ICategory GetCategory(Guid categoryId)
204+
{
205+
var category = _categoryRepository.Get(categoryId);
206+
if (null == category) throw new NotFoundException("Category not found.");
207+
208+
category = _categoryFactory.Build(
209+
category,
210+
_noteFactory,
211+
_subscriberFactory
212+
);
213+
214+
return category;
215+
}
203216
}
204217
}

0 commit comments

Comments
 (0)