mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02:00
fix: show/set activity like per user (#4775)
* fix: like per user * chore: open api * chore: e2e test for userId filtering
This commit is contained in:
parent
cf4ec06750
commit
0130591a0f
23
cli/src/api/open-api/api.ts
generated
23
cli/src/api/open-api/api.ts
generated
@ -5076,10 +5076,11 @@ export const ActivityApiAxiosParamCreator = function (configuration?: Configurat
|
|||||||
* @param {string} albumId
|
* @param {string} albumId
|
||||||
* @param {string} [assetId]
|
* @param {string} [assetId]
|
||||||
* @param {ReactionType} [type]
|
* @param {ReactionType} [type]
|
||||||
|
* @param {string} [userId]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
getActivities: async (albumId: string, assetId?: string, type?: ReactionType, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
getActivities: async (albumId: string, assetId?: string, type?: ReactionType, userId?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||||
// verify required parameter 'albumId' is not null or undefined
|
// verify required parameter 'albumId' is not null or undefined
|
||||||
assertParamExists('getActivities', 'albumId', albumId)
|
assertParamExists('getActivities', 'albumId', albumId)
|
||||||
const localVarPath = `/activity`;
|
const localVarPath = `/activity`;
|
||||||
@ -5115,6 +5116,10 @@ export const ActivityApiAxiosParamCreator = function (configuration?: Configurat
|
|||||||
localVarQueryParameter['type'] = type;
|
localVarQueryParameter['type'] = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userId !== undefined) {
|
||||||
|
localVarQueryParameter['userId'] = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||||
@ -5211,11 +5216,12 @@ export const ActivityApiFp = function(configuration?: Configuration) {
|
|||||||
* @param {string} albumId
|
* @param {string} albumId
|
||||||
* @param {string} [assetId]
|
* @param {string} [assetId]
|
||||||
* @param {ReactionType} [type]
|
* @param {ReactionType} [type]
|
||||||
|
* @param {string} [userId]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
async getActivities(albumId: string, assetId?: string, type?: ReactionType, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<ActivityResponseDto>>> {
|
async getActivities(albumId: string, assetId?: string, type?: ReactionType, userId?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<ActivityResponseDto>>> {
|
||||||
const localVarAxiosArgs = await localVarAxiosParamCreator.getActivities(albumId, assetId, type, options);
|
const localVarAxiosArgs = await localVarAxiosParamCreator.getActivities(albumId, assetId, type, userId, options);
|
||||||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -5264,7 +5270,7 @@ export const ActivityApiFactory = function (configuration?: Configuration, baseP
|
|||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig): AxiosPromise<Array<ActivityResponseDto>> {
|
getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig): AxiosPromise<Array<ActivityResponseDto>> {
|
||||||
return localVarFp.getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, options).then((request) => request(axios, basePath));
|
return localVarFp.getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, requestParameters.userId, options).then((request) => request(axios, basePath));
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -5332,6 +5338,13 @@ export interface ActivityApiGetActivitiesRequest {
|
|||||||
* @memberof ActivityApiGetActivities
|
* @memberof ActivityApiGetActivities
|
||||||
*/
|
*/
|
||||||
readonly type?: ReactionType
|
readonly type?: ReactionType
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof ActivityApiGetActivities
|
||||||
|
*/
|
||||||
|
readonly userId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5392,7 +5405,7 @@ export class ActivityApi extends BaseAPI {
|
|||||||
* @memberof ActivityApi
|
* @memberof ActivityApi
|
||||||
*/
|
*/
|
||||||
public getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig) {
|
public getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig) {
|
||||||
return ActivityApiFp(this.configuration).getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, options).then((request) => request(this.axios, this.basePath));
|
return ActivityApiFp(this.configuration).getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, requestParameters.userId, options).then((request) => request(this.axios, this.basePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
BIN
mobile/openapi/doc/ActivityApi.md
generated
BIN
mobile/openapi/doc/ActivityApi.md
generated
Binary file not shown.
BIN
mobile/openapi/lib/api/activity_api.dart
generated
BIN
mobile/openapi/lib/api/activity_api.dart
generated
Binary file not shown.
BIN
mobile/openapi/test/activity_api_test.dart
generated
BIN
mobile/openapi/test/activity_api_test.dart
generated
Binary file not shown.
@ -30,6 +30,15 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/ReactionType"
|
"$ref": "#/components/schemas/ReactionType"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "userId",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"format": "uuid",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
@ -38,6 +38,9 @@ export class ActivitySearchDto extends ActivityDto {
|
|||||||
@Optional()
|
@Optional()
|
||||||
@ApiProperty({ enumName: 'ReactionType', enum: ReactionType })
|
@ApiProperty({ enumName: 'ReactionType', enum: ReactionType })
|
||||||
type?: ReactionType;
|
type?: ReactionType;
|
||||||
|
|
||||||
|
@ValidateUUID({ optional: true })
|
||||||
|
userId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isComment = (dto: ActivityCreateDto) => dto.type === 'comment';
|
const isComment = (dto: ActivityCreateDto) => dto.type === 'comment';
|
||||||
|
@ -28,6 +28,7 @@ export class ActivityService {
|
|||||||
async getAll(authUser: AuthUserDto, dto: ActivitySearchDto): Promise<ActivityResponseDto[]> {
|
async getAll(authUser: AuthUserDto, dto: ActivitySearchDto): Promise<ActivityResponseDto[]> {
|
||||||
await this.access.requirePermission(authUser, Permission.ALBUM_READ, dto.albumId);
|
await this.access.requirePermission(authUser, Permission.ALBUM_READ, dto.albumId);
|
||||||
const activities = await this.repository.search({
|
const activities = await this.repository.search({
|
||||||
|
userId: dto.userId,
|
||||||
albumId: dto.albumId,
|
albumId: dto.albumId,
|
||||||
assetId: dto.assetId,
|
assetId: dto.assetId,
|
||||||
isLiked: dto.type && dto.type === ReactionType.LIKE,
|
isLiked: dto.type && dto.type === ReactionType.LIKE,
|
||||||
|
@ -134,6 +134,29 @@ describe(`${ActivityController.name} (e2e)`, () => {
|
|||||||
expect(body[0]).toEqual(reaction);
|
expect(body[0]).toEqual(reaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should filter by userId', async () => {
|
||||||
|
const [reaction] = await Promise.all([
|
||||||
|
api.activityApi.create(server, admin.accessToken, { albumId: album.id, type: ReactionType.LIKE }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const response1 = await request(server)
|
||||||
|
.get('/activity')
|
||||||
|
.query({ albumId: album.id, userId: uuidStub.notFound })
|
||||||
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
||||||
|
|
||||||
|
expect(response1.status).toEqual(200);
|
||||||
|
expect(response1.body.length).toBe(0);
|
||||||
|
|
||||||
|
const response2 = await request(server)
|
||||||
|
.get('/activity')
|
||||||
|
.query({ albumId: album.id, userId: admin.userId })
|
||||||
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
||||||
|
|
||||||
|
expect(response2.status).toEqual(200);
|
||||||
|
expect(response2.body.length).toBe(1);
|
||||||
|
expect(response2.body[0]).toEqual(reaction);
|
||||||
|
});
|
||||||
|
|
||||||
it('should filter by assetId', async () => {
|
it('should filter by assetId', async () => {
|
||||||
const [reaction] = await Promise.all([
|
const [reaction] = await Promise.all([
|
||||||
api.activityApi.create(server, admin.accessToken, {
|
api.activityApi.create(server, admin.accessToken, {
|
||||||
|
23
web/src/api/open-api/api.ts
generated
23
web/src/api/open-api/api.ts
generated
@ -5076,10 +5076,11 @@ export const ActivityApiAxiosParamCreator = function (configuration?: Configurat
|
|||||||
* @param {string} albumId
|
* @param {string} albumId
|
||||||
* @param {string} [assetId]
|
* @param {string} [assetId]
|
||||||
* @param {ReactionType} [type]
|
* @param {ReactionType} [type]
|
||||||
|
* @param {string} [userId]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
getActivities: async (albumId: string, assetId?: string, type?: ReactionType, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
getActivities: async (albumId: string, assetId?: string, type?: ReactionType, userId?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||||
// verify required parameter 'albumId' is not null or undefined
|
// verify required parameter 'albumId' is not null or undefined
|
||||||
assertParamExists('getActivities', 'albumId', albumId)
|
assertParamExists('getActivities', 'albumId', albumId)
|
||||||
const localVarPath = `/activity`;
|
const localVarPath = `/activity`;
|
||||||
@ -5115,6 +5116,10 @@ export const ActivityApiAxiosParamCreator = function (configuration?: Configurat
|
|||||||
localVarQueryParameter['type'] = type;
|
localVarQueryParameter['type'] = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userId !== undefined) {
|
||||||
|
localVarQueryParameter['userId'] = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||||
@ -5211,11 +5216,12 @@ export const ActivityApiFp = function(configuration?: Configuration) {
|
|||||||
* @param {string} albumId
|
* @param {string} albumId
|
||||||
* @param {string} [assetId]
|
* @param {string} [assetId]
|
||||||
* @param {ReactionType} [type]
|
* @param {ReactionType} [type]
|
||||||
|
* @param {string} [userId]
|
||||||
* @param {*} [options] Override http request option.
|
* @param {*} [options] Override http request option.
|
||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
async getActivities(albumId: string, assetId?: string, type?: ReactionType, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<ActivityResponseDto>>> {
|
async getActivities(albumId: string, assetId?: string, type?: ReactionType, userId?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<ActivityResponseDto>>> {
|
||||||
const localVarAxiosArgs = await localVarAxiosParamCreator.getActivities(albumId, assetId, type, options);
|
const localVarAxiosArgs = await localVarAxiosParamCreator.getActivities(albumId, assetId, type, userId, options);
|
||||||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -5264,7 +5270,7 @@ export const ActivityApiFactory = function (configuration?: Configuration, baseP
|
|||||||
* @throws {RequiredError}
|
* @throws {RequiredError}
|
||||||
*/
|
*/
|
||||||
getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig): AxiosPromise<Array<ActivityResponseDto>> {
|
getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig): AxiosPromise<Array<ActivityResponseDto>> {
|
||||||
return localVarFp.getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, options).then((request) => request(axios, basePath));
|
return localVarFp.getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, requestParameters.userId, options).then((request) => request(axios, basePath));
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -5332,6 +5338,13 @@ export interface ActivityApiGetActivitiesRequest {
|
|||||||
* @memberof ActivityApiGetActivities
|
* @memberof ActivityApiGetActivities
|
||||||
*/
|
*/
|
||||||
readonly type?: ReactionType
|
readonly type?: ReactionType
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof ActivityApiGetActivities
|
||||||
|
*/
|
||||||
|
readonly userId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5392,7 +5405,7 @@ export class ActivityApi extends BaseAPI {
|
|||||||
* @memberof ActivityApi
|
* @memberof ActivityApi
|
||||||
*/
|
*/
|
||||||
public getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig) {
|
public getActivities(requestParameters: ActivityApiGetActivitiesRequest, options?: AxiosRequestConfig) {
|
||||||
return ActivityApiFp(this.configuration).getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, options).then((request) => request(this.axios, this.basePath));
|
return ActivityApiFp(this.configuration).getActivities(requestParameters.albumId, requestParameters.assetId, requestParameters.type, requestParameters.userId, options).then((request) => request(this.axios, this.basePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,9 +123,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getFavorite = async () => {
|
const getFavorite = async () => {
|
||||||
if (album) {
|
if (album && user) {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.activityApi.getActivities({
|
const { data } = await api.activityApi.getActivities({
|
||||||
|
userId: user.id,
|
||||||
assetId: asset.id,
|
assetId: asset.id,
|
||||||
albumId: album.id,
|
albumId: album.id,
|
||||||
type: ReactionType.Like,
|
type: ReactionType.Like,
|
||||||
|
Loading…
Reference in New Issue
Block a user