Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/benho-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
modsyan committed May 20, 2024
2 parents ee9abcc + c994cc7 commit b6e10fc
Show file tree
Hide file tree
Showing 49 changed files with 861 additions and 350 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
backend/node_modules/
26 changes: 26 additions & 0 deletions backend/src/infrastructure/like-comments/like-comment.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { UserMapper } from '@infrastructure/users';
import { LikeCommentPersistence } from './like-comment.persistence';
import { LikeComment } from '@domain/entities/like-comment';
import { CommentMapper } from '@infrastructure/comments/comment.mapper';

class LikeCommentMapper {
static toDomain(likeCommentPer: LikeCommentPersistence): LikeComment {
return new LikeComment(
likeCommentPer.commentId,
CommentMapper.toDomain(likeCommentPer.comment),
likeCommentPer.userId,
UserMapper.toDomain(likeCommentPer.user),
);
}

static toPersistence(likeComment: LikeComment): LikeCommentPersistence {
return new LikeCommentPersistence(
likeComment.userId,
UserMapper.toPersistence(likeComment.user),
likeComment.commentId,
CommentMapper.toPersistence(likeComment.comment),
);
}
}

export { LikeCommentMapper };
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UserPersistence } from '@infrastructure/users';
import { Column, Entity, ManyToOne } from 'typeorm';
import CommentPersistence from '@infrastructure/comments/comment.persistence';
import BaseEntity from '@infrastructure/shared/persistence/entities/base.persistence';

@Entity()
class LikeCommentPersistence extends BaseEntity {
@Column()
userId: string;

@ManyToOne(() => UserPersistence, user => user.likedComments)
user: UserPersistence;

@Column()
commentId: string;

@ManyToOne(() => CommentPersistence, comment => comment.likes, { lazy: true })
comment: CommentPersistence;

constructor(
userId: string,
user: UserPersistence,
commentId: string,
comment: CommentPersistence,
) {
super();
this.userId = userId;
this.user = user;
this.commentId = commentId;
this.comment = comment;
}
}

export { LikeCommentPersistence };
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { DataSource, Repository } from 'typeorm';
import { injectable } from 'inversify';
import { LikeComment } from '@domain/entities/like-comment';
import { ILikeCommentRepository } from '@domain/repositories/like-comment.repository';

@injectable()
export class LikeCommentRepository
extends Repository<LikeComment>
implements ILikeCommentRepository
{
constructor(dataSource: DataSource) {
super(LikeComment, dataSource.createEntityManager());
}
createLikeComment(likeComment: LikeComment): Promise<LikeComment> {
return this.save(likeComment);
}
deleteLikeComment(likeComment: LikeComment): Promise<LikeComment> {
this.createQueryBuilder('likeComment')
.delete()
.where('likeComment.id = :id', { id: likeComment.id })
.execute();
return Promise.resolve(likeComment);
}
findLikeCommentById(likeCommentId: string): Promise<LikeComment> {
return this.createQueryBuilder('likeComment')
.where('likeComment.id = :likeCommentId', { likeCommentId })
.getOne() as Promise<LikeComment>;
}
findUserLikeComments(userId: string): Promise<LikeComment[]> {
return this.createQueryBuilder('likeComment')
.where('likeComment.userId = :userId', { userId })
.getMany();
}
findAll(limit: number, page: number): Promise<LikeComment[]> {
return this.createQueryBuilder('likeComment')
.take(limit || 10)
.skip(page * limit)
.getMany();
}
}
32 changes: 32 additions & 0 deletions backend/src/infrastructure/like-posts/like-post.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import LikePostPersistence from '@infrastructure/LikePosts/like-post.persistence';
import { LikePost } from '@domain/entities/like-post';
import { UserMapper } from '@infrastructure/users';
import { PostMapper } from '@infrastructure/posts/post.mapper';

class LikePostMapper {
static toDomain(likePostPer: LikePostPersistence): LikePost {
return new LikePost(
likePostPer.id,
likePostPer.postId,
likePostPer.userId,
likePostPer.createdAt,
likePostPer.updatedAt,
likePostPer.deletedAt,
);
}

static toPersistence(likePost: LikePost): LikePostPersistence {
return new LikePostPersistence(
likePost.id,
likePost.userId,
UserMapper.toPersistence(likePost.user),
likePost.postId,
PostMapper.toPersistence(likePost.post),
likePost.createdAt,
likePost.updatedAt,
likePost.deletedAt,
);
}
}

export { LikePostMapper };
34 changes: 34 additions & 0 deletions backend/src/infrastructure/like-posts/like-post.persistence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UserPersistence } from '@infrastructure/users';
import { Column, Entity, ManyToOne } from 'typeorm';
import { PostPersistence } from '../posts/post.persistence';
import BaseEntity from '@infrastructure/shared/persistence/entities/base.persistence';

@Entity()
class LikePostPersistence extends BaseEntity {
@Column()
userId: string;

@ManyToOne(() => UserPersistence)
user: UserPersistence;

@Column()
postId: string;

@ManyToOne(() => PostPersistence)
post: PostPersistence;

constructor(
userId: string,
user: UserPersistence,
postId: string,
post: PostPersistence,
) {
super();
this.userId = userId;
this.user = user;
this.postId = postId;
this.post = post;
}
}

export default LikePostPersistence;
49 changes: 49 additions & 0 deletions backend/src/infrastructure/like-posts/like-post.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { DataSource, Repository } from 'typeorm';
import { injectable } from 'inversify';
import { LikePost, Post } from '@domain/entities';
import { ILikePostRepository } from '@domain/repositories/like-post.repository';

@injectable()
export class LikePostRepository
extends Repository<LikePost>
implements ILikePostRepository
{
constructor(dataSource: DataSource) {
super(Post, dataSource.createEntityManager());
}
createLikePost(likePost: LikePost): Promise<LikePost> {
return this.save(likePost);
}
findLikePostById(likePostId: string): Promise<LikePost | null> {
return this.createQueryBuilder('likePost')
.where('likePost.id = :likePostId', { likePostId })
.getOne() as Promise<LikePost>;
}
findUserLikes(
limit: number,
page: number,
userId: string,
): Promise<LikePost[]> {
return this.createQueryBuilder('likePost')
.where('likePost.userId = :userId', { userId })
.take(limit || 10)
.skip(page * limit)
.getMany();
}
findAll(limit: number, page: number): Promise<LikePost[]> {
return this.createQueryBuilder('likePost')
.take(limit || 10)
.skip(page * limit)
.getMany();
}
findByPost(postId: string): Promise<LikePost[] | null> {
return this.createQueryBuilder('likePost')
.where('likePost.postId = :postId', { postId })
.getMany();
}
findByUser(userId: string): Promise<LikePost[] | null> {
return this.createQueryBuilder('likePost')
.where('likePost.userId = :userId', { userId })
.getMany();
}
}
30 changes: 30 additions & 0 deletions backend/src/infrastructure/like-replies/like-reply.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { UserMapper } from '@infrastructure/users';
import { LikeReply } from '@domain/entities';
import { LikeReplyPersistence } from './like-reply.persistence';
import { ReplyMapper } from '@infrastructure/replies/reply.mapper';

class LikeReplyMapper {
static toDomain(likeReplyPer: LikeReplyPersistence): LikeReply {
return new LikeReply(
likeReplyPer.replyId,
ReplyMapper.toDomain(likeReplyPer.reply),
likeReplyPer.userId,
UserMapper.toDomain(likeReplyPer.user),
);
}

static toPersistence(likeReply: LikeReply): LikeReplyPersistence {
return new LikeReplyPersistence(
likeReply.id,
likeReply.userId,
UserMapper.toPersistence(likeReply.user),
likeReply.replyId,
ReplyMapper.toPersistence(likeReply.reply),
likeReply.createdAt,
likeReply.updatedAt!,
likeReply.deletedAt!,
);
}
}

export { LikeReplyMapper };
34 changes: 34 additions & 0 deletions backend/src/infrastructure/like-replies/like-reply.persistence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UserPersistence } from '@infrastructure/users';
import { Column, Entity, ManyToOne } from 'typeorm';
import { ReplyPersistence } from '@infrastructure/replies/reply.persistence';
import BaseEntity from '@infrastructure/shared/persistence/entities/base.persistence';

@Entity()
class LikeReplyPersistence extends BaseEntity {
@Column()
userId: string;

@ManyToOne(() => UserPersistence)
user: UserPersistence;

@Column()
replyId: string;

@ManyToOne(() => ReplyPersistence, reply => reply.likes, { lazy: true })
reply: ReplyPersistence;

constructor(
userId: string,
user: UserPersistence,
replyId: string,
reply: ReplyPersistence,
) {
super();
this.userId = userId;
this.user = user;
this.replyId = replyId;
this.reply = reply;
}
}

export { LikeReplyPersistence };
31 changes: 31 additions & 0 deletions backend/src/infrastructure/like-replies/like-reply.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { DataSource, Repository } from 'typeorm';
import { injectable } from 'inversify';
import { LikeReply } from '@domain/entities';
import { ILikeReplyRepository } from '@domain/repositories/like-reply.repository';

@injectable()
export class LikeReplyRepository
extends Repository<LikeReply>
implements ILikeReplyRepository
{
constructor(dataSource: DataSource) {
super(LikeReply, dataSource.createEntityManager());
}
async createLikeReply(likeReply: LikeReply): Promise<LikeReply> {
await this.createQueryBuilder('likeReply')
.insert()
.values(likeReply)
.execute();
return likeReply;
}
findLikeReplyById(likeReplyId: string): Promise<LikeReply | null> {
return this.createQueryBuilder('likeReply')
.where('likeReply.id = :likeReplyId', { likeReplyId })
.getOne();
}
findUserLikeReplies(userId: string): Promise<LikeReply[]> {
return this.createQueryBuilder('likeReply')
.where('likeReply.userId = :userId', { userId })
.getMany();
}
}
28 changes: 28 additions & 0 deletions backend/src/infrastructure/replies/reply.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Reply } from '@domain/entities';
import { ReplyPersistence } from './reply.persistence';
import { CommentMapper } from '@infrastructure/comments/comment.mapper';
import { LikeReplyMapper } from '@infrastructure/like-replies/like-reply.mapper';

class ReplyMapper {
static toDomain(reply: ReplyPersistence): Reply {
return new Reply(
reply.commentId,
reply.userId,
reply.content,
CommentMapper.toDomain(reply.comment),
reply.likes.map(like => LikeReplyMapper.toDomain(like)),
);
}

static toPersistence(reply: Reply): ReplyPersistence {
return new ReplyPersistence(
reply.content,
reply.userId,
reply.commentId,
CommentMapper.toPersistence(reply.comment),
reply.likes,
);
}
}

export { ReplyMapper };
39 changes: 39 additions & 0 deletions backend/src/infrastructure/replies/reply.persistence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';
import CommentPersistence from '@infrastructure/comments/comment.persistence';
import { LikeReplyPersistence } from '@infrastructure/like-replies/like-reply.persistence';
import BaseEntity from '@infrastructure/shared/persistence/entities/base.persistence';

@Entity()
class ReplyPersistence extends BaseEntity {
@Column()
content: string;

@Column()
userId: string;

@Column()
commentId: string;

@OneToOne(() => CommentPersistence, comment => comment.replies, {
lazy: true,
})
comment: CommentPersistence;

@OneToMany(() => LikeReplyPersistence, like => like.reply, { lazy: true })
likes: LikeReplyPersistence[];

constructor(
content: string,
userId: string,
commentId: string,
comment: CommentPersistence,
) {
super();
this.content = content;
this.userId = userId;
this.commentId = commentId;
this.comment = comment;
}
}

export { ReplyPersistence };
Loading

0 comments on commit b6e10fc

Please sign in to comment.