From 0ee445bf5bd010c970a418ffa7e5a5ca75188810 Mon Sep 17 00:00:00 2001 From: Joshua Barlow Date: Thu, 5 Oct 2023 16:45:36 -0600 Subject: [PATCH] removed the in between classes for the last time --- src/combined/Controllers/AdminController.cs | 7 --- src/combined/Controllers/StripeController.cs | 1 - src/combined/DataAccess/TeamRepository.cs | 1 - src/v2/api/api/Controllers/AdminController.cs | 6 +-- .../api/api/Controllers/DonationController.cs | 2 +- src/v2/api/api/Controllers/EventController.cs | 4 +- src/v2/api/api/Controllers/LinkController.cs | 2 +- .../api/Controllers/LinkRecordContorller.cs | 2 +- .../api/api/Controllers/PersonController.cs | 2 +- .../PersonTeamAssociationController.cs | 4 +- .../api/api/Controllers/StripeController.cs | 5 +- src/v2/api/api/Controllers/TeamController.cs | 18 +++---- src/v2/api/api/Controllers/UserController.cs | 2 +- .../api/api/DataAccess/DonationRepository.cs | 36 +++++++------- src/v2/api/api/DataAccess/EventRepository.cs | 24 +++++----- .../api/DataAccess/LinkRecordRepository.cs | 6 +-- src/v2/api/api/DataAccess/LinkRepository.cs | 12 ++--- .../DataAccess/PaymentFailureRepository.cs | 18 +++---- src/v2/api/api/DataAccess/PersonRepository.cs | 34 ++++++------- .../PersonTeamAssoicationRepository.cs | 31 ++++++------ src/v2/api/api/DataAccess/TeamRepository.cs | 41 ++++++++-------- src/v2/api/api/GlobalUsings.cs | 1 - src/v2/api/api/Mappers/AspenMapperProfile.cs | 44 ++++++----------- src/v2/api/shared/DtoModels/DtoTeam.cs | 48 +++++++++++++------ 24 files changed, 172 insertions(+), 179 deletions(-) diff --git a/src/combined/Controllers/AdminController.cs b/src/combined/Controllers/AdminController.cs index 0597705b..1a6c2ee2 100644 --- a/src/combined/Controllers/AdminController.cs +++ b/src/combined/Controllers/AdminController.cs @@ -25,11 +25,4 @@ public async Task> GetTeamDonations( long teamID) return await service.GetTeamDonationsAsync(teamID); } - /*[HttpGet("donations/event/{eventID}")] - public async Task> GetEventDonations(long eventID) - { - return await service.GetEventDonationsAsync(eventID); - }*/ -} - public record UserClaim(string claim, string value); diff --git a/src/combined/Controllers/StripeController.cs b/src/combined/Controllers/StripeController.cs index 5bdf9b35..fd5c79b0 100644 --- a/src/combined/Controllers/StripeController.cs +++ b/src/combined/Controllers/StripeController.cs @@ -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; diff --git a/src/combined/DataAccess/TeamRepository.cs b/src/combined/DataAccess/TeamRepository.cs index 7b0a4d96..9ae1ffce 100644 --- a/src/combined/DataAccess/TeamRepository.cs +++ b/src/combined/DataAccess/TeamRepository.cs @@ -5,7 +5,6 @@ public interface ITeamRepository { Task AddAsync(DtoTeam team); - //Task DeleteTeamAsync(Team team); Task EditTeamAsync(DtoTeam team); Task GetTeamByIdAsync(long id); Task> GetByEventIdAsync(long eventID); diff --git a/src/v2/api/api/Controllers/AdminController.cs b/src/v2/api/api/Controllers/AdminController.cs index b814bb9d..95dc1132 100644 --- a/src/v2/api/api/Controllers/AdminController.cs +++ b/src/v2/api/api/Controllers/AdminController.cs @@ -25,21 +25,21 @@ public IEnumerable Get() => //public async Task> GetEventDonations(long eventID) //{ // //var donations = await donationRepository.GetByEventIdAsync(eventID); - // return mapper.Map, IEnumerable>(donations); + // return mapper.Map, IEnumerable>(donations); //} [HttpGet("donation/{eventID}/{teamID}")] public async Task> GetTeamDonations( long teamID) { var donations = await donationRepository.GetByTeamIdAsync(teamID); - return mapper.Map, IEnumerable>(donations); + return mapper.Map, IEnumerable>(donations); } [HttpGet("donations/event/{eventID}")] public async Task> GetEventDonations(long eventID) { var donations = await donationRepository.GetByEventIdAsync(eventID); - return mapper.Map, IEnumerable>(donations); + return mapper.Map, IEnumerable>(donations); } } diff --git a/src/v2/api/api/Controllers/DonationController.cs b/src/v2/api/api/Controllers/DonationController.cs index 82b4ce65..83a6f479 100644 --- a/src/v2/api/api/Controllers/DonationController.cs +++ b/src/v2/api/api/Controllers/DonationController.cs @@ -33,7 +33,7 @@ public async Task> Add([FromBody] DtoDonation dtoDonat if (dtoDonation.ID != 0) return BadRequest("Cannot add with a valid id"); - var donation = mapper.Map(dtoDonation); + var donation = mapper.Map(dtoDonation); var newDonation = await donationRepository.AddAsync(donation); return mapper.Map(newDonation); } diff --git a/src/v2/api/api/Controllers/EventController.cs b/src/v2/api/api/Controllers/EventController.cs index c7564509..200d8486 100644 --- a/src/v2/api/api/Controllers/EventController.cs +++ b/src/v2/api/api/Controllers/EventController.cs @@ -55,7 +55,7 @@ public async Task> Add([FromBody] DtoEvent dtoEvent) try { - var @event = mapper.Map(dtoEvent); + var @event = mapper.Map(dtoEvent); log.LogInformation("Mapped {dtoEvent} to {event}", dtoEvent, @event); var newEvent = await eventRepository.AddAsync(@event); log.LogInformation("Got back {newEvent} from event repository", newEvent); @@ -75,7 +75,7 @@ public async Task Edit([FromBody] DtoEvent dtoEvent) if (!ModelState.IsValid) return BadRequest(getModelStateErrorMessage()); - var e = mapper.Map(dtoEvent); + var e = mapper.Map(dtoEvent); await eventRepository.EditAsync(e); return Ok("Event edit was successful"); } diff --git a/src/v2/api/api/Controllers/LinkController.cs b/src/v2/api/api/Controllers/LinkController.cs index a22fe0dd..221ebe74 100644 --- a/src/v2/api/api/Controllers/LinkController.cs +++ b/src/v2/api/api/Controllers/LinkController.cs @@ -45,7 +45,7 @@ public async Task> Add([FromBody] DtoLink dtoLink) if (dtoLink.ID != 0) return BadRequest("Cannot add with a valid id"); - var link = mapper.Map(dtoLink); + var link = mapper.Map(dtoLink); var newLink = await linkRepository.Add(link); return mapper.Map(newLink); diff --git a/src/v2/api/api/Controllers/LinkRecordContorller.cs b/src/v2/api/api/Controllers/LinkRecordContorller.cs index 27365394..4148a2cc 100644 --- a/src/v2/api/api/Controllers/LinkRecordContorller.cs +++ b/src/v2/api/api/Controllers/LinkRecordContorller.cs @@ -33,7 +33,7 @@ public async Task> AddAsync([FromBody] DtoLinkRecord if (dtoLinkRecord.ID != 0) return BadRequest("Cannot add with a valid id"); - var linkRecord = mapper.Map(dtoLinkRecord); + var linkRecord = mapper.Map(dtoLinkRecord); var newLinkRecord = await linkRecordRepository.Add(linkRecord); return mapper.Map(newLinkRecord); diff --git a/src/v2/api/api/Controllers/PersonController.cs b/src/v2/api/api/Controllers/PersonController.cs index 0b006b6e..a4288ec1 100644 --- a/src/v2/api/api/Controllers/PersonController.cs +++ b/src/v2/api/api/Controllers/PersonController.cs @@ -80,7 +80,7 @@ public async Task> Edit([FromBody] DtoPerson dtoPerson) if (!await personRepository.ExistsAsync(dtoPerson.ID)) return NotFound("Person id does not exist"); - var person = mapper.Map(dtoPerson); + var person = mapper.Map(dtoPerson); var updatedPerson = await personRepository.EditAsync(person); return mapper.Map(updatedPerson); } diff --git a/src/v2/api/api/Controllers/PersonTeamAssociationController.cs b/src/v2/api/api/Controllers/PersonTeamAssociationController.cs index 6a448071..b3721358 100644 --- a/src/v2/api/api/Controllers/PersonTeamAssociationController.cs +++ b/src/v2/api/api/Controllers/PersonTeamAssociationController.cs @@ -34,7 +34,7 @@ public async Task> GetTeamAsync(long personId, long eventI public async Task SwitchTeam([FromBody] DtoPersonTeamAssociation dtoPersonTeamAssociation) { - var updatedPersonTeamAssociation = mapper.Map(dtoPersonTeamAssociation); + var updatedPersonTeamAssociation = mapper.Map(dtoPersonTeamAssociation); await personTeamAssociationRepository.SwitchTeamAsync(updatedPersonTeamAssociation); return Ok("Team switch was successful"); @@ -43,7 +43,7 @@ public async Task SwitchTeam([FromBody] DtoPersonTeamAssociation [HttpPost] public async Task> Add([FromBody] DtoPersonTeamAssociation dtoPersonTeamAssociation){ - var tempPersonTeam = mapper.Map(dtoPersonTeamAssociation); + var tempPersonTeam = mapper.Map(dtoPersonTeamAssociation); var newPersonTeamAssociation = await personTeamAssociationRepository.AddAsync(tempPersonTeam); return mapper.Map(newPersonTeamAssociation); } diff --git a/src/v2/api/api/Controllers/StripeController.cs b/src/v2/api/api/Controllers/StripeController.cs index 00e9aac2..a0667857 100644 --- a/src/v2/api/api/Controllers/StripeController.cs +++ b/src/v2/api/api/Controllers/StripeController.cs @@ -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; @@ -92,7 +91,7 @@ public async Task 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, @@ -140,7 +139,7 @@ public async Task 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, diff --git a/src/v2/api/api/Controllers/TeamController.cs b/src/v2/api/api/Controllers/TeamController.cs index 99da7ba8..98aa7bd9 100644 --- a/src/v2/api/api/Controllers/TeamController.cs +++ b/src/v2/api/api/Controllers/TeamController.cs @@ -36,13 +36,13 @@ public TeamController(ITeamRepository teamRepository, IMapper mapper, ILogger>> GetByEventID(long eventId) { - Log.Information("Getting Team by event {eventId}", eventId); + Log.Information("Getting DtoTeam by event {eventId}", eventId); try { var teams = mapper.Map>(await teamRepository.GetByEventIdAsync(eventId)); return new ActionResult>(teams); } - catch (NotFoundException> ex) + catch (NotFoundException> ex) { Log.Information(ex.Message, "Event Not Found"); return NotFound(ex.Message); @@ -58,7 +58,7 @@ public async Task>> GetUsersTeamsForEvent(long var teams = mapper.Map>(await teamRepository.GetUsersTeamsByEventIdAsync(eventId, userId)); return new ActionResult>(teams); } - catch (NotFoundException> ex) + catch (NotFoundException> ex) { Log.Information(ex.Message, "Event Not Found"); return NotFound(ex.Message); @@ -90,9 +90,9 @@ public async Task> Add([FromBody] DtoTeam dtoTeam) - var team = mapper.Map(dtoTeam); + var team = mapper.Map(dtoTeam); var newTeam = await teamRepository.AddAsync(team); - var personTeamAssociation = new PersonTeamAssociation { + var personTeamAssociation = new DtoPersonTeamAssociation { PersonId = dtoTeam.OwnerID, TeamId = newTeam.ID, EventId = dtoTeam.EventID, @@ -109,7 +109,7 @@ public async Task Edit([FromBody] DtoTeam dtoTeam) { log.LogInformation("Editing dtoTeam {dtoTeam}", dtoTeam); var role = ""; - var team = mapper.Map(dtoTeam); + var team = mapper.Map(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 @@ -139,7 +139,7 @@ public async Task Delete([FromBody] DtoTeam dtoTeam) { var role = ""; dtoTeam.IsArchived = true; - var team = mapper.Map(dtoTeam); + var team = mapper.Map(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 @@ -167,7 +167,7 @@ public async Task Delete([FromBody] DtoTeam dtoTeam) await teamRepository.EditTeamAsync(team); return Ok(); } - catch (UnableToDeleteException ex) + catch (UnableToDeleteException ex) { return BadRequest(ex.Message); } @@ -180,7 +180,7 @@ public async Task Delete([FromBody] DtoTeam dtoTeam) await teamRepository.EditTeamAsync(team); return Ok(); } - catch (UnableToDeleteException ex) + catch (UnableToDeleteException ex) { return BadRequest(ex.Message); } diff --git a/src/v2/api/api/Controllers/UserController.cs b/src/v2/api/api/Controllers/UserController.cs index 77c1f99f..b9542517 100644 --- a/src/v2/api/api/Controllers/UserController.cs +++ b/src/v2/api/api/Controllers/UserController.cs @@ -31,7 +31,7 @@ public async Task GetAsync() var person = await personRepository.GetByAuthIdAsync(emailAddress); return mapper.Map(person); } - catch (NotFoundException) + catch (NotFoundException) { var name = User.Claims.Single(c => c.Type == "name").Value; var person = await personRepository.AddAsync(name, null, emailAddress, "Bob"); diff --git a/src/v2/api/api/DataAccess/DonationRepository.cs b/src/v2/api/api/DataAccess/DonationRepository.cs index bf8cb983..ecc50c26 100644 --- a/src/v2/api/api/DataAccess/DonationRepository.cs +++ b/src/v2/api/api/DataAccess/DonationRepository.cs @@ -2,15 +2,15 @@ public interface IDonationRepository { - Task AddAsync(Donation donation); + Task AddAsync(DtoDonation donation); Task DeleteAsync(long id); - Task EditAsync(Donation e); + Task EditAsync(DtoDonation e); public Task ExistsAsync(long id); - Task GetByIdAsync(long id); + Task GetByIdAsync(long id); - Task> GetAllAsync(); - Task> GetByEventIdAsync(long eventId); - Task> GetByTeamIdAsync(long teamId); + Task> GetAllAsync(); + Task> GetByEventIdAsync(long eventId); + Task> GetByTeamIdAsync(long teamId); Task GetTeamDonationSum(long teamID); Task GetEventDonationSumAsync(long eventid); } @@ -31,28 +31,28 @@ public async Task ExistsAsync(long id) return await context.Donations.AnyAsync(e => e.ID == id); } - public async Task> GetAllAsync() + public async Task> GetAllAsync() { var DonationList = await EntityFrameworkQueryableExtensions.ToListAsync(context.Donations); - return mapper.Map, IEnumerable>(DonationList); + return mapper.Map, IEnumerable>(DonationList); } - public async Task GetByIdAsync(long id) + public async Task GetByIdAsync(long id) { var e = await context.Donations.FindAsync(id); - return mapper.Map(e); + return mapper.Map(e); } - public async Task AddAsync(Donation donation) + public async Task AddAsync(DtoDonation donation) { var newDonation = mapper.Map(donation); context.Donations.Add(newDonation); await context.SaveChangesAsync(); - return mapper.Map(newDonation); + return mapper.Map(newDonation); } - public async Task EditAsync(Donation e) + public async Task EditAsync(DtoDonation e) { var dbDonation = mapper.Map(e); context.Update(dbDonation); @@ -63,12 +63,12 @@ public async Task DeleteAsync(long id) { var e = await context.Donations.FindAsync(id); if (e == null) - throw new NotFoundException("Donation id does not exist"); + throw new NotFoundException("Donation id does not exist"); context.Donations.Remove(e); await context.SaveChangesAsync(); } - public async Task> GetByEventIdAsync(long eventId) + public async Task> GetByEventIdAsync(long eventId) { var teams = await context.Teams.Where(t => t.EventID == eventId).ToListAsync(); var donations = new List(); @@ -81,17 +81,17 @@ public async Task> GetByEventIdAsync(long eventId) } - return mapper.Map, IEnumerable>(donations); + return mapper.Map, IEnumerable>(donations); } - public async Task> GetByTeamIdAsync(long teamId) + public async Task> 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>(donations); + return mapper.Map, IEnumerable>(donations); } public async Task GetTeamDonationSum(long teamID) diff --git a/src/v2/api/api/DataAccess/EventRepository.cs b/src/v2/api/api/DataAccess/EventRepository.cs index 00bf8165..49de6ff1 100644 --- a/src/v2/api/api/DataAccess/EventRepository.cs +++ b/src/v2/api/api/DataAccess/EventRepository.cs @@ -2,12 +2,12 @@ public interface IEventRepository { - Task AddAsync(Event newEvent); + Task AddAsync(DtoEvent newEvent); Task DeleteAsync(long id); - Task EditAsync(Event e); + Task EditAsync(DtoEvent e); public Task ExistsAsync(long id); - Task GetByIdAsync(long id); - Task> GetAllAsync(); + Task GetByIdAsync(long id); + Task> GetAllAsync(); } public class EventRepository : IEventRepository @@ -26,28 +26,28 @@ public async Task ExistsAsync(long id) return await context.Events.AnyAsync(e => e.ID == id); } - public async Task> GetAllAsync() + public async Task> GetAllAsync() { var eventList = await EntityFrameworkQueryableExtensions.ToListAsync(context.Events); - return mapper.Map, IEnumerable>(eventList); + return mapper.Map, IEnumerable>(eventList); } - public async Task GetByIdAsync(long id) + public async Task GetByIdAsync(long id) { var e = await context.Events.FindAsync(id); - return mapper.Map(e); + return mapper.Map(e); } - public async Task AddAsync(Event @event) + public async Task AddAsync(DtoEvent @event) { var newEvent = mapper.Map(@event); context.Events.Add(newEvent); await context.SaveChangesAsync(); - return mapper.Map(newEvent); + return mapper.Map(newEvent); } - public async Task EditAsync(Event e) + public async Task EditAsync(DtoEvent e) { var dbEvent = mapper.Map(e); context.Update(dbEvent); @@ -58,7 +58,7 @@ public async Task DeleteAsync(long id) { var e = await context.Events.FindAsync(id); if (e == null) - throw new NotFoundException("Event id does not exist"); + throw new NotFoundException("Event id does not exist"); context.Events.Remove(e); await context.SaveChangesAsync(); } diff --git a/src/v2/api/api/DataAccess/LinkRecordRepository.cs b/src/v2/api/api/DataAccess/LinkRecordRepository.cs index fc5d5014..f98bd824 100644 --- a/src/v2/api/api/DataAccess/LinkRecordRepository.cs +++ b/src/v2/api/api/DataAccess/LinkRecordRepository.cs @@ -2,7 +2,7 @@ public interface ILinkRecordRepository { - Task Add(LinkRecord linkRecord); + Task Add(DtoLinkRecord linkRecord); } @@ -17,12 +17,12 @@ public LinkRecordRepository(AspenContext context, IMapper mapper) this.mapper = mapper; } - public async Task Add(LinkRecord linkRecord) + public async Task Add(DtoLinkRecord linkRecord) { var dbLinkRecord = mapper.Map(linkRecord); await context.LinkRecords.AddAsync(dbLinkRecord); await context.SaveChangesAsync(); - return mapper.Map(dbLinkRecord); + return mapper.Map(dbLinkRecord); } } \ No newline at end of file diff --git a/src/v2/api/api/DataAccess/LinkRepository.cs b/src/v2/api/api/DataAccess/LinkRepository.cs index e59837e2..301fcc34 100644 --- a/src/v2/api/api/DataAccess/LinkRepository.cs +++ b/src/v2/api/api/DataAccess/LinkRepository.cs @@ -2,8 +2,8 @@ public interface ILinkRepository { - Task Add(Link link); - Task LinkGUIDAsync(string linkGUID); + Task Add(DtoLink link); + Task LinkGUIDAsync(string linkGUID); } @@ -18,18 +18,18 @@ public LinkRepository(AspenContext context, IMapper mapper) this.mapper = mapper; } - public async Task Add(Link link) + public async Task Add(DtoLink link) { var dbLink = mapper.Map(link); await context.Links.AddAsync(dbLink); await context.SaveChangesAsync(); - return mapper.Map(dbLink); + return mapper.Map(dbLink); } - public async Task LinkGUIDAsync(string linkGUID) + public async Task LinkGUIDAsync(string linkGUID) { var link = await context.Links.FirstOrDefaultAsync(l => l.LinkGUID == linkGUID); - return mapper.Map(link); + return mapper.Map(link); } diff --git a/src/v2/api/api/DataAccess/PaymentFailureRepository.cs b/src/v2/api/api/DataAccess/PaymentFailureRepository.cs index a5e91c96..8623a142 100644 --- a/src/v2/api/api/DataAccess/PaymentFailureRepository.cs +++ b/src/v2/api/api/DataAccess/PaymentFailureRepository.cs @@ -5,9 +5,9 @@ namespace Api.DataAccess; public interface IPaymentFailureRepository { - Task Add(PaymentFailure paymentFailure); - Task GetByIdAsync(int paymentFailureId); - Task> GetAllAsync(); + Task Add(DtoPaymentFailure paymentFailure); + Task GetByIdAsync(int paymentFailureId); + Task> GetAllAsync(); } @@ -22,24 +22,24 @@ public PaymentFailureRepository(AspenContext context, IMapper mapper) this.mapper = mapper; } - public async Task Add(PaymentFailure paymentFailure) + public async Task Add(DtoPaymentFailure paymentFailure) { var dbPaymentFailure = mapper.Map(paymentFailure); await context.PaymentFailures.AddAsync(dbPaymentFailure); await context.SaveChangesAsync(); - return mapper.Map(dbPaymentFailure); + return mapper.Map(dbPaymentFailure); } - public async Task> GetAllAsync() + public async Task> GetAllAsync() { var paymentFailureList = await EntityFrameworkQueryableExtensions.ToListAsync(context.PaymentFailures); - return mapper.Map, IEnumerable>(paymentFailureList); + return mapper.Map, IEnumerable>(paymentFailureList); } - public async Task GetByIdAsync(int id) + public async Task GetByIdAsync(int id) { var e = await context.PaymentFailures.FindAsync(id); - return mapper.Map(e); + return mapper.Map(e); } } \ No newline at end of file diff --git a/src/v2/api/api/DataAccess/PersonRepository.cs b/src/v2/api/api/DataAccess/PersonRepository.cs index 5f1544e5..34c5dcd2 100644 --- a/src/v2/api/api/DataAccess/PersonRepository.cs +++ b/src/v2/api/api/DataAccess/PersonRepository.cs @@ -3,12 +3,12 @@ namespace Api.DataAccess; public interface IPersonRepository { Task ExistsAsync(long id); - Task AddAsync(string name, string bio, string nickname); - Task AddAsync(string name, string bio, string authID, string nickname); + Task AddAsync(string name, string bio, string nickname); + Task AddAsync(string name, string bio, string authID, string nickname); Task DeleteAsync(long id); - Task EditAsync(Person e); - Task GetByIDAsync(long id); - Task GetByAuthIdAsync(string authId); + Task EditAsync(DtoPerson e); + Task GetByIDAsync(long id); + Task GetByAuthIdAsync(string authId); } public class PersonRepository : IPersonRepository @@ -27,7 +27,7 @@ public async Task ExistsAsync(long id) return await context.Persons.AnyAsync(e => e.ID == id); } - public async Task AddAsync(string name, string bio, string nickname) + public async Task AddAsync(string name, string bio, string nickname) { var dbPerson = new DbPerson() { @@ -39,7 +39,7 @@ public async Task AddAsync(string name, string bio, string nickname) return await addDBPersonAsync(dbPerson); } - public async Task AddAsync(string name, string bio, string authID, string nickname) + public async Task AddAsync(string name, string bio, string authID, string nickname) { var dbPerson = new DbPerson() { @@ -51,11 +51,11 @@ public async Task AddAsync(string name, string bio, string authID, strin return await addDBPersonAsync(dbPerson); } - private async Task addDBPersonAsync(DbPerson dbPerson) + private async Task addDBPersonAsync(DbPerson dbPerson) { await context.Persons.AddAsync(dbPerson); await context.SaveChangesAsync(); - return mapper.Map(dbPerson); + return mapper.Map(dbPerson); } public async Task DeleteAsync(long id) @@ -63,13 +63,13 @@ public async Task DeleteAsync(long id) var person = await context.Persons.FindAsync(id); if (person == null) { - throw new NotFoundException("Person id does not exist"); + throw new NotFoundException("DtoPerson id does not exist"); } context.Persons.Remove(person); await context.SaveChangesAsync(); } - public async Task EditAsync(Person person) + public async Task EditAsync(DtoPerson person) { var dbPerson = mapper.Map(person); context.Update(dbPerson); @@ -77,23 +77,23 @@ public async Task EditAsync(Person person) return person; } - public async Task GetByIDAsync(long id) + public async Task GetByIDAsync(long id) { var dbPerson = await context.Persons.FindAsync(id); if (dbPerson == null) { - throw new NotFoundException($"Person id does not exist"); + throw new NotFoundException($"Person id does not exist"); } - return mapper.Map(dbPerson); + return mapper.Map(dbPerson); } - public async Task GetByAuthIdAsync(string authId) + public async Task GetByAuthIdAsync(string authId) { var dbPerson = await context.Persons.FirstOrDefaultAsync(p => p.AuthID == authId); if (dbPerson == null) { - throw new NotFoundException($"Unable to locate person by authId"); + throw new NotFoundException($"Unable to locate person by authId"); } - return mapper.Map(dbPerson); + return mapper.Map(dbPerson); } } diff --git a/src/v2/api/api/DataAccess/PersonTeamAssoicationRepository.cs b/src/v2/api/api/DataAccess/PersonTeamAssoicationRepository.cs index 59dce3d9..24748aae 100644 --- a/src/v2/api/api/DataAccess/PersonTeamAssoicationRepository.cs +++ b/src/v2/api/api/DataAccess/PersonTeamAssoicationRepository.cs @@ -7,12 +7,12 @@ namespace Api.DataAccess; public interface IPersonTeamAssoicationRepository { - Task AddAsync(PersonTeamAssociation personTeamAssociation); - Task SwitchTeamAsync(PersonTeamAssociation personTeamAssociation); + Task AddAsync(DtoPersonTeamAssociation personTeamAssociation); + Task SwitchTeamAsync(DtoPersonTeamAssociation personTeamAssociation); - Task GetTeamAsync(long personId, long eventId); - Task GetPersonTeamAssociationAsync(long personId, long eventId); - Task> GetTeamMembersAsync(long teamId); + Task GetTeamAsync(long personId, long eventId); + Task GetPersonTeamAssociationAsync(long personId, long eventId); + Task> GetTeamMembersAsync(long teamId); Task ExistsAsync(long personId, long eventId); @@ -30,15 +30,15 @@ public PersonTeamAssoicationRepository(AspenContext context, IMapper mapper) this.mapper = mapper; } - public async Task GetPersonTeamAssociationAsync(long personId, long eventId) + public async Task GetPersonTeamAssociationAsync(long personId, long eventId) { var dbPersonTeamAssociation = await context.PersonTeamAssociations .Where(e => e.PersonId == personId && e.EventId == eventId) .FirstOrDefaultAsync(); - return mapper.Map(dbPersonTeamAssociation); + return mapper.Map(dbPersonTeamAssociation); } - public async Task AddAsync(PersonTeamAssociation personTeamAssociation) + public async Task AddAsync(DtoPersonTeamAssociation personTeamAssociation) { var dbPersonTeamAssociation = mapper.Map(personTeamAssociation); try @@ -53,26 +53,26 @@ public async Task AddAsync(PersonTeamAssociation personTe throw new Exception("This person is already on the team for this event."); } } - return mapper.Map(dbPersonTeamAssociation); + return mapper.Map(dbPersonTeamAssociation); } - public async Task GetTeamAsync(long personId, long eventId) + public async Task GetTeamAsync(long personId, long eventId) { var dbPersonTeamAssociation = await context.PersonTeamAssociations .Where(e => e.PersonId == personId && e.EventId == eventId) .FirstOrDefaultAsync(); var dbTeam = await context.Teams.FindAsync(dbPersonTeamAssociation.TeamId); - return mapper.Map(dbTeam); + return mapper.Map(dbTeam); } - public async Task> GetTeamMembersAsync(long teamId) + public async Task> GetTeamMembersAsync(long teamId) { var dbPersonTeamAssociation = await context.PersonTeamAssociations .Where(e => e.TeamId == teamId) .ToListAsync(); var personIds = dbPersonTeamAssociation.Select(e => e.PersonId); var persons = await context.Persons.Where(e => personIds.Contains(e.ID)).ToListAsync(); - return mapper.Map>(persons); + return mapper.Map>(persons); } public async Task ExistsAsync(long personId, long eventId) @@ -92,15 +92,16 @@ public async Task DeleteAsync(long personId, long eventId) } else { - throw new NotFoundException("Person is not on a team in this Event"); + throw new NotFoundException("Person is not on a team in this Event"); } } - public async Task SwitchTeamAsync(PersonTeamAssociation personTeamAssociation) + public async Task SwitchTeamAsync(DtoPersonTeamAssociation personTeamAssociation) { var dbPersonTeamAssociation = mapper.Map(personTeamAssociation); context.Update(dbPersonTeamAssociation); await context.SaveChangesAsync(); } + } diff --git a/src/v2/api/api/DataAccess/TeamRepository.cs b/src/v2/api/api/DataAccess/TeamRepository.cs index 120c9e15..77a10179 100644 --- a/src/v2/api/api/DataAccess/TeamRepository.cs +++ b/src/v2/api/api/DataAccess/TeamRepository.cs @@ -1,17 +1,16 @@ namespace Api.DataAccess; -using Api.Models.Entities; using Microsoft.Extensions.Logging; public interface ITeamRepository { - Task AddAsync(Team team); - //Task DeleteTeamAsync(Team team); - Task EditTeamAsync(Team team); - Task GetTeamByIdAsync(long id); - Task> GetAllAsync(); - Task> GetByEventIdAsync(long eventID); - Task> GetUsersTeamsByEventIdAsync(long eventID, int userId); + Task AddAsync(DtoTeam team); + //Task DeleteTeamAsync(DtoTeam team); + Task EditTeamAsync(DtoTeam team); + Task GetTeamByIdAsync(long id); + Task> GetAllAsync(); + Task> GetByEventIdAsync(long eventID); + Task> GetUsersTeamsByEventIdAsync(long eventID, int userId); Task ExistsAsync(long id); } @@ -35,19 +34,19 @@ public async Task ExistsAsync(long id) { return await context.Teams.AnyAsync(e => e.ID == id); } - public async Task> GetAllAsync() + public async Task> GetAllAsync() { var teams = await EntityFrameworkQueryableExtensions.ToListAsync(context.Teams); - return mapper.Map, IEnumerable>(teams); + return mapper.Map, IEnumerable>(teams); } - public async Task GetTeamByIdAsync(long id) + public async Task GetTeamByIdAsync(long id) { var team = await context.Teams.FirstAsync(r => r.ID == id); - return mapper.Map(team); + return mapper.Map(team); } - public async Task AddAsync(Team team) + public async Task AddAsync(DtoTeam team) { var existingEvent = await context.Events.Include(e => e.Teams).FirstOrDefaultAsync(e => e.ID == team.EventID); var newTeam = team.WithEventId(existingEvent.ID); @@ -70,14 +69,14 @@ public async Task AddAsync(Team team) context.Update(existingEvent); await context.SaveChangesAsync(); - return mapper.Map(dbTeam); + return mapper.Map(dbTeam); } - public async Task EditTeamAsync(Team team) + public async Task EditTeamAsync(DtoTeam team) { var dbTeam = mapper.Map(team); context.Update(dbTeam); - if (team.isArchived == true) + if (team.IsArchived == true) { var teamMembers = await personTeamAssociationRepository.GetTeamMembersAsync(team.ID); @@ -108,18 +107,18 @@ public async Task EditTeamAsync(Team team) } */ - public async Task> GetByEventIdAsync(long eventID) + public async Task> GetByEventIdAsync(long eventID) { var existingEvent = await context.Events.Include(e => e.Teams).FirstOrDefaultAsync(e => e.ID == eventID); if (existingEvent == null) - throw new NotFoundException>($"Event {eventID} does not exist"); + throw new NotFoundException>($"Event {eventID} does not exist"); var unArchivedTeams = existingEvent.Teams.Where(team => team.IsArchived == false).ToList(); - return mapper.Map, IEnumerable>(unArchivedTeams); + return mapper.Map, IEnumerable>(unArchivedTeams); } - public async Task> GetUsersTeamsByEventIdAsync(long eventID, int userId) + public async Task> GetUsersTeamsByEventIdAsync(long eventID, int userId) { var teams = await context.PersonTeamAssociations .Include(a => a.Team) @@ -127,6 +126,6 @@ public async Task> GetUsersTeamsByEventIdAsync(long eventID, i .Select(a => a.Team) // Select the Team objects .ToListAsync(); - return mapper.Map, IEnumerable>(teams); + return mapper.Map, IEnumerable>(teams); } } diff --git a/src/v2/api/api/GlobalUsings.cs b/src/v2/api/api/GlobalUsings.cs index 7fee1646..b250eca4 100644 --- a/src/v2/api/api/GlobalUsings.cs +++ b/src/v2/api/api/GlobalUsings.cs @@ -1,7 +1,6 @@ global using Api.DataAccess; global using Api.DbModels; global using Api.Exceptions; -global using Api.Models.Entities; global using Api.Services; global using AutoMapper; global using Microsoft.AspNetCore.Authorization; diff --git a/src/v2/api/api/Mappers/AspenMapperProfile.cs b/src/v2/api/api/Mappers/AspenMapperProfile.cs index f3ae73bd..f31f8c44 100644 --- a/src/v2/api/api/Mappers/AspenMapperProfile.cs +++ b/src/v2/api/api/Mappers/AspenMapperProfile.cs @@ -11,64 +11,48 @@ public class AspenMapperProfile : Profile /// public AspenMapperProfile() { - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() - .ReverseMap(); - - CreateMap() + CreateMap() .ReverseMap(); CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() - .ReverseMap(); - - CreateMap() - .ReverseMap(); - - CreateMap() - .ReverseMap(); - - CreateMap(); - - CreateMap() - .ForMember(dest => dest.TeamName, opt => opt.MapFrom(src => src.Team.Name)) - .ForMember(dest => dest.PersonName, opt => opt.MapFrom(src => src.Person.Name)); + CreateMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); - CreateMap() + CreateMap() .ReverseMap(); } } diff --git a/src/v2/api/shared/DtoModels/DtoTeam.cs b/src/v2/api/shared/DtoModels/DtoTeam.cs index 82ef1e30..e75d544e 100644 --- a/src/v2/api/shared/DtoModels/DtoTeam.cs +++ b/src/v2/api/shared/DtoModels/DtoTeam.cs @@ -1,19 +1,39 @@ using Swashbuckle.AspNetCore.Annotations; using System.ComponentModel.DataAnnotations; -namespace shared.DtoModels; - -public record DtoTeam +namespace shared.DtoModels { - [SwaggerSchema(ReadOnly = true)] - public long ID { get; set; } - [Required] - public string Name { get; set; } - public string Description { get; set; } - public string MainImage { get; set; } - public string WelcomeMessage { get; set; } - public long OwnerID { get; set; } - public long EventID { get; set; } - public decimal DonationTarget { get; set; } - public bool IsArchived { get; set; } = false; + public record DtoTeam + { + [SwaggerSchema(ReadOnly = true)] + public long ID { get; set; } + [Required] + public string Name { get; set; } + public string Description { get; set; } + public string MainImage { get; set; } + public string WelcomeMessage { get; set; } + public long OwnerID { get; set; } + public long EventID { get; set; } + public decimal DonationTarget { get; set; } + public bool IsArchived { get; set; } = false; + } + + public static class DtoTeamExtensions + { + public static DtoTeam WithEventId(this DtoTeam currentTeam, long newEventId) + { + return new DtoTeam + { + ID = currentTeam.ID, + Name = currentTeam.Name, + Description = currentTeam.Description, + MainImage = currentTeam.MainImage, + OwnerID = currentTeam.OwnerID, + EventID = newEventId, + DonationTarget = currentTeam.DonationTarget, + IsArchived = currentTeam.IsArchived, + WelcomeMessage = currentTeam.WelcomeMessage + }; + } + } }