Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions apps/devmx/public/icons/tag-minus.svg
3 changes: 3 additions & 0 deletions apps/devmx/public/icons/tag-plus.svg
3 changes: 3 additions & 0 deletions apps/devmx/public/icons/tag.svg
4 changes: 2 additions & 2 deletions packages/album/data-access/src/lib/album.providers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { provideFacades, provideServices, provideUseCases } from './providers';
import { providePhoto, provideAlbum as $provideAlbum } from './providers';

export function provideAlbum() {
return [...provideServices(), ...provideUseCases(), ...provideFacades()];
return [...providePhoto(), ...$provideAlbum()];
}
12 changes: 10 additions & 2 deletions packages/album/data-access/src/lib/application/photo.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import {
DeletePhotoUseCase,
FindPhotoByIDUseCase,
FindPhotosUseCase,
UpdatePhotoTagsUseCase,
UpdatePhotoUseCase,
UploadPhoto,
UploadPhotoUseCase,
} from '@devmx/album-domain/client';
import { take } from 'rxjs';

export class PhotoFacade extends EntityFacade<Photo> {
constructor(
private createPhotoUseCase: CreatePhotoUseCase,
private findPhotosUseCase: FindPhotosUseCase,
private findPhotoByIdUseCase: FindPhotoByIDUseCase,
private updatePhotoUseCase: UpdatePhotoUseCase,
private updatePhotoTagsUseCase: UpdatePhotoTagsUseCase,
private deletePhotoUseCase: DeletePhotoUseCase,
private uploadPhotoUseCase: UploadPhotoUseCase
) {
Expand Down Expand Up @@ -49,11 +52,15 @@ export class PhotoFacade extends EntityFacade<Photo> {
update(data: EditablePhoto) {
const request$ = this.updatePhotoUseCase.execute(data);

this.onUpdate(request$);
// this.onUpdate(request$);

this.loadOne(data.id);

return request$;
return request$.pipe(take(1));
}

updateTags(data: EditablePhoto) {
this.onUpdate(this.updatePhotoTagsUseCase.execute(data));
}

delete(id: string) {
Expand All @@ -67,6 +74,7 @@ export function providePhotoFacade() {
FindPhotosUseCase,
FindPhotoByIDUseCase,
UpdatePhotoUseCase,
UpdatePhotoTagsUseCase,
DeletePhotoUseCase,
UploadPhotoUseCase,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export class PhotoHttpServiceImpl
extends HttpService<Photo>
implements PhotoService
{
updateTags(id: string, data: Photo) {
const url = [this.url, id, 'tags'];
return this.http.patch<Photo>(url.join('/'), data);
}

upload({ photo, ...value }: UploadPhoto) {
const data = new FormData();

Expand Down
23 changes: 23 additions & 0 deletions packages/album/data-access/src/lib/providers/album.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { provideAlbumHttpService } from '../infrastrucure';
import { provideAlbumFacade } from '../application';
import {
provideCreateAlbumUseCase,
provideDeleteAlbumUseCase,
provideFindAlbumByIDUseCase,
provideFindAlbumsUseCase,
provideUpdateAlbumUseCase,
} from '@devmx/album-domain/client';

export function provideAlbum() {
return [
provideAlbumHttpService(),

provideCreateAlbumUseCase(),
provideDeleteAlbumUseCase(),
provideFindAlbumByIDUseCase(),
provideFindAlbumsUseCase(),
provideUpdateAlbumUseCase(),

provideAlbumFacade(),
];
}
5 changes: 0 additions & 5 deletions packages/album/data-access/src/lib/providers/facades.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/album/data-access/src/lib/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './facades';
export * from './services';
export * from './use-cases';
export * from './album';
export * from './photo';
27 changes: 27 additions & 0 deletions packages/album/data-access/src/lib/providers/photo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { providePhotoHttpService } from '../infrastrucure';
import { providePhotoFacade } from '../application';
import {
provideCreatePhotoUseCase,
provideDeletePhotoUseCase,
provideFindPhotoByIDUseCase,
provideFindPhotosUseCase,
provideUpdatePhotoTagsUseCase,
provideUpdatePhotoUseCase,
provideUploadPhotoUseCase,
} from '@devmx/album-domain/client';

export function providePhoto() {
return [
providePhotoHttpService(),

provideCreatePhotoUseCase(),
provideDeletePhotoUseCase(),
provideFindPhotoByIDUseCase(),
provideFindPhotosUseCase(),
provideUpdatePhotoTagsUseCase(),
provideUpdatePhotoUseCase(),
provideUploadPhotoUseCase(),

providePhotoFacade(),
];
}
8 changes: 0 additions & 8 deletions packages/album/data-access/src/lib/providers/services.ts

This file was deleted.

73 changes: 0 additions & 73 deletions packages/album/data-access/src/lib/providers/use-cases.ts

This file was deleted.

11 changes: 6 additions & 5 deletions packages/album/data-source/src/lib/dtos/create-photo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNumber, IsOptional, IsString } from 'class-validator';
import { UserRef } from '@devmx/shared-api-interfaces';
import { UserRefDto } from '@devmx/shared-data-source';
import { UserTag } from '@devmx/shared-api-interfaces';
import { UserTagDto } from '@devmx/shared-data-source';
import { CreatePhoto } from '@devmx/album-domain';
import { Exclude, Type } from 'class-transformer';

Expand All @@ -14,7 +14,8 @@ export class CreatePhotoDto implements CreatePhoto {
caption?: string;

@IsString()
@ApiProperty()
@IsOptional()
@ApiPropertyOptional()
album: string;

@IsNumber()
Expand All @@ -35,8 +36,8 @@ export class CreatePhotoDto implements CreatePhoto {
@ApiPropertyOptional()
type: string;

@Type(() => UserRefDto)
tagged?: UserRef[];
@Type(() => UserTagDto)
tags?: UserTag[];

owner: string;
}
11 changes: 7 additions & 4 deletions packages/album/data-source/src/lib/dtos/photo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AlbumRefDto, UserRefDto, UserTagDto } from '@devmx/shared-data-source';
import { ImageMimeType, Photo } from '@devmx/shared-api-interfaces';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { AlbumRefDto, UserRefDto } from '@devmx/shared-data-source';
import { Exclude, Type } from 'class-transformer';

export class PhotoDto implements Photo {
Expand All @@ -25,9 +25,12 @@ export class PhotoDto implements Photo {
@Exclude()
content: Buffer;

@ApiPropertyOptional({ type: () => [UserRefDto] })
@Type(() => UserRefDto)
tagged?: UserRefDto[];
@Exclude()
tagged: UserRefDto[];

@ApiProperty({ type: () => [UserTagDto] })
@Type(() => UserTagDto)
tags: UserTagDto[] = [];

@ApiProperty({ type: () => Date })
@Type(() => Date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export class AlbumsMongoServiceImpl
.populate('contributors', 'name displayName');

if (method === 'findOne') {
query = query.populate('photos', 'type content caption createdAt');
query = query.populate(
'photos',
'type content caption width height tags createdAt'
);
} else {
query = query.select('-photos');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ export class PhotosMongoServiceImpl
protected override applyPopulate<U>(query: Query<U, PhotoCollection>) {
return query
.populate('owner', 'name displayName')
.populate('tagged', 'name displayName profile')
.populate('album', 'title createdAt');
.populate('album', 'title createdAt')
.populate('tags');
}

protected override applyEditableParser<U>(
data: EditableEntity<PhotoCollection>
): U {
const tagged = (data.tagged ?? []).map((p) => {
return typeof p === 'string' ? p : p.id;
});
// const tagged = (data.tags ?? []).map((p) => {
// return typeof p === 'string' ? p : p.id;
// });

const album = typeof data.album === 'string' ? data.album : data.album.id;

const owner = typeof data.owner === 'string' ? data.owner : data.owner.id;

return { ...data, album, owner, tagged } as U;
return { ...data, album, owner } as U;
}
}

Expand Down
17 changes: 11 additions & 6 deletions packages/album/data-source/src/lib/schemas/photo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Album, ImageMimeType, Photo } from '@devmx/shared-api-interfaces';
import { UserCollection } from '@devmx/account-data-source';
import { createSchema } from '@devmx/shared-data-source';
import { Prop, Schema } from '@nestjs/mongoose';
import mongoose, { Document } from 'mongoose';
import { userTag } from './user-tag';
import { toBase64 } from '../utils';
import {
Album,
Photo,
UserTag,
ImageMimeType,
} from '@devmx/shared-api-interfaces';

function toBase64(type: string, content: string) {
return `data:${type};base64,${content}`;
}

@Schema({ timestamps: { createdAt: true } })
export class PhotoCollection extends Document implements Photo {
Expand Down Expand Up @@ -49,9 +53,10 @@ export class PhotoCollection extends Document implements Photo {
caption?: string;

@Prop({
type: [{ type: mongoose.Schema.Types.ObjectId, ref: UserCollection.name }],
type: [userTag],
default: [],
})
tagged: UserCollection[];
tags?: UserTag[];

@Prop({
type: mongoose.Schema.Types.ObjectId,
Expand Down
11 changes: 11 additions & 0 deletions packages/album/data-source/src/lib/schemas/user-tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mongoose from 'mongoose';

export const userTag = {
x: Number,
y: Number,
user: {
id: mongoose.Schema.Types.ObjectId,
displayName: String,
name: String,
},
};
1 change: 1 addition & 0 deletions packages/album/data-source/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './to-base64';
3 changes: 3 additions & 0 deletions packages/album/data-source/src/lib/utils/to-base64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function toBase64(type: string, content: string) {
return `data:${type};base64,${content}`;
}
3 changes: 2 additions & 1 deletion packages/album/domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"tslib": "^2.3.0",
"@devmx/shared-api-interfaces": "0.0.1",
"rxjs": "^7.8.0",
"@devmx/shared-util-errors": "0.0.1"
"@devmx/shared-util-errors": "0.0.1",
"@devmx/shared-util-data": "0.0.1"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/album/domain/src/client/services/photo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { HttpProgressEvent } from '@devmx/shared-api-interfaces/client';
import { EntityService } from '@devmx/shared-api-interfaces/client';
import { Photo } from '@devmx/shared-api-interfaces';
import { EditablePhoto, Photo } from '@devmx/shared-api-interfaces';
import { UploadPhoto } from '../dtos';
import { Observable } from 'rxjs';

export abstract class PhotoService extends EntityService<Photo> {
abstract updateTags(id: string, data: EditablePhoto): Observable<Photo>;

abstract upload(data: UploadPhoto): Observable<HttpProgressEvent>;
}
Loading
Loading