-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User 모듈 추가 #3
Merged
Merged
User 모듈 추가 #3
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
Warnings: | ||
|
||
- The primary key for the `Comment` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- The primary key for the `Like` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- The primary key for the `Review` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- The primary key for the `ReviewTag` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- The primary key for the `Tag` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
|
||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_reviewId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Like" DROP CONSTRAINT "Like_reviewId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Like" DROP CONSTRAINT "Like_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Review" DROP CONSTRAINT "Review_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "ReviewTag" DROP CONSTRAINT "ReviewTag_reviewId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "ReviewTag" DROP CONSTRAINT "ReviewTag_tagId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ALTER COLUMN "reviewId" SET DATA TYPE TEXT, | ||
ALTER COLUMN "userId" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "Comment_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "Comment_id_seq"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Like" DROP CONSTRAINT "Like_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ALTER COLUMN "reviewId" SET DATA TYPE TEXT, | ||
ALTER COLUMN "userId" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "Like_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "Like_id_seq"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Review" DROP CONSTRAINT "Review_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ALTER COLUMN "userId" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "Review_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "Review_id_seq"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "ReviewTag" DROP CONSTRAINT "ReviewTag_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ALTER COLUMN "reviewId" SET DATA TYPE TEXT, | ||
ALTER COLUMN "tagId" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "ReviewTag_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "ReviewTag_id_seq"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Tag" DROP CONSTRAINT "Tag_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "Tag_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "Tag_id_seq"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" DROP CONSTRAINT "User_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "User_id_seq"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Review" ADD CONSTRAINT "Review_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Like" ADD CONSTRAINT "Like_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Like" ADD CONSTRAINT "Like_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ReviewTag" ADD CONSTRAINT "ReviewTag_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ReviewTag" ADD CONSTRAINT "ReviewTag_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "Tag"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (e.g., Git) | ||
provider = "postgresql" | ||
provider = "postgresql" |
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,5 @@ | ||
export class CreateUserDto { | ||
email: string; | ||
password: string; | ||
nickname: string; | ||
} |
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 { PartialType } from "@nestjs/mapped-types"; | ||
import { CreateUserDto } from "./create-user.dto"; | ||
|
||
export class UpdateUserDto extends PartialType(CreateUserDto) { | ||
email?: string; | ||
password?: string; | ||
nickname?: string; | ||
profileImgUrl?: string; | ||
} |
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 User {} |
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,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserController } from './user.controller'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserController', () => { | ||
let controller: UserController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UserController], | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
controller = module.get<UserController>(UserController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
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,37 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Patch, | ||
Param, | ||
Delete, | ||
} from "@nestjs/common"; | ||
import { UserService } from "./user.service"; | ||
import { CreateUserDto } from "./dto/create-user.dto"; | ||
import { UpdateUserDto } from "./dto/update-user.dto"; | ||
|
||
@Controller("user") | ||
export class UserController { | ||
constructor(private readonly userService: UserService) {} | ||
|
||
@Post() | ||
create(@Body() createUserDto: CreateUserDto) { | ||
return this.userService.createUser(createUserDto); | ||
} | ||
|
||
@Get(":id") | ||
findOne(@Param("id") id: string) { | ||
return this.userService.findUser(id); | ||
} | ||
|
||
@Patch(":id") | ||
update(@Param("id") id: string, @Body() updateUserDto: UpdateUserDto) { | ||
return this.userService.updateUser(id, updateUserDto); | ||
} | ||
|
||
@Delete(":id") | ||
remove(@Param("id") id: string) { | ||
return this.userService.removeUser(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,10 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { UserService } from "./user.service"; | ||
import { UserController } from "./user.controller"; | ||
import { PrismaService } from "src/prisma.service"; | ||
|
||
@Module({ | ||
controllers: [UserController], | ||
providers: [UserService, PrismaService], | ||
}) | ||
export class UserModule {} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserService', () => { | ||
let service: UserService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
service = module.get<UserService>(UserService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,39 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { CreateUserDto } from "./dto/create-user.dto"; | ||
import { UpdateUserDto } from "./dto/update-user.dto"; | ||
import { User } from "@prisma/client"; | ||
import { PrismaService } from "src/prisma.service"; | ||
import { Role } from "@prisma/client"; | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor(private prismaService: PrismaService) {} | ||
|
||
async createUser(createUserDto: CreateUserDto): Promise<User> { | ||
return await this.prismaService.user.create({ | ||
data: { | ||
...createUserDto, | ||
role: Role.USER, | ||
}, | ||
}); | ||
} | ||
|
||
async findUser(id: string): Promise<User> { | ||
return await this.prismaService.user.findUnique({ | ||
where: { id }, | ||
}); | ||
} | ||
|
||
async updateUser(id: string, updateUserDto: UpdateUserDto) { | ||
return await this.prismaService.user.update({ | ||
where: { id }, | ||
data: updateUserDto, | ||
}); | ||
} | ||
|
||
async removeUser(id: string) { | ||
return await this.prismaService.user.delete({ | ||
where: { id }, | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오잉 이 role은 남겨두셨군요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 깜박했습니다!