Skip to content

Commit

Permalink
signup 작업중
Browse files Browse the repository at this point in the history
  • Loading branch information
mirlee0304 committed Oct 14, 2023
1 parent e0ca3b4 commit 781167f
Show file tree
Hide file tree
Showing 635 changed files with 15,514 additions and 5 deletions.
96 changes: 96 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dotenv": "^16.3.1",
"jsonwebtoken": "^9.0.2",
"luxon": "^3.4.3",
"mysql2": "^3.6.1",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"pg": "^8.11.3",
Expand Down
14 changes: 14 additions & 0 deletions backend/src/auth/controller/signup-dtos/createuser.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IsString, IsNotEmpty, IsAlphanumeric, MinLength } from 'class-validator';

export class CreateUserDto {
@IsString()
name: string;

@IsString()
@IsNotEmpty()
username: string;

@IsString()
@IsNotEmpty()
password: string;
}
7 changes: 5 additions & 2 deletions backend/src/test/auth/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('login test', () => {
await dataSource.synchronize(true);

user = await UserFixture.create({
name: 'hi',
username: 'hello',
password: 'world',
});
Expand All @@ -40,16 +41,17 @@ describe('login test', () => {
supertest(testServer.getHttpServer())
.post('/auth/login')
.send({
name: 'hi',
username: 'hello',
password: 'world2',
})
.expect(HttpStatus.UNAUTHORIZED);
});

})
it('존재하지 않는 유저로 찾기', async () => {
await supertest(testServer.getHttpServer())
.post('/auth/login')
.send({
name: 'hi',
username: 'asdfasdfasdf',
password: 'world',
})
Expand All @@ -60,6 +62,7 @@ describe('login test', () => {
await supertest(testServer.getHttpServer())
.post('/auth/login')
.send({
name: 'hi',
username: 'hello',
password: 'world',
})
Expand Down
53 changes: 53 additions & 0 deletions backend/src/test/auth/signup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from '../../app.module';
import { Test } from '@nestjs/testing';
import { DataSource } from 'typeorm';
import { appSetting } from '../../main';
import * as supertest from 'supertest';
import { User } from '../../user/models/user.entity';
import { UserFixture } from '../fixture/user.fixture';
import { HttpStatus } from '@nestjs/common';

describe('signup test', () => {
let testServer: NestExpressApplication;
let dataSource: DataSource;
let user: User;

beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [AppModule],
}).compile();

testServer = module.createNestApplication<NestExpressApplication>();
dataSource = testServer.get(DataSource);
await dataSource.synchronize(true);
appSetting(testServer);

await testServer.init();
});

beforeEach(async () => {
await dataSource.synchronize(true);

user = await UserFixture.create({
name: 'hi',
username: 'hello',
password: 'world',
});
});

it('Check if the username already exists', async () => {
await supertest(testServer.getHttpServer())
.post('/user/signup')
.send({
name: 'John Doe',
username: 'hello',
password: 'password123',
})
.expect(HttpStatus.CONFLICT);
});

afterAll(async () => {
await testServer.close();
});
});
4 changes: 3 additions & 1 deletion backend/src/test/fixture/user.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { User } from '../../user/models/user.entity';

export type UserFixtureProps = {
name: string;
username: string;
password: string;
};

export class UserFixture {
static create({ username, password }: Partial<UserFixtureProps>) {
static create({ name, username, password }: Partial<UserFixtureProps>) {
return User.create({
name: name ?? 'test',
username: username ?? 'test',
password: password ?? 'test',
}).save();
Expand Down
4 changes: 3 additions & 1 deletion backend/src/user/models/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BeforeInsert, Column, Entity } from 'typeorm';
import { BeforeInsert, Column, Entity, BaseEntity } from 'typeorm';
import { IssuedAtMetaEntity } from '../../core/models/base.entity';
import * as bcrypt from 'bcrypt';
import { sign } from 'jsonwebtoken';
import * as process from 'process';

@Entity()
export class User extends IssuedAtMetaEntity {
@Column({ type: 'varchar' })
name: string;
@Column({ type: 'varchar' })
username: string;
@Column({ type: 'varchar' })
Expand Down
20 changes: 20 additions & 0 deletions backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Controller, Post, Body, ConflictException } from '@nestjs/common';
import { UserService } from './user.service';
import { User } from './models/user.entity';
import {CreateUserDto} from "../auth/controller/signup-dtos/createuser.dto";

@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}


@Post('signup')
async signUp(@Body() createUserDto: CreateUserDto): Promise<User> {
const existingUser = await this.userService.findByUsername(createUserDto.username);
if (existingUser) {
throw new ConflictException('Username already exists');
}
return this.userService.create(createUserDto);
}

}
10 changes: 9 additions & 1 deletion backend/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { User } from './models/user.entity';

@Module({})
@Module({
imports: [TypeOrmModule.forFeature([User])],
controllers: [UserController],
providers: [UserService],
})
export class UserModule {}
24 changes: 24 additions & 0 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from './models/user.entity';
import { CreateUserDto } from '../auth/controller/signup-dtos/createuser.dto';

@Injectable()
export class UserService {
constructor(
@InjectRepository(User)
private usersRepository: Repository<User>,
) {}

async create(createUserDto: CreateUserDto): Promise<User> {
const { name, username, password } = createUserDto;
const user = this.usersRepository.create({ name, username, password });
return this.usersRepository.save(user);
}

async findByUsername(username: string): Promise<User | undefined> {
const user = await this.usersRepository.findOne({ where: { username } });
return user ? user : undefined; // Return undefined when no user is found
}
}
Binary file added frontend/.gradle/8.0/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Binary file added frontend/.gradle/8.0/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added frontend/.gradle/8.0/fileChanges/last-build.bin
Binary file not shown.
Binary file added frontend/.gradle/8.0/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added frontend/.gradle/8.0/fileHashes/fileHashes.lock
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
2 changes: 2 additions & 0 deletions frontend/.gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Thu Oct 12 16:52:28 KST 2023
gradle.version=8.0
Binary file not shown.
Binary file added frontend/.gradle/file-system.probe
Binary file not shown.
Empty file.
Loading

0 comments on commit 781167f

Please sign in to comment.