Skip to content

Commit

Permalink
Merge pull request #5 from CAU-MOAPP-2023/feat/2-feat-user-entity
Browse files Browse the repository at this point in the history
✨ feat: implement all entities (#2)
  • Loading branch information
synoti21 authored Oct 13, 2023
2 parents 32e225f + 9c226ef commit c0e868e
Show file tree
Hide file tree
Showing 19 changed files with 947 additions and 49 deletions.
590 changes: 543 additions & 47 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.0",
"mysql2": "^3.6.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"typeorm": "^0.3.17"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './domain/user/user.module';

@Module({
imports: [],
imports: [UserModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
17 changes: 17 additions & 0 deletions src/database/mysql.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TypeOrmModule } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';

@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: '127.0.0.1',
username: 'root',
password: '12345678',
database: 'family_app_db',
entities: [],
synchronize: true,
}),
],
})
export class MysqlModule {}
1 change: 1 addition & 0 deletions src/domain/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateUserDto {}
4 changes: 4 additions & 0 deletions src/domain/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateUserDto } from './create-user.dto';

export class UpdateUserDto extends PartialType(CreateUserDto) {}
42 changes: 42 additions & 0 deletions src/domain/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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.create(createUserDto);
}

@Get()
findAll() {
return this.userService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.userService.findOne(+id);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.userService.update(+id, updateUserDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.userService.remove(+id);
}
}
11 changes: 11 additions & 0 deletions src/domain/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { MysqlModule } from '../../database/mysql.module';

@Module({
imports: [MysqlModule],
controllers: [UserController],
providers: [UserService],
})
export class UserModule {}
18 changes: 18 additions & 0 deletions src/domain/user/user.service.spec.ts
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();
});
});
26 changes: 26 additions & 0 deletions src/domain/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';

@Injectable()
export class UserService {
create(createUserDto: CreateUserDto) {
return 'This action adds a new user';
}

findAll() {
return `This action returns all user`;
}

findOne(id: number) {
return `This action returns a #${id} user`;
}

update(id: number, updateUserDto: UpdateUserDto) {
return `This action updates a #${id} user`;
}

remove(id: number) {
return `This action removes a #${id} user`;
}
}
36 changes: 36 additions & 0 deletions src/infra/entities/album.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
Column,
Entity,
Index,
JoinColumn,
ManyToOne,
OneToMany,
} from 'typeorm';
import { FamilyEntity } from './family.entity';
import { PhotoEntity } from './photo.entity';

@Index('FK_family_TO_album_1', ['familyId'], {})
@Entity('album', { schema: 'family_app_db' })
export class AlbumEntity {
@Column('int', { primary: true, name: 'ID' })
id: number;

@Column('int', { primary: true, name: 'family_ID' })
familyId: number;

@Column('int', { name: 'photo_number', nullable: true })
photoNumber: number | null;

@Column('varchar', { name: 'album_name', nullable: true, length: 50 })
albumName: string | null;

@ManyToOne(() => FamilyEntity, (family) => family.albums, {
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
})
@JoinColumn([{ name: 'family_ID', referencedColumnName: 'id' }])
family: FamilyEntity;

@OneToMany(() => PhotoEntity, (photo) => photo.album)
photos: PhotoEntity[];
}
28 changes: 28 additions & 0 deletions src/infra/entities/family.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Column, Entity, OneToMany } from 'typeorm';
import { AlbumEntity } from './album.entity';
import { FamilymemberEntity } from './familymember.entity';
import { FamilyScheduleEntity } from './familySchedule.entity';

@Entity('family', { schema: 'family_app_db' })
export class FamilyEntity {
@Column('int', { primary: true, name: 'ID' })
id: number;

@Column('int', { name: 'member_number', nullable: true })
memberNumber: number | null;

@Column('varchar', { name: 'family_name', nullable: true, length: 50 })
familyName: string | null;

@Column('date', { name: 'created_date', nullable: true })
createdDate: string | null;

@OneToMany(() => AlbumEntity, (album) => album.family)
albums: AlbumEntity[];

@OneToMany(() => FamilymemberEntity, (familyMember) => familyMember.family)
familyMembers: FamilymemberEntity[];

@OneToMany(() => FamilyScheduleEntity, (familySchedule) => familySchedule.family)
familySchedules: FamilyScheduleEntity[];
}
25 changes: 25 additions & 0 deletions src/infra/entities/familySchedule.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { FamilyEntity } from './family.entity';

@Index('FK_family_TO_family_schedule_1', ['familyId'], {})
@Entity('family_schedule', { schema: 'family_app_db' })
export class FamilyScheduleEntity {
@Column('int', { primary: true, name: 'ID' })
id: number;

@Column('int', { primary: true, name: 'family_ID' })
familyId: number;

@Column('varchar', { name: 'schedule_name', nullable: true, length: 50 })
scheduleName: string | null;

@Column('date', { name: 'schedule_date', nullable: true })
scheduleDate: string | null;

@ManyToOne(() => FamilyEntity, (family) => family.familySchedules, {
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
})
@JoinColumn([{ name: 'family_ID', referencedColumnName: 'id' }])
family: FamilyEntity;
}
58 changes: 58 additions & 0 deletions src/infra/entities/familymember.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
Column,
Entity,
Index,
JoinColumn,
ManyToOne,
OneToMany,
} from 'typeorm';
import { FamilyEntity } from './family.entity';
import { UserEntity } from './user.entity';
import { IndividualScheduleEntity } from './individualSchedule.entity';
import { PostEntity } from './post.entity';

@Index('FK_family_TO_family_member_1', ['familyId'], {})
@Index('FK_user_TO_family_member_1', ['userId'], {})
@Entity('family_member', { schema: 'family_app_db' })
export class FamilymemberEntity {
@Column('int', { primary: true, name: 'ID' })
id: number;

@Column('int', { primary: true, name: 'user_ID' })
userId: number;

@Column('int', { primary: true, name: 'family_ID' })
familyId: number;

@Column('int', { name: 'family_role', nullable: true })
familyRole: number | null;

@Column('int', { name: 'poke_count', nullable: true })
pokeCount: number | null;

@Column('int', { name: 'talk_count', nullable: true })
talkCount: number | null;

@ManyToOne(() => FamilyEntity, (family) => family.familyMembers, {
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
})
@JoinColumn([{ name: 'family_ID', referencedColumnName: 'id' }])
family: FamilyEntity;

@ManyToOne(() => UserEntity, (user) => user.familyMembers, {
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
})
@JoinColumn([{ name: 'user_ID', referencedColumnName: 'id' }])
user: UserEntity;

@OneToMany(
() => IndividualScheduleEntity,
(individualSchedule) => individualSchedule.member,
)
individualSchedules: IndividualScheduleEntity[];

@OneToMany(() => PostEntity, (post) => post.srcMember)
posts: PostEntity[];
}
26 changes: 26 additions & 0 deletions src/infra/entities/individualSchedule.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { FamilymemberEntity } from './familymember.entity';

@Index('FK_family_member_TO_individual_schedule_1', ['memberId'], {})
@Entity('individual_schedule', { schema: 'family_app_db' })
export class IndividualScheduleEntity {
@Column('int', { primary: true, name: 'ID' })
id: number;

@Column('int', { primary: true, name: 'member_ID' })
memberId: number;

@Column('varchar', { name: 'schedule_name', nullable: true, length: 50 })
scheduleName: string | null;

@Column('date', { name: 'schedule_date', nullable: true })
scheduleDate: string | null;

@ManyToOne(
() => FamilymemberEntity,
(familyMember) => familyMember.individualSchedules,
{ onDelete: 'CASCADE', onUpdate: 'NO ACTION' },
)
@JoinColumn([{ name: 'member_ID', referencedColumnName: 'id' }])
member: FamilymemberEntity;
}
28 changes: 28 additions & 0 deletions src/infra/entities/photo.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { AlbumEntity } from './album.entity';

@Index('FK_album_TO_photo_1', ['albumId'], {})
@Entity('photo', { schema: 'family_app_db' })
export class PhotoEntity {
@Column('int', { primary: true, name: 'ID' })
id: number;

@Column('int', { primary: true, name: 'album_ID' })
albumId: number;

@Column('varchar', { name: 'S3_image_URL', nullable: true, length: 100 })
s3ImageUrl: string | null;

@Column('varchar', { name: 'photo_name', nullable: true, length: 50 })
photoName: string | null;

@Column('date', { name: 'created_date', nullable: true })
createdDate: string | null;

@ManyToOne(() => AlbumEntity, (album) => album.photos, {
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
})
@JoinColumn([{ name: 'album_ID', referencedColumnName: 'id' }])
album: AlbumEntity;
}
28 changes: 28 additions & 0 deletions src/infra/entities/post.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { FamilymemberEntity } from './familymember.entity';

@Index('FK_family_member_TO_post_1', ['srcMemberId'], {})
@Entity('post', { schema: 'family_app_db' })
export class PostEntity {
@Column('varchar', { primary: true, name: 'ID', length: 255 })
id: string;

@Column('int', { primary: true, name: 'src_member_ID' })
srcMemberId: number;

@Column('varchar', { name: 'title', nullable: true, length: 50 })
title: string | null;

@Column('varchar', { name: 'post_context', nullable: true, length: 50 })
postContext: string | null;

@Column('date', { name: 'created_date', nullable: true })
createdDate: string | null;

@ManyToOne(() => FamilymemberEntity, (familyMember) => familyMember.posts, {
onDelete: 'CASCADE',
onUpdate: 'NO ACTION',
})
@JoinColumn([{ name: 'src_member_ID', referencedColumnName: 'id' }])
srcMember: FamilymemberEntity;
}
Loading

0 comments on commit c0e868e

Please sign in to comment.