Skip to content

Commit b2ca833

Browse files
feat: Add LastModifiedByUserId and related properties to MapRotations for better tracking of changes
1 parent f7b0d5e commit b2ca833

12 files changed

Lines changed: 108 additions & 10 deletions

File tree

src/XtremeIdiots.Portal.Repository.Abstractions.V1/Constants/V1/MapRotationsOrder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public enum MapRotationsOrder
1313
CreatedAtAsc,
1414
CreatedAtDesc,
1515
UpdatedAtAsc,
16-
UpdatedAtDesc
16+
UpdatedAtDesc,
17+
CreatedByAsc,
18+
CreatedByDesc
1719
}

src/XtremeIdiots.Portal.Repository.Abstractions.V1/Interfaces/V1/IMapRotationsApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface IMapRotationsApi
1010
Task<ApiResult<MapRotationDto>> GetMapRotation(Guid mapRotationId, CancellationToken cancellationToken = default);
1111
Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(GameType[]? gameTypes, string? gameMode, MapRotationsFilter? filter, int skipEntries, int takeEntries, MapRotationsOrder? order, CancellationToken cancellationToken = default);
1212
Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(GameType[]? gameTypes, string? gameMode, MapRotationStatus? status, string? filterString, MapRotationsFilter? filter, int skipEntries, int takeEntries, MapRotationsOrder? order, CancellationToken cancellationToken = default);
13+
Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(GameType[]? gameTypes, string? gameMode, MapRotationStatus? status, string? filterString, Guid? createdByUserId, MapRotationsFilter? filter, int skipEntries, int takeEntries, MapRotationsOrder? order, CancellationToken cancellationToken = default);
1314
Task<ApiResult<MapRotationDto>> CreateMapRotation(CreateMapRotationDto createMapRotationDto, CancellationToken cancellationToken = default);
1415
Task<ApiResult> UpdateMapRotation(UpdateMapRotationDto updateMapRotationDto, CancellationToken cancellationToken = default);
1516
Task<ApiResult> DeleteMapRotation(Guid mapRotationId, CancellationToken cancellationToken = default);

src/XtremeIdiots.Portal.Repository.Abstractions.V1/Models/V1/MapRotations/MapRotationDto.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public MapRotationDto(Guid mapRotationId, GameType gameType, string title, strin
5757
[JsonProperty]
5858
public string? CreatedByDisplayName { get; set; }
5959

60+
[JsonProperty]
61+
public Guid? LastModifiedByUserId { get; set; }
62+
63+
[JsonProperty]
64+
public string? LastModifiedByDisplayName { get; set; }
65+
6066
[JsonProperty]
6167
public DateTime CreatedAt { get; set; }
6268

src/XtremeIdiots.Portal.Repository.Abstractions.V1/Models/V1/MapRotations/UpdateMapRotationDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public UpdateMapRotationDto(Guid mapRotationId)
3535
[JsonProperty]
3636
public List<Guid>? MapIds { get; set; }
3737

38+
[JsonProperty]
39+
public Guid? LastModifiedByUserId { get; set; }
40+
3841
[JsonIgnore]
3942
public Dictionary<string, string> TelemetryProperties => [];
4043
}

src/XtremeIdiots.Portal.Repository.Api.Client.Testing/Fakes/FakeMapRotationsApi.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ public Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(GameType
5555
return Task.FromResult(new ApiResult<CollectionModel<MapRotationDto>>(HttpStatusCode.OK, new ApiResponse<CollectionModel<MapRotationDto>>(collection)));
5656
}
5757

58+
public Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(GameType[]? gameTypes, string? gameMode, MapRotationStatus? status, string? filterString, Guid? createdByUserId, MapRotationsFilter? filter, int skipEntries, int takeEntries, MapRotationsOrder? order, CancellationToken cancellationToken = default)
59+
{
60+
var items = _mapRotations.Values.AsEnumerable();
61+
if (gameTypes != null) items = items.Where(mr => gameTypes.Contains(mr.GameType));
62+
if (gameMode != null) items = items.Where(mr => mr.GameMode == gameMode);
63+
if (status.HasValue) items = items.Where(mr => mr.Status == status.Value);
64+
if (!string.IsNullOrWhiteSpace(filterString)) items = items.Where(mr => mr.Title.Contains(filterString, StringComparison.OrdinalIgnoreCase));
65+
if (createdByUserId.HasValue) items = items.Where(mr => mr.CreatedByUserId == createdByUserId.Value);
66+
var list = items.Skip(skipEntries).Take(takeEntries).ToList();
67+
var collection = new CollectionModel<MapRotationDto> { Items = list };
68+
return Task.FromResult(new ApiResult<CollectionModel<MapRotationDto>>(HttpStatusCode.OK, new ApiResponse<CollectionModel<MapRotationDto>>(collection)));
69+
}
70+
5871
public Task<ApiResult<MapRotationDto>> CreateMapRotation(CreateMapRotationDto createMapRotationDto, CancellationToken cancellationToken = default)
5972
{
6073
var dto = new MapRotationDto(Guid.NewGuid(), createMapRotationDto.GameType, createMapRotationDto.Title, createMapRotationDto.Description, createMapRotationDto.GameMode, 1, null, DateTime.UtcNow, DateTime.UtcNow, [], []);

src/XtremeIdiots.Portal.Repository.Api.Client.V1/Api/V1/MapRotationsApi.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,39 @@ public async Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(Ga
8080
return response.ToApiResult<CollectionModel<MapRotationDto>>();
8181
}
8282

83+
public async Task<ApiResult<CollectionModel<MapRotationDto>>> GetMapRotations(GameType[]? gameTypes, string? gameMode, MapRotationStatus? status, string? filterString, Guid? createdByUserId, MapRotationsFilter? filter, int skipEntries, int takeEntries, MapRotationsOrder? order, CancellationToken cancellationToken = default)
84+
{
85+
var request = await CreateRequestAsync("v1/map-rotations", Method.Get).ConfigureAwait(false);
86+
87+
if (gameTypes != null)
88+
request.AddQueryParameter("gameTypes", string.Join(",", gameTypes));
89+
90+
if (gameMode != null)
91+
request.AddQueryParameter("gameMode", gameMode);
92+
93+
if (status.HasValue)
94+
request.AddQueryParameter("status", status.ToString());
95+
96+
if (!string.IsNullOrWhiteSpace(filterString))
97+
request.AddQueryParameter("filterString", filterString);
98+
99+
if (createdByUserId.HasValue)
100+
request.AddQueryParameter("createdByUserId", createdByUserId.ToString());
101+
102+
if (filter.HasValue)
103+
request.AddQueryParameter("filter", filter.ToString());
104+
105+
request.AddQueryParameter("skipEntries", skipEntries.ToString());
106+
request.AddQueryParameter("takeEntries", takeEntries.ToString());
107+
108+
if (order.HasValue)
109+
request.AddQueryParameter("order", order.ToString());
110+
111+
var response = await ExecuteAsync(request, cancellationToken).ConfigureAwait(false);
112+
113+
return response.ToApiResult<CollectionModel<MapRotationDto>>();
114+
}
115+
83116
public async Task<ApiResult<MapRotationDto>> CreateMapRotation(CreateMapRotationDto createMapRotationDto, CancellationToken cancellationToken = default)
84117
{
85118
var request = await CreateRequestAsync("v1/map-rotations", Method.Post).ConfigureAwait(false);

src/XtremeIdiots.Portal.Repository.Api.V1/Controllers/V1/MapRotationsController.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public async Task<IActionResult> GetMapRotations(
8585
[FromQuery] string? gameMode = null,
8686
[FromQuery] MapRotationStatus? status = null,
8787
[FromQuery] string? filterString = null,
88+
[FromQuery] Guid? createdByUserId = null,
8889
[FromQuery] MapRotationsFilter? filter = null,
8990
[FromQuery] int skipEntries = 0,
9091
[FromQuery] int takeEntries = 20,
@@ -107,7 +108,7 @@ public async Task<IActionResult> GetMapRotations(
107108
gameTypesFilter = parsed.ToArray();
108109
}
109110

110-
var response = await ((IMapRotationsApi)this).GetMapRotations(gameTypesFilter, gameMode, status, filterString, filter, skipEntries, takeEntries, order, cancellationToken).ConfigureAwait(false);
111+
var response = await ((IMapRotationsApi)this).GetMapRotations(gameTypesFilter, gameMode, status, filterString, createdByUserId, filter, skipEntries, takeEntries, order, cancellationToken).ConfigureAwait(false);
111112
return response.ToHttpResult();
112113
}
113114

@@ -131,7 +132,7 @@ async Task<ApiResult<CollectionModel<MapRotationDto>>> IMapRotationsApi.GetMapRo
131132
MapRotationsOrder? order,
132133
CancellationToken cancellationToken)
133134
{
134-
return await ((IMapRotationsApi)this).GetMapRotations(gameTypes, gameMode, null, null, filter, skipEntries, takeEntries, order, cancellationToken).ConfigureAwait(false);
135+
return await ((IMapRotationsApi)this).GetMapRotations(gameTypes, gameMode, null, null, null, filter, skipEntries, takeEntries, order, cancellationToken).ConfigureAwait(false);
135136
}
136137

137138
async Task<ApiResult<CollectionModel<MapRotationDto>>> IMapRotationsApi.GetMapRotations(
@@ -144,19 +145,35 @@ async Task<ApiResult<CollectionModel<MapRotationDto>>> IMapRotationsApi.GetMapRo
144145
int takeEntries,
145146
MapRotationsOrder? order,
146147
CancellationToken cancellationToken)
148+
{
149+
return await ((IMapRotationsApi)this).GetMapRotations(gameTypes, gameMode, status, filterString, null, filter, skipEntries, takeEntries, order, cancellationToken).ConfigureAwait(false);
150+
}
151+
152+
async Task<ApiResult<CollectionModel<MapRotationDto>>> IMapRotationsApi.GetMapRotations(
153+
GameType[]? gameTypes,
154+
string? gameMode,
155+
MapRotationStatus? status,
156+
string? filterString,
157+
Guid? createdByUserId,
158+
MapRotationsFilter? filter,
159+
int skipEntries,
160+
int takeEntries,
161+
MapRotationsOrder? order,
162+
CancellationToken cancellationToken)
147163
{
148164
var baseQuery = context.MapRotations.AsNoTracking();
149165

150166
var totalCount = await baseQuery.CountAsync(cancellationToken).ConfigureAwait(false);
151167

152-
var filteredQuery = ApplyFilters(baseQuery, gameTypes, gameMode, status, filterString, filter);
168+
var filteredQuery = ApplyFilters(baseQuery, gameTypes, gameMode, status, filterString, createdByUserId, filter);
153169
var filteredCount = await filteredQuery.CountAsync(cancellationToken).ConfigureAwait(false);
154170

155171
var orderedQuery = ApplyOrderingAndPagination(filteredQuery, skipEntries, takeEntries, order);
156172
var results = await orderedQuery
157173
.Include(mr => mr.MapRotationMaps)
158174
.Include(mr => mr.MapRotationServerAssignments)
159175
.Include(mr => mr.CreatedByUser)
176+
.Include(mr => mr.LastModifiedByUser)
160177
.AsSplitQuery()
161178
.ToListAsync(cancellationToken).ConfigureAwait(false);
162179

@@ -773,7 +790,7 @@ async Task<ApiResult> IMapRotationsApi.UpdateAssignmentOperation(Guid operationI
773790

774791
// ───────────────────────── Private Helpers ─────────────────────────
775792

776-
private static IQueryable<MapRotation> ApplyFilters(IQueryable<MapRotation> query, GameType[]? gameTypes, string? gameMode, MapRotationStatus? status, string? filterString, MapRotationsFilter? filter)
793+
private static IQueryable<MapRotation> ApplyFilters(IQueryable<MapRotation> query, GameType[]? gameTypes, string? gameMode, MapRotationStatus? status, string? filterString, Guid? createdByUserId, MapRotationsFilter? filter)
777794
{
778795
if (gameTypes?.Length > 0)
779796
{
@@ -797,6 +814,11 @@ private static IQueryable<MapRotation> ApplyFilters(IQueryable<MapRotation> quer
797814
query = query.Where(mr => mr.Title.Contains(filterString) || (mr.Description != null && mr.Description.Contains(filterString)));
798815
}
799816

817+
if (createdByUserId.HasValue)
818+
{
819+
query = query.Where(mr => mr.CreatedByUserId == createdByUserId.Value);
820+
}
821+
800822
return filter switch
801823
{
802824
MapRotationsFilter.HasActiveAssignments => query.Where(mr => mr.MapRotationServerAssignments.Any(a => a.DeploymentState != (int)DeploymentState.Removed)),
@@ -822,6 +844,8 @@ private static IQueryable<MapRotation> ApplyOrderingAndPagination(IQueryable<Map
822844
MapRotationsOrder.CreatedAtDesc => query.OrderByDescending(mr => mr.CreatedAt),
823845
MapRotationsOrder.UpdatedAtAsc => query.OrderBy(mr => mr.UpdatedAt),
824846
MapRotationsOrder.UpdatedAtDesc => query.OrderByDescending(mr => mr.UpdatedAt),
847+
MapRotationsOrder.CreatedByAsc => query.OrderBy(mr => mr.CreatedByUser != null ? mr.CreatedByUser.DisplayName : ""),
848+
MapRotationsOrder.CreatedByDesc => query.OrderByDescending(mr => mr.CreatedByUser != null ? mr.CreatedByUser.DisplayName : ""),
825849
_ => query.OrderBy(mr => mr.Title)
826850
};
827851

src/XtremeIdiots.Portal.Repository.Api.V1/Mapping/MapRotationsMappingExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public static MapRotationDto ToDto(this MapRotation entity, bool expand = true)
3737
Category = entity.Category,
3838
SequenceOrder = entity.SequenceOrder,
3939
CreatedByUserId = entity.CreatedByUserId,
40-
CreatedByDisplayName = entity.CreatedByUser?.DisplayName
40+
CreatedByDisplayName = entity.CreatedByUser?.DisplayName,
41+
LastModifiedByUserId = entity.LastModifiedByUserId,
42+
LastModifiedByDisplayName = entity.LastModifiedByUser?.DisplayName
4143
};
4244
}
4345

@@ -72,6 +74,7 @@ public static void ApplyTo(this UpdateMapRotationDto dto, MapRotation entity)
7274
if (dto.Status.HasValue) entity.Status = (int)dto.Status.Value;
7375
if (dto.Category is not null) entity.Category = dto.Category;
7476
if (dto.SequenceOrder.HasValue) entity.SequenceOrder = dto.SequenceOrder.Value;
77+
if (dto.LastModifiedByUserId.HasValue) entity.LastModifiedByUserId = dto.LastModifiedByUserId.Value;
7578

7679
entity.UpdatedAt = DateTime.UtcNow;
7780
}

src/XtremeIdiots.Portal.Repository.DataLib/MapRotation.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ public partial class MapRotation
3939

4040
public Guid? CreatedByUserId { get; set; }
4141

42+
public Guid? LastModifiedByUserId { get; set; }
43+
4244
public DateTime CreatedAt { get; set; }
4345

4446
public DateTime UpdatedAt { get; set; }
4547

4648
[ForeignKey("CreatedByUserId")]
47-
[InverseProperty("MapRotations")]
49+
[InverseProperty("MapRotationCreatedByUsers")]
4850
public virtual UserProfile? CreatedByUser { get; set; }
4951

52+
[ForeignKey("LastModifiedByUserId")]
53+
[InverseProperty("MapRotationLastModifiedByUsers")]
54+
public virtual UserProfile? LastModifiedByUser { get; set; }
55+
5056
[InverseProperty("MapRotation")]
5157
public virtual ICollection<MapRotationMap> MapRotationMaps { get; set; } = new List<MapRotationMap>();
5258

src/XtremeIdiots.Portal.Repository.DataLib/PortalDbContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
226226
entity.Property(e => e.UpdatedAt).HasDefaultValueSql("SYSUTCDATETIME()");
227227
entity.Property(e => e.Version).HasDefaultValue(1);
228228

229-
entity.HasOne(d => d.CreatedByUser).WithMany(p => p.MapRotations)
229+
entity.HasOne(d => d.CreatedByUser).WithMany(p => p.MapRotationCreatedByUsers)
230230
.OnDelete(DeleteBehavior.SetNull)
231231
.HasConstraintName("FK_dbo.MapRotations_dbo.UserProfiles_CreatedByUserId");
232+
233+
entity.HasOne(d => d.LastModifiedByUser).WithMany(p => p.MapRotationLastModifiedByUsers).HasConstraintName("FK_dbo.MapRotations_dbo.UserProfiles_LastModifiedByUserId");
232234
});
233235

234236
modelBuilder.Entity<MapRotationAssignmentOperation>(entity =>

0 commit comments

Comments
 (0)