-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
a866ea9
to
a4bae7d
Compare
import {User} from '../../domain/user/user.entity'; | ||
import {UserDto} from '../../app/user/dto/user.dto'; | ||
import {BadRequestException} from '@nestjs/common'; | ||
|
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.
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') |
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.
let's talk about url naming!
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.
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
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.
How about it changes to @Put(':id/level')
and amount
has positive amount or negative amount?
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.
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.
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.
Then, how about @Put(':id?level=amount')
?
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.
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
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.
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; |
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.
plz read nestjs/nest#1843 this to rollback transactions
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.
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 () => { |
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.
in e2e test cases we don't need to restart whole app per a test case!!
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.
didn't understand. it's 'beforeAll', not 'beforeEach'
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.
ok
server/test/user/user.e2e-spec.ts
Outdated
import {getConnection} from 'typeorm'; | ||
import * as assert from 'assert'; | ||
|
||
// todo: implement ExceptionHandler, apply custom Error |
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.
It seems to be possible to perform the test with one user data.
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.
i minimized the default data, but needed 2 data. That's because i needed 2 state: user with 10 point, user with 0 point
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.
Except the comment!
LGTM
a4bae7d
to
3eb4c3e
Compare
b9c1512
to
c358994
Compare
c358994
to
5642f25
Compare
import {TypeOrmModuleOptions, TypeOrmOptionsFactory} from '@nestjs/typeorm'; | ||
|
||
@Injectable() | ||
export class RepositoryConfigService implements TypeOrmOptionsFactory { |
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.
If you implement TypeOrmOptionsFactory
, should you name RepositoryConfigFactory
?
Why does RepositoryConfigService
implement TypeOrmOptionsFactory
?
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.
it make sense ur comment but I think name repositoryconfihservice is better
- We are using "service" at all the other place. i used service for consistency.
- other references are using name "service" at the same usage like
ConfigService
.
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.
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'); |
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.
In line 17, you throw BadRequestException
, but in line 54, you throw NotFoundException
.
Why did you separated "finding undefined user" to BadRequestException
and NotFoundException
?
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.
thanks!! very nice
async delete(@Param('id') id: number): Promise<DeleteResult> { | ||
return await this.service.delete(id); | ||
} | ||
@Put(':id/increase-level') |
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.
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') |
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.
Also, I suggest that it changes to @Put(':id/point')
and amount
has positive amount or negative amount.
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.
point is not object. that's why i didn't use noun for point at the url
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.
How about @Put(':id?point=amount')
?
I've already known it's too tiny but, commit message format is |
i referenced example at the contributing guide example: all the samples has whitespace |
@inDlife Oh, really sorry to commit message! In our commit logs, messages have Let's follow contribution guide or modify contribution guide! |
5642f25
to
9c64854
Compare
@hihiboss |
9c64854
to
cac0e25
Compare
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.
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 () => { |
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.
ok
Related Issue
resolve: #1, #9 , #65
Description
user controller & e2e test
Checklist
Thank you for your contribution.
Before submitting this PR, please make sure: