Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e8c8a9e
refactoredLocation
Nov 23, 2021
912c6fb
savedBeforeSwithcing
Nov 24, 2021
71e89ba
justsaved
Nov 24, 2021
6a48a71
RafatctoredLocationLogic
Nov 26, 2021
0d7374d
addedEventLocationViewValidationInEventController
Nov 26, 2021
a26e87d
removedUnnecesaryCodeFromEventValidator
Nov 26, 2021
a151024
DestructuredPropsInLocationComponent
Nov 26, 2021
36b7ea4
RemovedUnnecessaryCodeAndAddNecessary
Nov 29, 2021
64ea743
ChangedSomeTests
Nov 29, 2021
b4168d5
AddedSomeNotVeryGoodCorrectionsInTests
Nov 29, 2021
68699c5
JustWorkingTests
Nov 29, 2021
1dbea26
AddedTestsToEventViewModelValidator
Nov 29, 2021
0e444fb
removedComments
Nov 30, 2021
2b2b7bb
fixedOneTestOnlineMeeting
Nov 30, 2021
85a24f8
fixedLocationTypeCheck
Nov 30, 2021
234950e
ReplacedLocationMapFiledByComponent
Dec 1, 2021
7af6531
removedUnnecessaryCodeRows
Dec 1, 2021
aae9011
tryOneThing
Dec 2, 2021
cf69699
reinstalledMaterial-UI/Lab
Dec 2, 2021
fb55aad
tryWithoutMaterial-ui/lab
Dec 2, 2021
3c3ceb7
AnotherVersionOfMU/lab
Dec 2, 2021
10a4e30
ReinstalledAnotherVersionOfNodeJsAndNpmAndMU/lab
Dec 2, 2021
d492239
TryAnotherMU/labVersion
Dec 2, 2021
69a83f3
replacedAlphaMUByDeprecation
Dec 2, 2021
31090a1
returnedToFirstVersionOfMUi/lab
Dec 2, 2021
fec9be0
tryWithCleardCacheAndNewMUIVersion
Dec 3, 2021
192abae
resetTobeginSettings
Dec 3, 2021
3f1d213
resetTo17alphaVersion
Dec 3, 2021
552d1f9
tryLecacyPeerDeps
Dec 6, 2021
41548ac
tryAgainLegacyPeerDeps
Dec 6, 2021
b3061fc
Merge branch 'development' into 736-FixLocationFieldErrorDisplayng
Dec 6, 2021
d934b19
changedToPreviousMUI/labVersoin
Dec 6, 2021
9228550
removedUnnecessaryCode
Dec 7, 2021
b656761
DeletedDublicationCodeInMappingToLocationDto
Dec 7, 2021
8d118c9
RefactoredMapToLocationMethod
Dec 8, 2021
daeb03b
upgradedPublishMethodOnController
Dec 15, 2021
af15940
removedUnnecesaryMapping
Dec 15, 2021
e52ffd9
removedUnnecessaryCodeFromCreatePointProcess
Dec 15, 2021
ff69d41
movedLocationHelpers
Dec 15, 2021
065931c
PetternMatchFirstVariant
Dec 16, 2021
9dd895e
patternMatchSecondVariant
Dec 16, 2021
541b900
removedUnnecessaryValidator
Dec 16, 2021
1218547
refactoredLocationCodeStructureOnFront
Dec 16, 2021
02175b1
removedUnnecessaryTests
Dec 16, 2021
ff8e3fe
addedSwitchMatchPattern
Dec 17, 2021
c7894d2
addedPublishOkTest
Dec 17, 2021
2b3126f
refactoredCodeStructureOnLocationFrontend
Dec 17, 2021
29aa756
removedUnnecesaryValidatorInjection
Dec 20, 2021
5255fb3
fixtesteventcontrollerconstructor
Dec 20, 2021
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
6 changes: 1 addition & 5 deletions EventsExpress.Core/DTOs/EventDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ public class EventDto

public bool? IsPublic { get; set; }

public Point Point { get; set; }

public LocationType Type { get; set; }

public Uri OnlineMeeting { get; set; }
public LocationDto Location { get; set; }

public IEnumerable<CategoryDto> Categories { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions EventsExpress.Core/DTOs/LocationDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class LocationDto

public Point Point { get; set; }

public Uri OnlineMeeting { get; set; }
public string OnlineMeeting { get; set; }

public LocationType Type { get; set; }
public LocationType? Type { get; set; }
}
}
2 changes: 1 addition & 1 deletion EventsExpress.Core/IServices/ILocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public interface ILocationService

LocationDto LocationByPoint(Point point);

LocationDto LocationByURI(Uri uri);
LocationDto LocationByURI(string uri);
}
}
41 changes: 8 additions & 33 deletions EventsExpress.Core/Services/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class EventService : BaseService<Event>, IEventService
private readonly ILocationService _locationService;
private readonly IMediator _mediator;
private readonly IEventScheduleService _eventScheduleService;
private readonly IValidator<Event> _validator;
private readonly ISecurityContext _securityContextService;

public EventService(
Expand All @@ -36,15 +35,13 @@ public EventService(
IPhotoService photoService,
ILocationService locationService,
IEventScheduleService eventScheduleService,
IValidator<Event> validator,
ISecurityContext securityContextService)
: base(context, mapper)
{
_photoService = photoService;
_locationService = locationService;
_mediator = mediator;
_eventScheduleService = eventScheduleService;
_validator = validator;
_securityContextService = securityContextService;
}

Expand Down Expand Up @@ -156,7 +153,7 @@ public async Task<Guid> Create(EventDto eventDTO)
eventDTO.DateFrom = (eventDTO.DateFrom == DateTime.MinValue) ? DateTime.Today : eventDTO.DateFrom;
eventDTO.DateTo = (eventDTO.DateTo < eventDTO.DateFrom) ? eventDTO.DateFrom : eventDTO.DateTo;

var locationDTO = Mapper.Map<EventDto, LocationDto>(eventDTO);
var locationDTO = eventDTO.Location;
var locationId = await _locationService.AddLocationToEvent(locationDTO);

var ev = Mapper.Map<EventDto, Event>(eventDTO);
Expand Down Expand Up @@ -230,10 +227,9 @@ public async Task<Guid> Edit(EventDto e)
.Include(e => e.EventSchedule)
.FirstOrDefault(x => x.Id == e.Id);

if (e.OnlineMeeting != null || e.Point != null)
if (e.Location != null)
{
var locationDTO = Mapper.Map<EventDto, LocationDto>(e);
var locationId = await _locationService.AddLocationToEvent(locationDTO);
var locationId = await _locationService.AddLocationToEvent(e.Location);
ev.EventLocationId = locationId;
}

Expand Down Expand Up @@ -287,38 +283,17 @@ public async Task<Guid> Publish(Guid eventId)
.ThenInclude(c => c.Category)
.FirstOrDefault(x => x.Id == eventId);

if (ev == null)
{
throw new EventsExpressException("Not found");
}

Dictionary<string, string> exept = new Dictionary<string, string>();
var result = _validator.Validate(ev);

if (result.IsValid)
{
ev.StatusHistory.Add(
ev.StatusHistory.Add(
new EventStatusHistory
{
EventStatus = EventStatus.Active,
CreatedOn = DateTime.UtcNow,
UserId = CurrentUserId(),
});
await Context.SaveChangesAsync();
EventDto dtos = Mapper.Map<Event, EventDto>(ev);
await _mediator.Publish(new EventCreatedMessage(dtos));
return ev.Id;
}
else
{
var p = result.Errors.Select(e => new KeyValuePair<string, string>(e.PropertyName, e.ErrorMessage));
foreach (var x in p)
{
exept.Add(x.Key, x.Value);
}

throw new EventsExpressException("validation failed", exept);
}
await Context.SaveChangesAsync();
EventDto dtos = Mapper.Map<Event, EventDto>(ev);
await _mediator.Publish(new EventCreatedMessage(dtos));
return ev.Id;
}

public async Task<Guid> EditNextEvent(EventDto eventDTO)
Expand Down
2 changes: 1 addition & 1 deletion EventsExpress.Core/Services/LocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public LocationDto LocationByPoint(Point point)
return locationDTO;
}

public LocationDto LocationByURI(Uri uri)
public LocationDto LocationByURI(string uri)
{
var locationDTO = Mapper.Map<LocationDto>(Context.EventLocations
.Where(e =>
Expand Down
4 changes: 2 additions & 2 deletions EventsExpress.Db/Entities/EventLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class EventLocation : BaseEntity
public Point Point { get; set; }

[Track]
public Uri OnlineMeeting { get; set; }
public string OnlineMeeting { get; set; }

[Track]
public LocationType Type { get; set; }
public LocationType? Type { get; set; }
}
}
17 changes: 17 additions & 0 deletions EventsExpress.Test/ControllerTests/EventControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
using EventsExpress.Db.Bridge;
using EventsExpress.Db.Entities;
using EventsExpress.Db.Enums;
using EventsExpress.ExtensionMethods;
using EventsExpress.ViewModels;
using EventsExpress.ViewModels.Base;
using FluentValidation;
using FluentValidation.Results;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
Expand All @@ -34,6 +37,7 @@ internal class EventControllerTests
private Mock<ISecurityContext> mockSecurityContextService;
private Mock<IPhotoService> mockPhotoservice;
private Mock<IValidator<IFormFile>> mockValidator;
private Mock<IValidator<EventViewModel>> mockEventViewModelValidator;
private UserDto _userDto;
private Guid _idUser = Guid.NewGuid();
private Guid _eventId = Guid.NewGuid();
Expand All @@ -51,6 +55,7 @@ protected void Initialize()
mockPhotoservice = new Mock<IPhotoService>();
service = new Mock<IEventService>();
mockValidator = new Mock<IValidator<IFormFile>>();
mockEventViewModelValidator = new Mock<IValidator<EventViewModel>>();
eventController = new EventController(service.Object, MockMapper.Object, mockSecurityContextService.Object, mockPhotoservice.Object);
eventController.ControllerContext = new ControllerContext();
eventController.ControllerContext.HttpContext = new DefaultHttpContext();
Expand Down Expand Up @@ -194,5 +199,17 @@ public void VisitedEvents_OkResult()
var expected = eventController.VisitedEvents(_idUser, 1);
Assert.IsInstanceOf<OkObjectResult>(expected);
}

[Test]
public void Publish_OkResult()
{
mockEventViewModelValidator.Setup(v => v.Validate(It.IsAny<EventViewModel>()))
.Returns(new ValidationResult() { });
MockMapper.Setup(m => m.Map<EventViewModel>(It.IsAny<EventDto>())).Returns(new EventViewModel() { });
service.Setup(e => e.EventById(_eventId)).Returns(new EventDto() { });
service.Setup(e => e.Publish(_eventId)).Returns(Task.FromResult(Guid.NewGuid()));
var expected = eventController.Publish(_eventId, mockEventViewModelValidator.Object);
Assert.IsInstanceOf<OkObjectResult>(expected.Result);
}
}
}
46 changes: 25 additions & 21 deletions EventsExpress.Test/MapperTests/EventMapperProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ private EventDto GetEventDto()
},
},

Type = LocationType.Map,
Point = new Point(8, 3),
Location = new LocationDto
{
Type = LocationType.Map,
Point = new Point(8, 3),
},

Visitors = new List<UserEvent>()
{
new UserEvent
Expand Down Expand Up @@ -343,9 +347,9 @@ public void EventMapperProfile_EventToEventDto()
var e = Mapper.Map<Event, EventDto>(firstEvent);

Assert.That(e.Photo, Is.Null);
Assert.That(e.Point, Is.EqualTo(firstEvent.EventLocation.Point));
Assert.That(e.Type, Is.EqualTo(firstEvent.EventLocation.Type));
Assert.That(e.OnlineMeeting, Is.EqualTo(firstEvent.EventLocation.OnlineMeeting));
Assert.That(e.Location.Point, Is.EqualTo(firstEvent.EventLocation.Point));
Assert.That(e.Location.Type, Is.EqualTo(firstEvent.EventLocation.Type));
Assert.That(e.Location.OnlineMeeting, Is.EqualTo(firstEvent.EventLocation.OnlineMeeting));
Assert.That(e.Owners, Has.All.Matches<User>(ex =>
firstEvent.Owners
.All(f =>
Expand Down Expand Up @@ -407,10 +411,10 @@ public void EventMapperProfile_EventDtoToEventPreviewViewModel()
.All(f =>
ex.Id == f.Id &&
ex.Name == f.Name)));
Assert.That(resEven.Location.Type, Is.EqualTo(firstEventDto.Type));
Assert.That(resEven.Location.OnlineMeeting, Is.EqualTo(firstEventDto.OnlineMeeting));
Assert.That(resEven.Location.Latitude, Is.EqualTo(firstEventDto.Point.X));
Assert.That(resEven.Location.Longitude, Is.EqualTo(firstEventDto.Point.Y));
Assert.That(resEven.Location.Type, Is.EqualTo(firstEventDto.Location.Type));
Assert.That(resEven.Location.OnlineMeeting, Is.EqualTo(firstEventDto.Location.OnlineMeeting));
Assert.That(resEven.Location.Latitude, Is.EqualTo(firstEventDto.Location.Point.X));
Assert.That(resEven.Location.Longitude, Is.EqualTo(firstEventDto.Location.Point.Y));
Assert.That(resEven.CountVisitor, Is.EqualTo(visitorCount));
Assert.That(resEven.MaxParticipants, Is.EqualTo(firstEventDto.MaxParticipants));
Assert.That(resEven.Members, Has.All.Matches<UserPreviewViewModel>(ex =>
Expand Down Expand Up @@ -448,10 +452,10 @@ public void EventMapperProfile_EventDtoToEventViewModel()
ex.UnitOfMeasuring.Id == f.UnitOfMeasuring.Id &&
ex.UnitOfMeasuring.ShortName == f.UnitOfMeasuring.ShortName &&
ex.UnitOfMeasuring.UnitName == f.UnitOfMeasuring.UnitName)));
Assert.That(resView.Location.Type, Is.EqualTo(firstEventDto.Type));
Assert.That(resView.Location.OnlineMeeting, Is.EqualTo(firstEventDto.OnlineMeeting));
Assert.That(resView.Location.Latitude, Is.EqualTo(firstEventDto.Point.X));
Assert.That(resView.Location.Longitude, Is.EqualTo(firstEventDto.Point.Y));
Assert.That(resView.Location.Type, Is.EqualTo(firstEventDto.Location.Type));
Assert.That(resView.Location.OnlineMeeting, Is.EqualTo(firstEventDto.Location.OnlineMeeting));
Assert.That(resView.Location.Latitude, Is.EqualTo(firstEventDto.Location.Point.X));
Assert.That(resView.Location.Longitude, Is.EqualTo(firstEventDto.Location.Point.Y));
Assert.That(resView.Visitors, Has.All.Matches<UserPreviewViewModel>(ex =>
firstEventDto.Visitors
.All(f =>
Expand Down Expand Up @@ -495,11 +499,11 @@ public void EventMapperProfile_EventEditViewModelToEventDto()
firstEventEditViewModel.Owners
.All(f =>
ex == f.Id)));
Assert.That(resDto.Point, Is.EqualTo(firstEventEditViewModel.Location.Type == LocationType.Map ?
Assert.That(resDto.Location.Point, Is.EqualTo(firstEventEditViewModel.Location.Type == LocationType.Map ?
new Point(firstEventEditViewModel.Location.Latitude.Value, firstEventEditViewModel.Location.Longitude.Value) { SRID = 4326 } : null));
Assert.That(resDto.OnlineMeeting, Is.EqualTo(firstEventEditViewModel.Location.Type == LocationType.Online ?
new Uri(firstEventEditViewModel.Location.OnlineMeeting) : null));
Assert.That(resDto.Type, Is.EqualTo(firstEventEditViewModel.Location.Type));
Assert.That(resDto.Location.OnlineMeeting, Is.EqualTo(firstEventEditViewModel.Location.Type == LocationType.Online ?
firstEventEditViewModel.Location.OnlineMeeting : null));
Assert.That(resDto.Location.Type, Is.EqualTo(firstEventEditViewModel.Location.Type));
Assert.That(resDto.Visitors, Is.EqualTo(default(string)));
}

Expand All @@ -518,11 +522,11 @@ public void EventMapperProfile_EventCreateViewModelToEventDto()
firstEventCreateViewModel.Owners
.All(f =>
ex == f.Id)));
Assert.That(resDto.Point, Is.EqualTo(firstEventCreateViewModel.Location.Type == LocationType.Map ?
Assert.That(resDto.Location.Point, Is.EqualTo(firstEventCreateViewModel.Location.Type == LocationType.Map ?
new Point(firstEventCreateViewModel.Location.Latitude.Value, firstEventCreateViewModel.Location.Longitude.Value) { SRID = 4326 } : null));
Assert.That(resDto.OnlineMeeting, Is.EqualTo(firstEventCreateViewModel.Location.Type == LocationType.Online ?
new Uri(firstEventCreateViewModel.Location.OnlineMeeting) : null));
Assert.That(resDto.Type, Is.EqualTo(firstEventCreateViewModel.Location.Type));
Assert.That(resDto.Location.OnlineMeeting, Is.EqualTo(firstEventCreateViewModel.Location.Type == LocationType.Online ?
firstEventCreateViewModel.Location.OnlineMeeting : null));
Assert.That(resDto.Location.Type, Is.EqualTo(firstEventCreateViewModel.Location.Type));
Assert.That(resDto.Periodicity, Is.EqualTo(firstEventCreateViewModel.Periodicity));
Assert.That(resDto.IsReccurent, Is.EqualTo(firstEventCreateViewModel.IsReccurent));
Assert.That(resDto.Inventories, Has.All.Matches<InventoryDto>(ex =>
Expand Down
Loading