-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Started new event sourcing app. * Added first endpoint * Updated example with another state change * Formatting * Added CompleteJob API * Update using * Formatting * Added some projections and read APIs * Refactored into IJobTrackerReadService.cs * Get all jobs lists for a user * Refactored into Endpoints extensions. * Renaming * nits
- Loading branch information
Showing
35 changed files
with
937 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace EventSourcingJobsTracker.API.DTOs; | ||
|
||
public record JobDto( | ||
string Id, | ||
string Title, | ||
DateTime Due, | ||
DateTime? CompletedAt = null) | ||
|
||
{ | ||
public bool IsComplete => | ||
CompletedAt is not null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace EventSourcingJobsTracker.API.DTOs; | ||
|
||
public record JobsListDto(string Id, | ||
string Username, | ||
string Category, | ||
DateTime Created); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace EventSourcingJobsTracker.API.Requests; | ||
|
||
public record CompleteJob( | ||
Guid JobListId, | ||
Guid JobId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace EventSourcingJobsTracker.API.Requests; | ||
|
||
public record CreateJob( | ||
Guid JobListId, | ||
string Title, | ||
DateTime Due); |
9 changes: 9 additions & 0 deletions
9
samples/EventSourcingJobsTracker/API/Requests/CreateJobList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace EventSourcingJobsTracker.API.Requests; | ||
|
||
public record CreateJobList( | ||
string Name, | ||
string Category, | ||
string Username); |
13 changes: 13 additions & 0 deletions
13
samples/EventSourcingJobsTracker/Application/Infrastructure/IJobListRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using EventSourcingJobsTracker.Core.Aggregates; | ||
|
||
namespace EventSourcingJobsTracker.Application.Infrastructure; | ||
|
||
public interface IJobListRepository | ||
{ | ||
ValueTask SaveAsync(JobsList jobList); | ||
|
||
ValueTask<JobsList> ReadAsync(Guid jobListId); | ||
} |
63 changes: 63 additions & 0 deletions
63
samples/EventSourcingJobsTracker/Application/Services/DefaultJobTrackerReadService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using EventSourcingJobsTracker.API.DTOs; | ||
using EventSourcingJobsTracker.Infrastructure.Items; | ||
using Microsoft.Azure.CosmosRepository; | ||
|
||
namespace EventSourcingJobsTracker.Application.Services; | ||
|
||
public class DefaultJobTrackerReadService : IJobTrackerReadService | ||
{ | ||
private readonly IReadOnlyRepository<JobsListReadItem> _jobsListRepository; | ||
private readonly IReadOnlyRepository<JobItem> _jobsRepository; | ||
|
||
public DefaultJobTrackerReadService( | ||
IReadOnlyRepository<JobsListReadItem> jobsListRepository, | ||
IReadOnlyRepository<JobItem> jobsRepository) | ||
{ | ||
_jobsListRepository = jobsListRepository; | ||
_jobsRepository = jobsRepository; | ||
} | ||
|
||
public async ValueTask<JobsListDto?> FindJobsListAsync( | ||
Guid id, | ||
string username) | ||
{ | ||
JobsListReadItem? jobsList = await _jobsListRepository.TryGetAsync( | ||
id.ToString(), | ||
username); | ||
|
||
return jobsList is null | ||
? null | ||
: new JobsListDto( | ||
jobsList.Id, | ||
jobsList.Username, | ||
jobsList.Category, | ||
jobsList.CreatedTimeUtc!.Value); | ||
} | ||
|
||
public async ValueTask<IEnumerable<JobDto>> FindJobsForJobsListAsync(Guid jobListId) | ||
{ | ||
IEnumerable<JobItem> jobs = await _jobsRepository.GetAsync(x => | ||
x.PartitionKey == jobListId.ToString()); | ||
|
||
return jobs.Select(x => new JobDto( | ||
x.Id, | ||
x.Title, | ||
x.Due, | ||
x.CompletedAt)); | ||
} | ||
|
||
public async Task<IEnumerable<JobsListDto>> FindJobsListAsync(string username) | ||
{ | ||
IEnumerable<JobsListReadItem> jobLists = await _jobsListRepository.GetAsync(x => | ||
x.PartitionKey == username); | ||
|
||
return jobLists.Select(x => new JobsListDto( | ||
x.Id, | ||
x.Username, | ||
x.Category, | ||
x.CreatedTimeUtc!.Value)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
samples/EventSourcingJobsTracker/Application/Services/DefaultJobsTrackerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using EventSourcingJobsTracker.Application.Infrastructure; | ||
using EventSourcingJobsTracker.Core.Aggregates; | ||
|
||
namespace EventSourcingJobsTracker.Application.Services; | ||
|
||
public class DefaultJobsTrackerService : IJobsTrackerService | ||
{ | ||
private readonly IJobListRepository _jobListRepository; | ||
|
||
public DefaultJobsTrackerService(IJobListRepository jobListRepository) => | ||
_jobListRepository = jobListRepository; | ||
|
||
public async ValueTask<Guid> CreateJobList( | ||
string name, | ||
string category, | ||
string username) | ||
{ | ||
JobsList jobList = new(name, category, username); | ||
|
||
await _jobListRepository.SaveAsync(jobList); | ||
|
||
return jobList.Id; | ||
} | ||
|
||
public async ValueTask AddJob( | ||
Guid jobListId, | ||
string title, | ||
DateTime due) | ||
{ | ||
JobsList jobsList = await _jobListRepository.ReadAsync(jobListId); | ||
|
||
jobsList.AddJob(title, due); | ||
|
||
await _jobListRepository.SaveAsync(jobsList); | ||
} | ||
|
||
public async ValueTask CompleteJob( | ||
Guid jobListId, | ||
Guid jobId) | ||
{ | ||
JobsList jobsList = await _jobListRepository.ReadAsync(jobListId); | ||
|
||
jobsList.CompleteJob(jobId); | ||
|
||
await _jobListRepository.SaveAsync(jobsList); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/EventSourcingJobsTracker/Application/Services/IJobTrackerReadService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using EventSourcingJobsTracker.API.DTOs; | ||
|
||
namespace EventSourcingJobsTracker.Application.Services; | ||
|
||
public interface IJobTrackerReadService | ||
{ | ||
ValueTask<JobsListDto?> FindJobsListAsync( | ||
Guid id, | ||
string username); | ||
|
||
ValueTask<IEnumerable<JobDto>> FindJobsForJobsListAsync(Guid jobListId); | ||
Task<IEnumerable<JobsListDto>> FindJobsListAsync(string username); | ||
} |
21 changes: 21 additions & 0 deletions
21
samples/EventSourcingJobsTracker/Application/Services/IJobsTrackerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) IEvangelist. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace EventSourcingJobsTracker.Application.Services; | ||
|
||
public interface IJobsTrackerService | ||
{ | ||
ValueTask<Guid> CreateJobList( | ||
string name, | ||
string category, | ||
string username); | ||
|
||
ValueTask AddJob( | ||
Guid jobListId, | ||
string title, | ||
DateTime due); | ||
|
||
ValueTask CompleteJob( | ||
Guid jobListId, | ||
Guid jobId); | ||
} |
Oops, something went wrong.