Skip to content

Commit ed2e61f

Browse files
committed
feat: add user interest toggle endpoint
1 parent e49876e commit ed2e61f

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

backend/src/CCE.Api.External/Endpoints/UserInterestEndpoints.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static IEndpointRouteBuilder MapUserInterestEndpoints(this IEndpointRoute
2424
if (userId == System.Guid.Empty) return Results.Unauthorized();
2525

2626
var result = await mediator.Send(
27-
new UpsertUserInterestCommand(userId, body.Interest), ct).ConfigureAwait(false);
27+
new UpsertUserInterestCommand(userId, body.Interests), ct).ConfigureAwait(false);
2828
return result.ToHttpResult();
2929
})
3030
.WithName("UpsertUserInterest");
@@ -33,4 +33,4 @@ public static IEndpointRouteBuilder MapUserInterestEndpoints(this IEndpointRoute
3333
}
3434
}
3535

36-
public sealed record UpsertUserInterestRequest(string Interest);
36+
public sealed record UpsertUserInterestRequest(IReadOnlyList<string> Interests);

backend/src/CCE.Application/Identity/Public/Commands/UserInterest/UpsertUserInterestCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ namespace CCE.Application.Identity.Public.Commands.UserInterest;
55

66
public sealed record UpsertUserInterestCommand(
77
System.Guid UserId,
8-
string Interest) : IRequest<Response<UpsertUserInterestResult>>;
8+
IReadOnlyList<string> Interests) : IRequest<Response<UpsertUserInterestResult>>;

backend/src/CCE.Application/Identity/Public/Commands/UserInterest/UpsertUserInterestCommandHandler.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using CCE.Application.Common;
23
using CCE.Application.Common.Interfaces;
34
using CCE.Application.Messages;
@@ -30,13 +31,21 @@ public async Task<Response<UpsertUserInterestResult>> Handle(
3031
if (user is null)
3132
return _msg.UserNotFound<UpsertUserInterestResult>();
3233

33-
var added = user.ToggleInterest(request.Interest);
34+
var oldInterests = user.Interests.ToList();
35+
var newList = request.Interests ?? System.Array.Empty<string>();
36+
37+
user.UpdateInterests(newList);
38+
39+
var newInterests = user.Interests;
40+
var added = newInterests.Except(oldInterests).ToList();
41+
var removed = oldInterests.Except(newInterests).ToList();
3442

3543
_service.Update(user);
3644
await _db.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
3745

3846
return _msg.InterestUpserted(new UpsertUserInterestResult(
39-
user.Interests,
40-
added));
47+
newInterests,
48+
added,
49+
removed));
4150
}
4251
}

backend/src/CCE.Application/Identity/Public/Commands/UserInterest/UpsertUserInterestResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ namespace CCE.Application.Identity.Public.Commands.UserInterest;
22

33
public sealed record UpsertUserInterestResult(
44
IReadOnlyList<string> Interests,
5-
bool Added);
5+
IReadOnlyList<string> Added,
6+
IReadOnlyList<string> Removed);

0 commit comments

Comments
 (0)