Skip to content

Commit

Permalink
removed the in between classes for the last time
Browse files Browse the repository at this point in the history
  • Loading branch information
Stormgate1998 committed Oct 5, 2023
1 parent d4b7fc8 commit 0ee445b
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 179 deletions.
7 changes: 0 additions & 7 deletions src/combined/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,4 @@ public async Task<IEnumerable<DtoDonation>> GetTeamDonations( long teamID)
return await service.GetTeamDonationsAsync(teamID);
}

/*[HttpGet("donations/event/{eventID}")]
public async Task<IEnumerable<DtoDonation>> GetEventDonations(long eventID)
{
return await service.GetEventDonationsAsync(eventID);
}*/
}

public record UserClaim(string claim, string value);
1 change: 0 additions & 1 deletion src/combined/Controllers/StripeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using static System.Net.WebRequestMethods;
using System.Net;
using shared;
//using DtoPerson = v2.Models.Entities.DtoPerson;
using v2.DataAccess;
using AutoMapper;
using Serilog;
Expand Down
1 change: 0 additions & 1 deletion src/combined/DataAccess/TeamRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
public interface ITeamRepository
{
Task<DtoTeam> AddAsync(DtoTeam team);
//Task DeleteTeamAsync(Team team);
Task<DtoTeam> EditTeamAsync(DtoTeam team);
Task<DtoTeam> GetTeamByIdAsync(long id);
Task<IEnumerable<DtoTeam>> GetByEventIdAsync(long eventID);
Expand Down
6 changes: 3 additions & 3 deletions src/v2/api/api/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ public IEnumerable<UserClaim> Get() =>
//public async Task<IEnumerable<DtoDonation>> GetEventDonations(long eventID)
//{
// //var donations = await donationRepository.GetByEventIdAsync(eventID);
// return mapper.Map<IEnumerable<Donation>, IEnumerable<DtoDonation>>(donations);
// return mapper.Map<IEnumerable<DtoDonation>, IEnumerable<DtoDonation>>(donations);
//}

[HttpGet("donation/{eventID}/{teamID}")]
public async Task<IEnumerable<DtoDonation>> GetTeamDonations( long teamID)
{
var donations = await donationRepository.GetByTeamIdAsync(teamID);
return mapper.Map<IEnumerable<Donation>, IEnumerable<DtoDonation>>(donations);
return mapper.Map<IEnumerable<DtoDonation>, IEnumerable<DtoDonation>>(donations);
}

[HttpGet("donations/event/{eventID}")]
public async Task<IEnumerable<DtoDonation>> GetEventDonations(long eventID)
{
var donations = await donationRepository.GetByEventIdAsync(eventID);
return mapper.Map<IEnumerable<Donation>, IEnumerable<DtoDonation>>(donations);
return mapper.Map<IEnumerable<DtoDonation>, IEnumerable<DtoDonation>>(donations);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/api/api/Controllers/DonationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<ActionResult<DtoDonation>> Add([FromBody] DtoDonation dtoDonat
if (dtoDonation.ID != 0)
return BadRequest("Cannot add with a valid id");

var donation = mapper.Map<Donation>(dtoDonation);
var donation = mapper.Map<DtoDonation>(dtoDonation);
var newDonation = await donationRepository.AddAsync(donation);
return mapper.Map<DtoDonation>(newDonation);
}
Expand Down
4 changes: 2 additions & 2 deletions src/v2/api/api/Controllers/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task<ActionResult<DtoEvent>> Add([FromBody] DtoEvent dtoEvent)

try
{
var @event = mapper.Map<Event>(dtoEvent);
var @event = mapper.Map<DtoEvent>(dtoEvent);
log.LogInformation("Mapped {dtoEvent} to {event}", dtoEvent, @event);
var newEvent = await eventRepository.AddAsync(@event);
log.LogInformation("Got back {newEvent} from event repository", newEvent);
Expand All @@ -75,7 +75,7 @@ public async Task<IActionResult> Edit([FromBody] DtoEvent dtoEvent)
if (!ModelState.IsValid)
return BadRequest(getModelStateErrorMessage());

var e = mapper.Map<Event>(dtoEvent);
var e = mapper.Map<DtoEvent>(dtoEvent);
await eventRepository.EditAsync(e);
return Ok("Event edit was successful");
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2/api/api/Controllers/LinkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<ActionResult<DtoLink>> Add([FromBody] DtoLink dtoLink)
if (dtoLink.ID != 0)
return BadRequest("Cannot add with a valid id");

var link = mapper.Map<Link>(dtoLink);
var link = mapper.Map<DtoLink>(dtoLink);
var newLink = await linkRepository.Add(link);
return mapper.Map<DtoLink>(newLink);

Expand Down
2 changes: 1 addition & 1 deletion src/v2/api/api/Controllers/LinkRecordContorller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<ActionResult<DtoLinkRecord>> AddAsync([FromBody] DtoLinkRecord
if (dtoLinkRecord.ID != 0)
return BadRequest("Cannot add with a valid id");

var linkRecord = mapper.Map<LinkRecord>(dtoLinkRecord);
var linkRecord = mapper.Map<DtoLinkRecord>(dtoLinkRecord);
var newLinkRecord = await linkRecordRepository.Add(linkRecord);
return mapper.Map<DtoLinkRecord>(newLinkRecord);

Expand Down
2 changes: 1 addition & 1 deletion src/v2/api/api/Controllers/PersonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task<ActionResult<DtoPerson>> Edit([FromBody] DtoPerson dtoPerson)
if (!await personRepository.ExistsAsync(dtoPerson.ID))
return NotFound("Person id does not exist");

var person = mapper.Map<Person>(dtoPerson);
var person = mapper.Map<DtoPerson>(dtoPerson);
var updatedPerson = await personRepository.EditAsync(person);
return mapper.Map<DtoPerson>(updatedPerson);
}
Expand Down
4 changes: 2 additions & 2 deletions src/v2/api/api/Controllers/PersonTeamAssociationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<ActionResult<DtoTeam>> GetTeamAsync(long personId, long eventI
public async Task<IActionResult> SwitchTeam([FromBody] DtoPersonTeamAssociation dtoPersonTeamAssociation)
{

var updatedPersonTeamAssociation = mapper.Map<PersonTeamAssociation>(dtoPersonTeamAssociation);
var updatedPersonTeamAssociation = mapper.Map<DtoPersonTeamAssociation>(dtoPersonTeamAssociation);
await personTeamAssociationRepository.SwitchTeamAsync(updatedPersonTeamAssociation);
return Ok("Team switch was successful");

Expand All @@ -43,7 +43,7 @@ public async Task<IActionResult> SwitchTeam([FromBody] DtoPersonTeamAssociation
[HttpPost]
public async Task<ActionResult<DtoPersonTeamAssociation>> Add([FromBody] DtoPersonTeamAssociation dtoPersonTeamAssociation){

var tempPersonTeam = mapper.Map<PersonTeamAssociation>(dtoPersonTeamAssociation);
var tempPersonTeam = mapper.Map<DtoPersonTeamAssociation>(dtoPersonTeamAssociation);
var newPersonTeamAssociation = await personTeamAssociationRepository.AddAsync(tempPersonTeam);
return mapper.Map<DtoPersonTeamAssociation>(newPersonTeamAssociation);
}
Expand Down
5 changes: 2 additions & 3 deletions src/v2/api/api/Controllers/StripeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using static System.Net.WebRequestMethods;
using System.Net;
using shared;
using Person = Api.Models.Entities.Person;
using Api.DataAccess;
using AutoMapper;
using Serilog;
Expand Down Expand Up @@ -92,7 +91,7 @@ public async Task<ActionResult> Index()
personId = long.Parse(currentCustomer.Name);
}

var paymentFailed = new PaymentFailure
var paymentFailed = new DtoPaymentFailure
{
Amount = responseObject.data.@object.amount,
Decline_Code = responseObject.data.@object.last_payment_error.decline_code,
Expand Down Expand Up @@ -140,7 +139,7 @@ public async Task<ActionResult> CheckoutSuccess(long? teamId, long? personId,str
var paymentIntentId = s.PaymentIntentId;


var newDonation = new Donation {
var newDonation = new DtoDonation {
TeamID=teamId,
PersonID=personId,
Amount=amount/100,
Expand Down
18 changes: 9 additions & 9 deletions src/v2/api/api/Controllers/TeamController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public TeamController(ITeamRepository teamRepository, IMapper mapper, ILogger<Te
[HttpGet("event/{eventId}")]
public async Task<ActionResult<IEnumerable<DtoTeam>>> GetByEventID(long eventId)
{
Log.Information("Getting Team by event {eventId}", eventId);
Log.Information("Getting DtoTeam by event {eventId}", eventId);
try
{
var teams = mapper.Map<IEnumerable<DtoTeam>>(await teamRepository.GetByEventIdAsync(eventId));
return new ActionResult<IEnumerable<DtoTeam>>(teams);
}
catch (NotFoundException<IEnumerable<Team>> ex)
catch (NotFoundException<IEnumerable<DtoTeam>> ex)
{
Log.Information(ex.Message, "Event Not Found");
return NotFound(ex.Message);
Expand All @@ -58,7 +58,7 @@ public async Task<ActionResult<IEnumerable<DtoTeam>>> GetUsersTeamsForEvent(long
var teams = mapper.Map<IEnumerable<DtoTeam>>(await teamRepository.GetUsersTeamsByEventIdAsync(eventId, userId));
return new ActionResult<IEnumerable<DtoTeam>>(teams);
}
catch (NotFoundException<IEnumerable<Team>> ex)
catch (NotFoundException<IEnumerable<DtoTeam>> ex)
{
Log.Information(ex.Message, "Event Not Found");
return NotFound(ex.Message);
Expand Down Expand Up @@ -90,9 +90,9 @@ public async Task<ActionResult<DtoTeam>> Add([FromBody] DtoTeam dtoTeam)



var team = mapper.Map<Team>(dtoTeam);
var team = mapper.Map<DtoTeam>(dtoTeam);
var newTeam = await teamRepository.AddAsync(team);
var personTeamAssociation = new PersonTeamAssociation {
var personTeamAssociation = new DtoPersonTeamAssociation {
PersonId = dtoTeam.OwnerID,
TeamId = newTeam.ID,
EventId = dtoTeam.EventID,
Expand All @@ -109,7 +109,7 @@ public async Task<IActionResult> Edit([FromBody] DtoTeam dtoTeam)
{
log.LogInformation("Editing dtoTeam {dtoTeam}", dtoTeam);
var role = "";
var team = mapper.Map<Team>(dtoTeam);
var team = mapper.Map<DtoTeam>(dtoTeam);
var teamOwner = team.OwnerID;
var emailAddress = User.Claims.Single(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value;
try
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task<IActionResult> Delete([FromBody] DtoTeam dtoTeam)
{
var role = "";
dtoTeam.IsArchived = true;
var team = mapper.Map<Team>(dtoTeam);
var team = mapper.Map<DtoTeam>(dtoTeam);
var teamOwner = team.OwnerID;
var emailAddress = User.Claims.Single(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value;
try
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task<IActionResult> Delete([FromBody] DtoTeam dtoTeam)
await teamRepository.EditTeamAsync(team);
return Ok();
}
catch (UnableToDeleteException<Team> ex)
catch (UnableToDeleteException<DtoTeam> ex)
{
return BadRequest(ex.Message);
}
Expand All @@ -180,7 +180,7 @@ public async Task<IActionResult> Delete([FromBody] DtoTeam dtoTeam)
await teamRepository.EditTeamAsync(team);
return Ok();
}
catch (UnableToDeleteException<Team> ex)
catch (UnableToDeleteException<DtoTeam> ex)
{
return BadRequest(ex.Message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2/api/api/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<DtoPerson> GetAsync()
var person = await personRepository.GetByAuthIdAsync(emailAddress);
return mapper.Map<DtoPerson>(person);
}
catch (NotFoundException<Person>)
catch (NotFoundException<DtoPerson>)
{
var name = User.Claims.Single(c => c.Type == "name").Value;
var person = await personRepository.AddAsync(name, null, emailAddress, "Bob");
Expand Down
36 changes: 18 additions & 18 deletions src/v2/api/api/DataAccess/DonationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

public interface IDonationRepository
{
Task<Donation> AddAsync(Donation donation);
Task<DtoDonation> AddAsync(DtoDonation donation);
Task DeleteAsync(long id);
Task EditAsync(Donation e);
Task EditAsync(DtoDonation e);
public Task<bool> ExistsAsync(long id);
Task<Donation> GetByIdAsync(long id);
Task<DtoDonation> GetByIdAsync(long id);

Task<IEnumerable<Donation>> GetAllAsync();
Task<IEnumerable<Donation>> GetByEventIdAsync(long eventId);
Task<IEnumerable<Donation>> GetByTeamIdAsync(long teamId);
Task<IEnumerable<DtoDonation>> GetAllAsync();
Task<IEnumerable<DtoDonation>> GetByEventIdAsync(long eventId);
Task<IEnumerable<DtoDonation>> GetByTeamIdAsync(long teamId);
Task<decimal> GetTeamDonationSum(long teamID);
Task<decimal> GetEventDonationSumAsync(long eventid);
}
Expand All @@ -31,28 +31,28 @@ public async Task<bool> ExistsAsync(long id)
return await context.Donations.AnyAsync(e => e.ID == id);
}

public async Task<IEnumerable<Donation>> GetAllAsync()
public async Task<IEnumerable<DtoDonation>> GetAllAsync()
{
var DonationList = await EntityFrameworkQueryableExtensions.ToListAsync(context.Donations);
return mapper.Map<IEnumerable<DbDonation>, IEnumerable<Donation>>(DonationList);
return mapper.Map<IEnumerable<DbDonation>, IEnumerable<DtoDonation>>(DonationList);
}

public async Task<Donation> GetByIdAsync(long id)
public async Task<DtoDonation> GetByIdAsync(long id)
{
var e = await context.Donations.FindAsync(id);

return mapper.Map<Donation>(e);
return mapper.Map<DtoDonation>(e);
}
public async Task<Donation> AddAsync(Donation donation)
public async Task<DtoDonation> AddAsync(DtoDonation donation)
{
var newDonation = mapper.Map<DbDonation>(donation);
context.Donations.Add(newDonation);
await context.SaveChangesAsync();

return mapper.Map<Donation>(newDonation);
return mapper.Map<DtoDonation>(newDonation);
}

public async Task EditAsync(Donation e)
public async Task EditAsync(DtoDonation e)
{
var dbDonation = mapper.Map<DbDonation>(e);
context.Update(dbDonation);
Expand All @@ -63,12 +63,12 @@ public async Task DeleteAsync(long id)
{
var e = await context.Donations.FindAsync(id);
if (e == null)
throw new NotFoundException<Donation>("Donation id does not exist");
throw new NotFoundException<DtoDonation>("Donation id does not exist");
context.Donations.Remove(e);
await context.SaveChangesAsync();
}

public async Task<IEnumerable<Donation>> GetByEventIdAsync(long eventId)
public async Task<IEnumerable<DtoDonation>> GetByEventIdAsync(long eventId)
{
var teams = await context.Teams.Where(t => t.EventID == eventId).ToListAsync();
var donations = new List<DbDonation>();
Expand All @@ -81,17 +81,17 @@ public async Task<IEnumerable<Donation>> GetByEventIdAsync(long eventId)
}


return mapper.Map<IEnumerable<DbDonation>, IEnumerable<Donation>>(donations);
return mapper.Map<IEnumerable<DbDonation>, IEnumerable<DtoDonation>>(donations);
}

public async Task<IEnumerable<Donation>> GetByTeamIdAsync(long teamId)
public async Task<IEnumerable<DtoDonation>> GetByTeamIdAsync(long teamId)
{
var donations = await context.Donations
.Include(d => d.Team)
.Include(d => d.Person)
.Where(d => d.TeamID == teamId).ToListAsync();

return mapper.Map<IEnumerable<DbDonation>, IEnumerable<Donation>>(donations);
return mapper.Map<IEnumerable<DbDonation>, IEnumerable<DtoDonation>>(donations);
}

public async Task<decimal> GetTeamDonationSum(long teamID)
Expand Down
24 changes: 12 additions & 12 deletions src/v2/api/api/DataAccess/EventRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public interface IEventRepository
{
Task<Event> AddAsync(Event newEvent);
Task<DtoEvent> AddAsync(DtoEvent newEvent);
Task DeleteAsync(long id);
Task EditAsync(Event e);
Task EditAsync(DtoEvent e);
public Task<bool> ExistsAsync(long id);
Task<Event> GetByIdAsync(long id);
Task<IEnumerable<Event>> GetAllAsync();
Task<DtoEvent> GetByIdAsync(long id);
Task<IEnumerable<DtoEvent>> GetAllAsync();
}

public class EventRepository : IEventRepository
Expand All @@ -26,28 +26,28 @@ public async Task<bool> ExistsAsync(long id)
return await context.Events.AnyAsync(e => e.ID == id);
}

public async Task<IEnumerable<Event>> GetAllAsync()
public async Task<IEnumerable<DtoEvent>> GetAllAsync()
{
var eventList = await EntityFrameworkQueryableExtensions.ToListAsync(context.Events);
return mapper.Map<IEnumerable<DbEvent>, IEnumerable<Event>>(eventList);
return mapper.Map<IEnumerable<DbEvent>, IEnumerable<DtoEvent>>(eventList);
}

public async Task<Event> GetByIdAsync(long id)
public async Task<DtoEvent> GetByIdAsync(long id)
{
var e = await context.Events.FindAsync(id);

return mapper.Map<Event>(e);
return mapper.Map<DtoEvent>(e);
}
public async Task<Event> AddAsync(Event @event)
public async Task<DtoEvent> AddAsync(DtoEvent @event)
{
var newEvent = mapper.Map<DbEvent>(@event);
context.Events.Add(newEvent);
await context.SaveChangesAsync();

return mapper.Map<Event>(newEvent);
return mapper.Map<DtoEvent>(newEvent);
}

public async Task EditAsync(Event e)
public async Task EditAsync(DtoEvent e)
{
var dbEvent = mapper.Map<DbEvent>(e);
context.Update(dbEvent);
Expand All @@ -58,7 +58,7 @@ public async Task DeleteAsync(long id)
{
var e = await context.Events.FindAsync(id);
if (e == null)
throw new NotFoundException<Event>("Event id does not exist");
throw new NotFoundException<DtoEvent>("Event id does not exist");
context.Events.Remove(e);
await context.SaveChangesAsync();
}
Expand Down
Loading

0 comments on commit 0ee445b

Please sign in to comment.