-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82c40c8
commit b333a3c
Showing
12 changed files
with
199 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Application.Activities; | ||
using Domain; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Persistence; | ||
|
||
namespace API.Controllers | ||
{ | ||
public class ActivitiesController : BaseApiController | ||
{ | ||
private readonly DataContext _context; | ||
|
||
public ActivitiesController(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<ActionResult<List<Activity>>> GetActivities() | ||
{ | ||
return await _context.Activities.ToListAsync(); | ||
return await Mediator.Send(new List.Query()); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
public async Task<ActionResult<Activity>> GetActivity(Guid id) | ||
{ | ||
return await _context.Activities.FindAsync(id); | ||
return await Mediator.Send(new Details.Query { Id = id }); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> CreateActivity(Activity activity) | ||
{ | ||
return Ok(await Mediator.Send(new Create.Command { Activity = activity })); | ||
} | ||
|
||
[HttpPut("{id}")] | ||
public async Task<IActionResult> EditActivity(Guid id, Activity activity) | ||
{ | ||
activity.Id = id; | ||
return Ok(await Mediator.Send(new Edit.Command { Activity = activity })); | ||
} | ||
} | ||
} |
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
Binary file not shown.
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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Domain; | ||
using MediatR; | ||
using Persistence; | ||
|
||
namespace Application.Activities | ||
{ | ||
public class Create | ||
{ | ||
public class Command : IRequest | ||
{ | ||
public Activity Activity { get; set; } | ||
} | ||
|
||
public class Handler : IRequestHandler<Command> | ||
{ | ||
private readonly DataContext _context; | ||
public Handler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
_context.Activities.Add(request.Activity); | ||
|
||
await _context.SaveChangesAsync(); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
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,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Domain; | ||
using MediatR; | ||
using Persistence; | ||
|
||
namespace Application.Activities | ||
{ | ||
public class Details | ||
{ | ||
public class Query : IRequest<Activity> | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
|
||
public class Handler : IRequestHandler<Query, Activity> | ||
{ | ||
private readonly DataContext _context; | ||
public Handler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Activity> Handle(Query request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Activities.FindAsync(request.Id); | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using Domain; | ||
using MediatR; | ||
using Persistence; | ||
|
||
namespace Application.Activities | ||
{ | ||
public class Edit | ||
{ | ||
public class Command : IRequest | ||
{ | ||
public Activity Activity { get; set; } | ||
} | ||
|
||
public class Handler : IRequestHandler<Command> | ||
{ | ||
private readonly DataContext _context; | ||
private readonly IMapper _mapper; | ||
public Handler(DataContext context, IMapper mapper) | ||
{ | ||
_mapper = mapper; | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var activity = await _context.Activities.FindAsync(request.Activity.Id); | ||
|
||
_mapper.Map(request.Activity, activity); | ||
|
||
await _context.SaveChangesAsync(); | ||
return Unit.Value; | ||
} | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Domain; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Persistence; | ||
|
||
namespace Application.Activities | ||
{ | ||
public class List | ||
{ | ||
public class Query : IRequest<List<Activity>> | ||
{ | ||
|
||
} | ||
|
||
public class Handler : IRequestHandler<Query, List<Activity>> | ||
{ | ||
private readonly DataContext _context; | ||
|
||
public Handler(DataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<List<Activity>> Handle(Query request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Activities.ToListAsync(); | ||
} | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using Domain; | ||
|
||
namespace Application.Core | ||
{ | ||
public class MappingProfiles : Profile | ||
{ | ||
public MappingProfiles() | ||
{ | ||
CreateMap<Activity, Activity>(); | ||
} | ||
} | ||
} |