Skip to content

Commit

Permalink
Updated eventcontroller logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bilimig committed Jun 20, 2024
1 parent 32d432d commit 79a1ff4
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 254 deletions.
287 changes: 120 additions & 167 deletions Server/ReasnAPI/ReasnAPI/Controllers/EventsController.cs

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions Server/ReasnAPI/ReasnAPI/Helpers/EventCreateRequestMapper.cs

This file was deleted.

29 changes: 0 additions & 29 deletions Server/ReasnAPI/ReasnAPI/Helpers/EventResponseMapper.cs

This file was deleted.

27 changes: 0 additions & 27 deletions Server/ReasnAPI/ReasnAPI/Helpers/EventUpdateMapper.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Server/ReasnAPI/ReasnAPI/Mappers/CommentMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Controller;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;

namespace ReasnAPI.Mappers;
Expand Down
56 changes: 55 additions & 1 deletion Server/ReasnAPI/ReasnAPI/Mappers/EventMapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Controller;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using ReasnAPI.Models.Enums;

namespace ReasnAPI.Mappers
{
Expand Down Expand Up @@ -46,5 +48,57 @@ public static Event ToEntity(this EventDto eventDto)
};
}

public static EventResponse ToResponse(this EventDto eventDto, int participating, int interested)
{
return new EventResponse
{
Name = eventDto.Name,
AddressId = eventDto.AddressId,
Description = eventDto.Description,
OrganizerId = eventDto.OrganizerId,
StartAt = eventDto.StartAt,
EndAt = eventDto.EndAt,
CreatedAt = eventDto.CreatedAt,
UpdatedAt = eventDto.UpdatedAt,
Slug = eventDto.Slug,
Status = eventDto.Status,
Tags = eventDto.Tags,
Parameters = eventDto.Parameters,
ParticipatingParticipantsCount = participating,
InterestedParticipantsCount = interested
};
}

public static EventDto ToDto(this EventUpdateRequest eventCreateRequest)
{
return new EventDto()
{
Name = eventCreateRequest.Name,
AddressId = eventCreateRequest.AddressId,
OrganizerId = eventCreateRequest.OrganizerId,
Description = eventCreateRequest.Description,
StartAt = eventCreateRequest.StartAt,
EndAt = eventCreateRequest.EndAt,
Tags = eventCreateRequest.Tags,
Status = eventCreateRequest.Status,
Parameters = eventCreateRequest.Parameters,
};
}
public static EventDto ToDto(this EventCreateRequest eventCreateRequest, int organizerId)
{
return new EventDto()
{
Name = eventCreateRequest.Name,
AddressId = eventCreateRequest.AddressId,
Description = eventCreateRequest.Description,
StartAt = eventCreateRequest.StartAt,
EndAt = eventCreateRequest.EndAt,
Tags = eventCreateRequest.Tags,
Status = EventStatus.PendingApproval,
Parameters = eventCreateRequest.Parameters,
OrganizerId = organizerId
};
}

}
}
14 changes: 13 additions & 1 deletion Server/ReasnAPI/ReasnAPI/Mappers/ParticipantMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Controller;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;

namespace ReasnAPI.Mappers;
Expand Down Expand Up @@ -28,4 +29,15 @@ public static Participant ToEntity(this ParticipantDto participantDto)
Status = participantDto.Status
};
}

public static ParticipantsResponse ToResponse(this List<ParticipantDto> participating,
List<ParticipantDto> interested)
{
return new ParticipantsResponse
{
Participating = participating,
Interested = interested
};
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReasnAPI.Helpers
namespace ReasnAPI.Models.Controller
{
public class CommentRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ReasnAPI.Models.DTOs;
using ReasnAPI.Models.Enums;

namespace ReasnAPI.Helpers
namespace ReasnAPI.Models.Controller
{
public class EventCreateRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ReasnAPI.Models.DTOs;
using ReasnAPI.Models.Enums;

namespace ReasnAPI.Helpers
namespace ReasnAPI.Models.Controller
{
public class EventResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ReasnAPI.Models.DTOs;
using ReasnAPI.Models.Enums;

namespace ReasnAPI.Helpers
namespace ReasnAPI.Models.Controller
{
public class EventUpdateRequest
{
Expand Down
11 changes: 11 additions & 0 deletions Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using ReasnAPI.Models.DTOs;

namespace ReasnAPI.Models.Controller
{
public class ParticipantsResponse
{
public List<ParticipantDto> Participating { get; set; }

Check warning on line 7 in Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (ubuntu-latest)

Non-nullable property 'Participating' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (macos-latest)

Non-nullable property 'Participating' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 7 in Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (windows-latest)

Non-nullable property 'Participating' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<ParticipantDto> Interested { get; set; }

Check warning on line 8 in Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (ubuntu-latest)

Non-nullable property 'Interested' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (macos-latest)

Non-nullable property 'Interested' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Server/ReasnAPI/ReasnAPI/Models/Controller/ParticipantsResponse.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (windows-latest)

Non-nullable property 'Interested' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

}
}

0 comments on commit 79a1ff4

Please sign in to comment.