Skip to content

Commit

Permalink
Fix Rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dercraker committed Mar 31, 2024
1 parent 58bb612 commit f88048f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
10 changes: 5 additions & 5 deletions Map.Api/Controllers/StepController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task<ActionResult<StepDto>> AddStepAsync([FromRoute] Guid tripId, [
[ProducesResponseType(typeof(Error), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(Error), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(Error), StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<StepDto>> AddStepBeforAsync([FromRoute] Guid tripId, [FromRoute] int stepId, [FromBody] AddStepDto addStepDto)
public async Task<ActionResult<StepDto>> AddStepBeforeAsync([FromRoute] Guid tripId, [FromRoute] int stepId, [FromBody] AddStepDto addStepDto)
{
ValidationResult validationResult = _addStepValidator.Validate(addStepDto);

Expand All @@ -121,7 +121,7 @@ public async Task<ActionResult<StepDto>> AddStepBeforAsync([FromRoute] Guid trip

Step entity = _mapper.Map<AddStepDto, Step>(addStepDto);

await _stepPlatform.AddStepBeforAsync(trip, nextStep, entity);
await _stepPlatform.AddStepBeforeAsync(trip, nextStep, entity);

return CreatedAtAction(nameof(GetStepById), new { stepId = entity.StepId }, _mapper.Map<Step, StepDto>(entity));
}
Expand Down Expand Up @@ -454,14 +454,14 @@ public async Task<ActionResult<StepDto>> UpdateStepLocationAsync([FromRoute] int
[HttpPatch]
[Route("{stepId}/transportMode")]
[MapToApiVersion(ApiControllerVersions.V1)]
[ProducesResponseType(typeof(StepDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(StepDtoList), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ICollection<Error>), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(Error), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(Error), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(Error), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(Error), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(Error), StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<StepDto>> UpdateStepTransportModeAsync([FromRoute] int stepId, [FromBody] UpdateStepTransportModeDto updateStepTransportModeDto)
public async Task<ActionResult<StepDtoList>> UpdateStepTransportModeAsync([FromRoute] int stepId, [FromBody] UpdateStepTransportModeDto updateStepTransportModeDto)
{
ValidationResult validationResult = _updateStepTransportModeValidator.Validate(updateStepTransportModeDto);
if (!validationResult.IsValid)
Expand All @@ -473,7 +473,7 @@ public async Task<ActionResult<StepDto>> UpdateStepTransportModeAsync([FromRoute

await _stepPlatform.UpdateStepTransportModeAsync(step, updateStepTransportModeDto);

return _mapper.Map<Step, StepDto>(step);
return _mapper.Map<Step, StepDtoList>(step);
}

#endregion
Expand Down
5 changes: 3 additions & 2 deletions Map.EFCore/Data/DBInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ private async Task AddTripsAsync()
Latitude = (decimal)(_random.NextDouble() * 180 - 90),
Description = $"Description for Step {j + 1} for Trip {i + 1}",
StartDate = DateTime.Now.AddDays(j),
EndDate = DateTime.Now.AddDays(j + 1)
EndDate = DateTime.Now.AddDays(j + 1),
TransportMode = "plane",
};

steps.Add(step);
Expand All @@ -241,7 +242,7 @@ private async Task AddTripsAsync()
TripId = trip.TripId,
OriginStep = steps[k],
DestinationStep = steps[k + 1],
TransportMode = "Mode of Transport",
TransportMode = "plane",
Distance = (decimal)_random.NextDouble() * 1000,
Duration = (decimal)_random.NextDouble() * 24
};
Expand Down
2 changes: 1 addition & 1 deletion Map.EFCore/Interfaces/IStepRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IStepRepository : IGenericRepository<Step>
/// <param name="trip">trip where add step</param>
/// <param name="nextStep">Step before where to add a new step</param>
/// <param name="step">new step to add</param>
public Task AddStepBeforAsync(Trip trip, Step nextStep, Step step);
public Task AddStepBeforeAsync(Trip trip, Step nextStep, Step step);

/// <summary>
/// Add a step to a trip after a step
Expand Down
2 changes: 1 addition & 1 deletion Map.EFCore/Repositories/StepRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task AddStepAfterAsync(Trip trip, Step nextStep, Step step)
}

/// <inheritdoc/>
public async Task AddStepBeforAsync(Trip trip, Step previousStep, Step step)
public async Task AddStepBeforeAsync(Trip trip, Step previousStep, Step step)
{
trip.Steps = trip.Steps.OrderBy(step => step.Order).ToList();
int previousStepIndex = trip.Steps.ToList().FindIndex(s => s.Order == previousStep.Order);
Expand Down
32 changes: 13 additions & 19 deletions Map.EFCore/Repositories/TravelRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,56 @@ public TravelRepository(MapContext context) : base(context)
}

/// <inheritdoc/>
public Task AddLinkedTravelAsync(Step step, Travel travelBefore, Travel travelAfter)
public async Task AddLinkedTravelAsync(Step step, Travel travelBefore, Travel travelAfter)
{
step.TravelBefore = travelBefore;
step.TravelAfter = travelAfter;

return _context.SaveChangesAsync();
await _context.SaveChangesAsync();
}

/// <inheritdoc/>
public Task AddTravelBeforeAsync(Step step, Travel travel)
public async Task AddTravelBeforeAsync(Step step, Travel travel)
{
step.TravelBefore = travel;

return _context.SaveChangesAsync();
await _context.SaveChangesAsync();
}

/// <inheritdoc/>
public Task RemoveLinkedTravelAsync(Step step)
public async Task RemoveLinkedTravelAsync(Step step)
{
if (step.TravelBefore is not null)
{
_context.Travel.Remove(step.TravelBefore);
_context.TravelRoad.Remove(step.TravelBefore.TravelRoad);
await _context.SaveChangesAsync();
}

if (step.TravelAfter is not null)
{
_context.Travel.Remove(step.TravelAfter);
_context.TravelRoad.Remove(step.TravelAfter.TravelRoad);
await _context.SaveChangesAsync();
}

return _context.SaveChangesAsync();

}

/// <inheritdoc/>
public Task RemoveTravelAfterStepAsync(Step step)
public async Task RemoveTravelAfterStepAsync(Step step)
{
if (step.TravelAfter is null)
return Task.CompletedTask;
return;

_context.Travel.Remove(step.TravelAfter);
_context.TravelRoad.Remove(step.TravelAfter.TravelRoad);

return _context.SaveChangesAsync();
await _context.SaveChangesAsync();
}

/// <inheritdoc/>
public Task RemoveTravelBeforeStepAsync(Step step)
public async Task RemoveTravelBeforeStepAsync(Step step)
{
if (step.TravelBefore is null)
return Task.CompletedTask;
return;

_context.Travel.Remove(step.TravelBefore);
_context.TravelRoad.Remove(step.TravelBefore.TravelRoad);

return _context.SaveChangesAsync();
await _context.SaveChangesAsync();
}
}
6 changes: 3 additions & 3 deletions Map.EFCore/Repositories/TripRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public TripRepository(MapContext context) : base(context)

/// <inheritdoc/>
public async Task<Trip?> GetTripByIdAsync(Guid TripId) => await _context.Trip.Include(t => t.Steps)
.Include(t => t.Travels)
.ThenInclude(t => t.TravelRoad)
.FirstOrDefaultAsync(t => t.TripId == TripId);
.Include(t => t.Travels)
.ThenInclude(t => t.TravelRoad)
.FirstOrDefaultAsync(t => t.TripId == TripId);

/// <inheritdoc/>
public async Task<Trip> UpdateAsync(Trip trip, UpdateTripDto update)
Expand Down
1 change: 1 addition & 0 deletions Map.Platform/AuthPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public async Task<SecurityToken> CreateTokenAsync(MapUser user)
{
Subject = new ClaimsIdentity(authClaims),
Expires = DateTime.UtcNow.AddHours(_jwtSettings.DurationTime),
IssuedAt = DateTime.UtcNow,
Issuer = _jwtSettings.ValidIssuer,
Audience = _jwtSettings.ValidAudience,

Expand Down
2 changes: 1 addition & 1 deletion Map.Platform/Interfaces/IStepPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IStepPlatform
/// <param name="trip">trip where add step</param>
/// <param name="nextStep">step where add new step</param>
/// <param name="entity">dto of new</param>
Task AddStepBeforAsync(Trip trip, Step nextStep, Step entity);
Task AddStepBeforeAsync(Trip trip, Step nextStep, Step entity);

/// <summary>
/// Add a step to a trip after a step
Expand Down
4 changes: 2 additions & 2 deletions Map.Platform/StepPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public async Task AddStepAsync(Trip trip, Step entity)
}

/// <inheritdoc/>
public async Task AddStepBeforAsync(Trip trip, Step previousStep, Step entity)
public async Task AddStepBeforeAsync(Trip trip, Step previousStep, Step entity)
{
await _unitOfWork.Travel.RemoveTravelBeforeStepAsync(previousStep);
await _unitOfWork.Step.AddStepBeforAsync(trip, previousStep, entity);
await _unitOfWork.Step.AddStepBeforeAsync(trip, previousStep, entity);
await _unitOfWork.CompleteAsync();
}

Expand Down

0 comments on commit f88048f

Please sign in to comment.