-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30b29cf
commit eccdced
Showing
12 changed files
with
189 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PrimaryKey, Property } from '@mikro-orm/core'; | ||
|
||
export abstract class BaseEntity { | ||
@PrimaryKey() | ||
id: number; | ||
|
||
@Property() | ||
createdAt = new Date(); | ||
|
||
@Property({ onUpdate: () => new Date() }) | ||
updatedAt = new Date(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class CreatePostDto {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreatePostDto } from './create-post.dto'; | ||
|
||
export class UpdatePostDto extends PartialType(CreatePostDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Entity, ManyToOne, Property } from '@mikro-orm/core'; | ||
import { BaseEntity } from 'src/common/entities/base.entity'; | ||
import { User } from 'src/users/entities/user.entity'; | ||
import { Post } from './post.entity'; | ||
|
||
@Entity() | ||
export class PostComment extends BaseEntity { | ||
@Property() | ||
text: string; | ||
|
||
@ManyToOne({ entity: () => User, inversedBy: 'comments' }) | ||
author: User; | ||
|
||
@ManyToOne({ entity: () => Post, inversedBy: 'comments' }) | ||
post: Post; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Embeddable, Property } from '@mikro-orm/core'; | ||
|
||
@Embeddable() | ||
export class PostLocation { | ||
@Property() | ||
latitude: number; | ||
|
||
@Property() | ||
longitude: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Embeddable, Property } from '@mikro-orm/core'; | ||
|
||
@Embeddable() | ||
export class PostSticker { | ||
@Property() | ||
id: number; | ||
|
||
@Property() | ||
x: number; | ||
|
||
@Property() | ||
y: number; | ||
|
||
@Property() | ||
rotation: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
Collection, | ||
Embedded, | ||
Entity, | ||
ManyToMany, | ||
ManyToOne, | ||
OneToMany, | ||
Property, | ||
} from '@mikro-orm/core'; | ||
import { BaseEntity } from 'src/common/entities/base.entity'; | ||
import { User } from 'src/users/entities/user.entity'; | ||
import { PostComment } from './post-comment.entity'; | ||
import { PostLocation } from './post-location.embeddable'; | ||
import { PostSticker } from './post-sticker.embeddable'; | ||
|
||
@Entity() | ||
export class Post extends BaseEntity { | ||
@Property() | ||
imageUrl: string; | ||
|
||
@Property() | ||
caption: string; | ||
|
||
@ManyToOne({ entity: () => User, inversedBy: 'posts' }) | ||
author: User; | ||
|
||
@Embedded(() => PostSticker, { array: true }) | ||
stickers: PostSticker[] = []; | ||
|
||
@ManyToMany({ entity: () => User, inversedBy: 'likedPosts' }) | ||
likedBy = new Collection<User>(this); | ||
|
||
@OneToMany({ entity: () => PostComment, mappedBy: 'post' }) | ||
comments = new Collection<PostComment>(this); | ||
|
||
@Embedded(() => PostLocation) | ||
location: PostLocation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; | ||
import { PostsService } from './posts.service'; | ||
import { CreatePostDto } from './dto/create-post.dto'; | ||
import { UpdatePostDto } from './dto/update-post.dto'; | ||
|
||
@Controller('posts') | ||
export class PostsController { | ||
constructor(private readonly postsService: PostsService) {} | ||
|
||
@Post() | ||
create(@Body() createPostDto: CreatePostDto) { | ||
return this.postsService.create(createPostDto); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.postsService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.postsService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
update(@Param('id') id: string, @Body() updatePostDto: UpdatePostDto) { | ||
return this.postsService.update(+id, updatePostDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.postsService.remove(+id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PostsService } from './posts.service'; | ||
import { PostsController } from './posts.controller'; | ||
|
||
@Module({ | ||
controllers: [PostsController], | ||
providers: [PostsService], | ||
}) | ||
export class PostsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreatePostDto } from './dto/create-post.dto'; | ||
import { UpdatePostDto } from './dto/update-post.dto'; | ||
|
||
@Injectable() | ||
export class PostsService { | ||
create(createPostDto: CreatePostDto) { | ||
return 'This action adds a new post'; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all posts`; | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} post`; | ||
} | ||
|
||
update(id: number, updatePostDto: UpdatePostDto) { | ||
return `This action updates a #${id} post`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} post`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters