Skip to content

Features/rush #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions Map.Api/Controllers/StepController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class StepController : ControllerBase
private readonly IValidator<UpdateStepDescriptionDto> _updateStepDescriptionValidator;
private readonly IValidator<UpdateStepDateDto> _updateStepDateValidator;
private readonly IValidator<UpdateStepLocationDto> _updateStepLocationValidator;
private readonly IValidator<UpdateStepTransportModeDto> _updateStepTransportModeValidator;
private readonly ITripPlatform _tripPlatform;
private readonly IStepPlatform _stepPlatform;

Expand All @@ -39,7 +40,8 @@ public StepController(IMapper mapper,
IValidator<UpdateStepDescriptionDto> updateStepDescriptionValidator,
IValidator<UpdateStepDateDto> updateStepDateValidator,
IValidator<UpdateStepLocationDto> updateStepLocationValidator,
IValidator<UpdateStepNameDto> updateStepNameValidator)
IValidator<UpdateStepNameDto> updateStepNameValidator,
IValidator<UpdateStepTransportModeDto> updateStepTransportModeValidator)
{
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_addStepValidator = addStepValidator ?? throw new ArgumentNullException(nameof(addStepValidator));
Expand All @@ -49,6 +51,7 @@ public StepController(IMapper mapper,
_updateStepDescriptionValidator = updateStepDescriptionValidator ?? throw new ArgumentNullException(nameof(updateStepDescriptionValidator));
_updateStepDateValidator = updateStepDateValidator ?? throw new ArgumentNullException(nameof(updateStepDateValidator));
_updateStepLocationValidator = updateStepLocationValidator ?? throw new ArgumentNullException(nameof(updateStepLocationValidator));
_updateStepTransportModeValidator = updateStepTransportModeValidator ?? throw new ArgumentNullException(nameof(updateStepTransportModeValidator));
}
#endregion

Expand Down Expand Up @@ -101,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 @@ -118,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 @@ -442,6 +445,37 @@ public async Task<ActionResult<StepDto>> UpdateStepLocationAsync([FromRoute] int
return _mapper.Map<Step, StepDto>(step);
}

/// <summary>
/// Update step location
/// </summary>
/// <param name="stepId">Id of wanted Step</param>
/// <param name="updateStepTransportModeDto">updateStepTransportModeDto</param>
/// <returns>Step</returns>
[HttpPatch]
[Route("{stepId}/transportMode")]
[MapToApiVersion(ApiControllerVersions.V1)]
[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<StepDtoList>> UpdateStepTransportModeAsync([FromRoute] int stepId, [FromBody] UpdateStepTransportModeDto updateStepTransportModeDto)
{
ValidationResult validationResult = _updateStepTransportModeValidator.Validate(updateStepTransportModeDto);
if (!validationResult.IsValid)
return BadRequest(validationResult.Errors.Select(e => new Error(e.ErrorCode, e.ErrorMessage)));

Step? step = await _stepPlatform.GetStepByIdAsync(stepId);
if (step is null)
return NotFound(new Error(EStepErrorCodes.StepNotFoundById.ToStringValue(), "Etape non trouvé par id"));

await _stepPlatform.UpdateStepTransportModeAsync(step, updateStepTransportModeDto);

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

#endregion

#region Delete
Expand Down
1 change: 1 addition & 0 deletions Map.Api/Extension/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ private static IServiceCollection AddValidators(this IServiceCollection services
services.AddScoped<IValidator<UpdateStepDescriptionDto>, UpdateStepDescriptionValidator>();
services.AddScoped<IValidator<UpdateStepLocationDto>, UpdateStepLocationValidator>();
services.AddScoped<IValidator<UpdateStepNameDto>, UpdateStepNameValidator>();
services.AddScoped<IValidator<UpdateStepTransportModeDto>, UpdateStepTransportModeValidatior>();
#endregion

#region TravelValidator
Expand Down
10 changes: 8 additions & 2 deletions Map.Api/Validator/StepValidator/AddStepValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ public AddStepValidator(IValidator<AddTravelDto> addTravelValidator)
//check if the latitude is not empty
.NotEmpty()
.WithErrorCode(EStepErrorCodes.LatitudeNotEmpty.ToStringValue())
.WithMessage("Latitude is required");
.WithMessage("La Latitude est requise");

RuleFor(dto => dto.Longitude)
//check if the longitude is not empty
.NotEmpty()
.WithErrorCode(EStepErrorCodes.LongitudeNotEmpty.ToStringValue())
.WithMessage("Longitude is required");
.WithMessage("La longitude est requise");

RuleFor(dto => dto.TransportMode)
//check if the transport mode is not empty
.NotEmpty()
.WithErrorCode(EStepErrorCodes.TransportModeNotEmpty.ToStringValue())
.WithMessage("Les Mode de transport est requis");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using FluentValidation;
using Map.API.Extension;
using Map.Domain.ErrorCodes;
using Map.Domain.Models.Step;

namespace Map.API.Validator.StepValidator;

internal class UpdateStepTransportModeValidatior : AbstractValidator<UpdateStepTransportModeDto>
{
public UpdateStepTransportModeValidatior()
{
RuleFor(dto => dto)
//check if the dto is not empty
.NotEmpty()
.WithErrorCode(EStepErrorCodes.DtoNotNull.ToStringValue())
.WithMessage("Le Dto est requis");

RuleFor(dto => dto.TransportMode)
//check if the transport mode is not empty
.NotEmpty()
.WithErrorCode(EStepErrorCodes.TransportModeNotEmpty.ToStringValue())
.WithMessage("Le mode de transport est requis");
}
}
186 changes: 186 additions & 0 deletions Map.Api/wwwroot/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,170 @@
}
}
},
"/api/v1/Step/{stepId}/transportMode": {
"patch": {
"tags": [
"Step"
],
"summary": "Update step location",
"operationId": "UpdateStepTransportModeAsyncPATCH",
"parameters": [
{
"name": "stepId",
"in": "path",
"description": "Id of wanted Step",
"required": true,
"style": "simple",
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"requestBody": {
"description": "updateStepTransportModeDto",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateStepTransportModeDto"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/UpdateStepTransportModeDto"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/UpdateStepTransportModeDto"
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/StepDto"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/StepDto"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/StepDto"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"500": {
"description": "Server Error",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/api/v1/Testimonial/{userId}": {
"post": {
"tags": [
Expand Down Expand Up @@ -4584,6 +4748,10 @@
"longitude": {
"type": "number",
"format": "double"
},
"transportMode": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
Expand Down Expand Up @@ -4848,6 +5016,10 @@
"type": "number",
"format": "double"
},
"transportMode": {
"type": "string",
"nullable": true
},
"travelBefore": {
"$ref": "#/components/schemas/TravelDto"
},
Expand Down Expand Up @@ -4897,6 +5069,10 @@
"longitude": {
"type": "number",
"format": "double"
},
"transportMode": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
Expand Down Expand Up @@ -5124,6 +5300,16 @@
},
"additionalProperties": false
},
"UpdateStepTransportModeDto": {
"type": "object",
"properties": {
"transportMode": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"UpdateTripDto": {
"type": "object",
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions Map.Domain/Entities/Step.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Step
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }

public string TransportMode { get; set; }

public virtual Travel? TravelBefore { get; set; }
public virtual Travel? TravelAfter { get; set; }

Expand Down
1 change: 1 addition & 0 deletions Map.Domain/ErrorCodes/EStepErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public enum EStepErrorCodes
EndDateNotEmpty = 312,
StartDateNotEmpty = 313,
OrderNotInOrder = 314,
TransportModeNotEmpty = 315,
}
1 change: 1 addition & 0 deletions Map.Domain/Models/Step/AddStepDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class AddStepDto
public DateTime? EndDate { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public string TransportMode { get; set; }
}
1 change: 1 addition & 0 deletions Map.Domain/Models/Step/StepDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class StepDto
public DateTime? EndDate { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public string TransportMode { get; set; }

public virtual TravelDto? TravelBefore { get; set; }
public virtual TravelDto? TravelAfter { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Map.Domain/Models/Step/StepDtoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class StepDtoList
public DateTime? EndDate { get; set; }
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public string TransportMode { get; set; }
}
5 changes: 5 additions & 0 deletions Map.Domain/Models/Step/UpdateStepTransportModeDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Map.Domain.Models.Step;
public class UpdateStepTransportModeDto
{
public string TransportMode { get; set; }
}
Loading
Loading