Skip to content

Commit

Permalink
FIX Update Distance & Time of TRavel
Browse files Browse the repository at this point in the history
- content
  • Loading branch information
Dercraker committed Mar 31, 2024
1 parent 6f31918 commit 7137c93
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 50 deletions.
1 change: 0 additions & 1 deletion Map.Api/AutoMapperProfies/TravelProfiles.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutoMapper;
using Map.Domain.Entities;
using Map.Domain.Models.AddTravel;
using Map.Domain.Models.Travels;

namespace Map.API.AutoMapperProfies;
Expand Down
2 changes: 1 addition & 1 deletion Map.Api/Controllers/TravelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using FluentValidation.Results;
using Map.Domain.Entities;
using Map.Domain.ErrorCodes;
using Map.Domain.Models.AddTravel;
using Map.Domain.Models.Travels;
using Map.Platform.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down
2 changes: 1 addition & 1 deletion Map.Api/Extension/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
using Map.API.Validator.TripValidator;
using Map.API.Validator.UserValidator;
using Map.Domain.Entities;
using Map.Domain.Models.AddTravel;
using Map.Domain.Models.Auth;
using Map.Domain.Models.Step;
using Map.Domain.Models.Testimonial;
using Map.Domain.Models.Travels;
using Map.Domain.Models.Trip;
using Map.Domain.Models.User;
using Map.Domain.Settings;
Expand Down
2 changes: 1 addition & 1 deletion Map.Api/Validator/StepValidator/AddStepValidator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using FluentValidation;
using Map.API.Extension;
using Map.Domain.ErrorCodes;
using Map.Domain.Models.AddTravel;
using Map.Domain.Models.Step;
using Map.Domain.Models.Travels;

namespace Map.API.Validator.StepValidator;

Expand Down
2 changes: 1 addition & 1 deletion Map.Api/Validator/TravelValidator/AddTravelValidator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FluentValidation;
using Map.Domain.Entities;
using Map.Domain.ErrorCodes;
using Map.Domain.Models.AddTravel;
using Map.Domain.Models.Travels;
using Map.Platform.Interfaces;

namespace Map.API.Validator.TravelValidator;
Expand Down
24 changes: 12 additions & 12 deletions Map.Api/wwwroot/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4782,12 +4782,12 @@
"nullable": true
},
"distance": {
"type": "number",
"format": "double"
"type": "integer",
"format": "int32"
},
"duration": {
"type": "number",
"format": "double"
"type": "integer",
"format": "int32"
},
"originStepId": {
"type": "integer",
Expand Down Expand Up @@ -5142,12 +5142,12 @@
"nullable": true
},
"distance": {
"type": "number",
"format": "double"
"type": "integer",
"format": "int32"
},
"duration": {
"type": "number",
"format": "double"
"type": "integer",
"format": "int32"
},
"travelRoad": {
"$ref": "#/components/schemas/TravelRoadDto"
Expand Down Expand Up @@ -5175,12 +5175,12 @@
"nullable": true
},
"distance": {
"type": "number",
"format": "double"
"type": "integer",
"format": "int32"
},
"duration": {
"type": "number",
"format": "double"
"type": "integer",
"format": "int32"
},
"travelRoad": {
"$ref": "#/components/schemas/TravelRoadDto"
Expand Down
4 changes: 2 additions & 2 deletions Map.Domain/Entities/Travel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class Travel
public virtual Step? DestinationStep { get; set; }

public string TransportMode { get; set; }
public decimal Distance { get; set; }
public decimal Duration { get; set; }
public int Distance { get; set; }
public int Duration { get; set; }

public virtual TravelRoad? TravelRoad { get; set; }
}
6 changes: 3 additions & 3 deletions Map.Domain/Models/Travels/AddTravelDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Map.Domain.Models.AddTravel;
namespace Map.Domain.Models.Travels;
public class AddTravelDto
{
public string TransportMode { get; set; }
public decimal Distance { get; set; }
public decimal Duration { get; set; }
public int Distance { get; set; }
public int Duration { get; set; }
public int OriginStepId { get; set; }
public int DestinationStepId { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions Map.Domain/Models/Travels/TravelDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class TravelDto
public virtual StepDto? DestinationStep { get; set; }

public string TransportMode { get; set; }
public decimal Distance { get; set; }
public decimal Duration { get; set; }
public int Distance { get; set; }
public int Duration { get; set; }

public virtual TravelRoadDto? TravelRoad { get; set; }
}
4 changes: 2 additions & 2 deletions Map.Domain/Models/Travels/TravelDtoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class TravelDtoList
public int DestinationStepId { get; set; }

public string TransportMode { get; set; }
public decimal Distance { get; set; }
public decimal Duration { get; set; }
public int Distance { get; set; }
public int Duration { get; set; }

public virtual TravelRoadDto? TravelRoad { get; set; }
}
26 changes: 12 additions & 14 deletions Map.EFCore/Data/DBInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ private async Task AddSingleUserAsync()
PhoneNumberConfirmed = true,
};


IdentityResult resultAddUser = await _userManager.CreateAsync(simpleUser, _password);
if (!resultAddUser.Succeeded)
throw new ApplicationException("Adding user '" + simpleUser.UserName + "' failed with error(s): " + resultAddUser.Errors);
Expand All @@ -131,7 +130,7 @@ private async Task AddSingleUserAsync()

private async Task AddUsersAsync()
{
List<MapUser> mapUsers = new List<MapUser>
List<MapUser> mapUsers = new()
{
new MapUser
{
Expand Down Expand Up @@ -175,7 +174,7 @@ private async Task AddUsersAsync()
},
};

Random random = new Random();
Random random = new();
foreach (MapUser user in mapUsers)
{
user.EmailConfirmed = random.Next(2) == 0;
Expand All @@ -199,7 +198,7 @@ private async Task AddTripsAsync()
int numTrips = _random.Next(2, 11);
for (int i = 0; i < numTrips; i++)
{
Trip trip = new Trip
Trip trip = new()
{
User = user,
Name = $"Trip {i + 1} for {user.UserName}",
Expand All @@ -212,17 +211,17 @@ private async Task AddTripsAsync()
await _context.Trip.AddAsync(trip);

int numSteps = _random.Next(5, 15);
List<Step> steps = new List<Step>();
List<Step> steps = new();

for (int j = 0; j < numSteps; j++)
{
Step step = new Step
Step step = new()
{
TripId = trip.TripId,
Order = j + 1,
Name = $"Step {j + 1} for Trip {i + 1} of user {user.UserName}",
Longitude = (decimal)(_random.NextDouble() * 360 - 180),
Latitude = (decimal)(_random.NextDouble() * 180 - 90),
Longitude = (decimal)((_random.NextDouble() * 360) - 180),
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),
Expand All @@ -237,16 +236,16 @@ private async Task AddTripsAsync()

for (int k = 0; k < steps.Count - 1; k++)
{
Travel travel = new Travel
Travel travel = new()
{
TripId = trip.TripId,
OriginStep = steps[k],
DestinationStep = steps[k + 1],
TransportMode = "plane",
Distance = (decimal)_random.NextDouble() * 1000,
Duration = (decimal)_random.NextDouble() * 24
Distance = (int)_random.Next() * 1000,
Duration = (int)_random.Next() * 60
};
TravelRoad travelRoad = new TravelRoad
TravelRoad travelRoad = new()
{
TravelId = travel.TravelId,
Travel = travel,
Expand All @@ -268,7 +267,7 @@ private async Task GenerateTestimonialsAsync()
int numTestimonials = _random.Next(1, 4);
for (int i = 0; i < numTestimonials; i++)
{
Testimonial testimonial = new Testimonial
Testimonial testimonial = new()
{
FeedBack = GenerateRandomFeedback(),
UserId = user.Id,
Expand Down Expand Up @@ -299,6 +298,5 @@ private string GenerateRandomFeedback()
return feedbacks[_random.Next(feedbacks.Length)];
}


}

6 changes: 2 additions & 4 deletions Map.EFCore/MapContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ protected override void OnModelCreating(ModelBuilder builder)
s.Property(s => s.StartDate).IsRequired(false);
s.Property(s => s.EndDate).IsRequired(false);



s.HasOne(s => s.Trip)
.WithMany(t => t.Steps)
.HasForeignKey(s => s.TripId)
Expand All @@ -112,8 +110,8 @@ protected override void OnModelCreating(ModelBuilder builder)
t.Property(t => t.OriginStepId).IsRequired();
t.Property(t => t.DestinationStepId).IsRequired();
t.Property(t => t.TransportMode).IsRequired();
t.Property(t => t.Distance).HasPrecision(18, 12).IsRequired();
t.Property(t => t.Duration).HasPrecision(18, 12).IsRequired();
t.Property(t => t.Distance).IsRequired();
t.Property(t => t.Duration).IsRequired();

t.HasOne(t => t.OriginStep)
.WithOne(s => s.TravelAfter)
Expand Down
Loading

0 comments on commit 7137c93

Please sign in to comment.