Skip to content
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

feat: userController [ISSUE-1,9,65] #66

Merged
merged 4 commits into from
Jun 24, 2019

Conversation

ttkmw
Copy link
Contributor

@ttkmw ttkmw commented Jun 12, 2019

Related Issue

resolve: #1, #9 , #65

Description

user controller & e2e test

Checklist

Thank you for your contribution.
Before submitting this PR, please make sure:

  • Test case
  • End of Work

@ttkmw ttkmw force-pushed the feature/userController branch 2 times, most recently from a866ea9 to a4bae7d Compare June 16, 2019 13:34
import {User} from '../../domain/user/user.entity';
import {UserDto} from '../../app/user/dto/user.dto';
import {BadRequestException} from '@nestjs/common';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should specify error(ex InvalidParameterException, ValidationException... ) such as BadRequestException

async delete(@Param('id') id: number): Promise<DeleteResult> {
return await this.service.delete(id);
}
@Put(':id/increase-level')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's talk about url naming!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was not sure http method and url is good.

i referenced: github-api
PUT /repos/:owner/:repo/pulls/:pull_number/update-branch

it was using verb in url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about it changes to @Put(':id/level') and amount has positive amount or negative amount?

Copy link
Contributor Author

@ttkmw ttkmw Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using verb is better

level is not entity or object.

And if verb doesn’t exist, maybe client think create level with just method and parameter.

Copy link
Member

@hihiboss hihiboss Jun 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, how about @Put(':id?level=amount')?

Copy link
Contributor Author

@ttkmw ttkmw Jun 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's good but
maybe client will think like "set level with the amount".

like i wanted to say increase level 2 up but client will think like level = 2.

and there is another issue that one controller should route the url only with the parameter.
i mean one controller should cover 'increase-level', 'increase-point' like that. i think that is not goood

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about the comment @Put(':id/level'):

i think only resources should be used as 'noun'.
seeing reference,
it says resource is like object in oop.

A resource is an object with a type, associated data, relationships to other resources, and a set of methods that operate on it.

resources has have data associated with them,

so i think resource is like 'entity'.

but level is just value.

// todo: implement ExceptionHandler, apply custom Error

describe('UserController', () => {
let app: INestApplication;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz read nestjs/nest#1843 this to rollback transactions

Copy link
Contributor Author

@ttkmw ttkmw Jun 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i used dropSchema option at config file.

it's a little bit different from the reference, but i wanted to gather all the configuration in config file which is not applied at the reference

const initUserForDecreasePoint = {id: 3, address: 'thirdAddress', name: 'thirdName', point: 10, level: 0};
const initUserForDelete = {id: 4, address: 'fourthAddress', name: 'fourthName', point: 0, level: 0};

beforeAll(async () => {
Copy link
Member

@junbeomlee junbeomlee Jun 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in e2e test cases we don't need to restart whole app per a test case!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't understand. it's 'beforeAll', not 'beforeEach'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

import {getConnection} from 'typeorm';
import * as assert from 'assert';

// todo: implement ExceptionHandler, apply custom Error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be possible to perform the test with one user data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i minimized the default data, but needed 2 data. That's because i needed 2 state: user with 10 point, user with 0 point

Copy link
Member

@junbeomlee junbeomlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except the comment!
LGTM

@ttkmw ttkmw changed the title [WIP]Feature/userController & e2e test feat: userController & e2e test Jun 18, 2019
@ttkmw ttkmw force-pushed the feature/userController branch 4 times, most recently from b9c1512 to c358994 Compare June 19, 2019 12:49
@ttkmw ttkmw changed the title feat: userController & e2e test feat: userController [ISSUE-1,9,65] Jun 19, 2019
import {TypeOrmModuleOptions, TypeOrmOptionsFactory} from '@nestjs/typeorm';

@Injectable()
export class RepositoryConfigService implements TypeOrmOptionsFactory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you implement TypeOrmOptionsFactory, should you name RepositoryConfigFactory?

Why does RepositoryConfigService implement TypeOrmOptionsFactory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it make sense ur comment but I think name repositoryconfihservice is better

  1. We are using "service" at all the other place. i used service for consistency.
  2. other references are using name "service" at the same usage like ConfigService.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see!

I understand your mind. Thank you :)

errors = user.canDecreasePoint(amount);
if (errors.length !== 0) {
throw new Error('can not decrease point');
throw new NotFoundException('user with the id is not found');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 17, you throw BadRequestException, but in line 54, you throw NotFoundException.

Why did you separated "finding undefined user" to BadRequestException and NotFoundException?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!! very nice

async delete(@Param('id') id: number): Promise<DeleteResult> {
return await this.service.delete(id);
}
@Put(':id/increase-level')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about it changes to @Put(':id/level') and amount has positive amount or negative amount?

async increaseLevel(@Param('id') id: number, @Query('amount', new ParseIntPipe()) amount): Promise<User> {
return await this.service.increaseLevel(id, amount);
}
@Put(':id/increase-point')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I suggest that it changes to @Put(':id/point') and amount has positive amount or negative amount.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

point is not object. that's why i didn't use noun for point at the url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about @Put(':id?point=amount')?

@hihiboss
Copy link
Member

hihiboss commented Jun 19, 2019

I've already known it's too tiny but, commit message format is [type]: [msg], not [type] : [msg]. Just whitespace... :)

@ttkmw
Copy link
Contributor Author

ttkmw commented Jun 19, 2019

i referenced example at the contributing guide

example:
[type] : [description]
docs : add more description about PBFT [ISSUE-1]
fix : change type int to unit [ISSUE-20]

all the samples has whitespace

@hihiboss

@hihiboss
Copy link
Member

@inDlife

Oh, really sorry to commit message!

In our commit logs, messages have [type]: [message] style.
But, I checked that our contribution guide says [type] : [message].

Let's follow contribution guide or modify contribution guide!

@ttkmw
Copy link
Contributor Author

ttkmw commented Jun 20, 2019

@hihiboss
it's okay. respect ur precise, details(꼼꼼함ㅎㅎ)

Copy link
Member

@junbeomlee junbeomlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

const initUserForDecreasePoint = {id: 3, address: 'thirdAddress', name: 'thirdName', point: 10, level: 0};
const initUserForDelete = {id: 4, address: 'fourthAddress', name: 'fourthName', point: 0, level: 0};

beforeAll(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@junbeomlee junbeomlee merged commit 723dfbb into DE-labtory:develop Jun 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

connect db
3 participants