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

10 naming #25

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

10 naming #25

wants to merge 9 commits into from

Conversation

IK541
Copy link
Collaborator

@IK541 IK541 commented Sep 20, 2024

  • Changed notes directory to note directory as all the other resource directories (event, search, task, user) use singular
  • Modified controller methods names so that these follow the same convention across different resources (only event, task and note have methods with similar functionality, search and users were left untouched as these have completly different functionality, therefore there was no need for same naming conventions and their current naming conventions seemed reasonable). The new naming convention is:
html request method endpoint name controller method name service method name
GET <resource> getUser<Resource>s fetchUser
GET <resource>/<id> get<Resource>ById fetch
POST <resource> add<Resource> add
PATCH <resource>/<id> edit<Resource> edit
DELETE <resource>/<id> delete<Resource> delete
  • Modified task endpoints and one of note endpoints to adhere to the naming convention
  • Modified service methods names to adhere to the naming conventions - mainly deleting resource name from method name as resource names are already included in service class names
  • added typing to notes

Copy link
Collaborator

@smazik02 smazik02 left a comment

Choose a reason for hiding this comment

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

Looks good overall, I'd suggest one naming convention change though

@@ -42,7 +42,7 @@ export class EventService {
return event;
}

async fetchUserEvents(userId: number): Promise<ReturnEventDTO[]> {
async fetchUser(userId: number): Promise<ReturnEventDTO[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong naming convention in my opinion, service method returns Events, not a User, I think something like "fetchByUser" would be more descriptive

Copy link
Member

Choose a reason for hiding this comment

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

I agree

@@ -12,22 +12,22 @@ export class NoteService {
private noteRepository: Repository<NoteEntity>,
) {}

async fetchUserNotes(user: UserEntity) {
async fetchUser(user: UserEntity): Promise<NoteDTO[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

return await this.taskRepository.findOne({
where: { id, user },
});
}

async getAllUserTasks(user: UserEntity): Promise<ReturnTaskDTO[]> {
async fetchUser(user: UserEntity): Promise<ReturnTaskDTO[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here

@IK541
Copy link
Collaborator Author

IK541 commented Sep 20, 2024

The requested change (renaming fetchUser to fetchByUser) has been implemented. The updated naming table looks like this:

html request method endpoint name controller method name service method name
GET <resource> getUser<Resource>s fetchByUser
GET <resource>/<id> get<Resource>ById fetch
POST <resource> add<Resource> add
PATCH <resource>/<id> edit<Resource> edit
DELETE <resource>/<id> delete<Resource> delete

Copy link
Collaborator

@smazik02 smazik02 left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Member

@Aeri4a Aeri4a left a comment

Choose a reason for hiding this comment

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

Small changes, overall good job

@@ -54,7 +54,7 @@ export class EventController {
async getUserEvents(
@GetUser('id') userId: number,
): Promise<ReturnEventDTO[]> {
return await this.eventService.fetchUserEvents(userId);
return await this.eventService.fetchByUser(userId);
Copy link
Member

Choose a reason for hiding this comment

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

And that one is clear, cool

@@ -74,7 +74,7 @@ export class EventController {
@Get(':id')
@GetEventByIdApi()
async getEventById(@Param('id') eventId: number): Promise<ReturnEventDTO> {
return await this.eventService.fetchById(eventId);
return await this.eventService.fetch(eventId);
Copy link
Member

Choose a reason for hiding this comment

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

fetchById because we don't know if we fetch all or not.
You could use [serviceName].fetchAll or fetchOne and albo fetchById

}

@HttpCode(HttpStatus.NO_CONTENT)
@Delete('exceptions/:id')
@DeleteExceptionApi()
async deleteException(@Param('id') exceptionId: number): Promise<void> {
await this.eventService.removeExceptionById(exceptionId);
await this.eventService.deleteException(exceptionId);
Copy link
Member

Choose a reason for hiding this comment

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

deleteException in this case is clear, because we know that we want to delete one so it is obvious that we need for example id

Comment on lines 18 to 19
EditNoteApi as EditNoteApi,
GetUserNotesApi as GetUserNotesApi,
Copy link
Member

Choose a reason for hiding this comment

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

Wait, why there is 'as'?

Comment on lines +30 to +32
@GetUserNotesApi()
getUserNotes(@GetUser() user: UserEntity): Promise<NoteDTO[]> {
return this.notesService.fetchByUser(user);
Copy link
Member

Choose a reason for hiding this comment

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

I forgot to mention that if TypeScript infer type properly if you hover your mouse on function then you don't need to declare type explicitly

Comment on lines 26 to 27
GetUserTasksApi as GetUserTasksApi,
GetTaskByIdApi as GetTaskbyIdApi,
Copy link
Member

Choose a reason for hiding this comment

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

Again unnecessary 'as'

@IK541
Copy link
Collaborator Author

IK541 commented Sep 20, 2024

Both changes have been implemented: fetch changed to fetchById and as removed
The updated naming table looks like this:

html request method endpoint name controller method name service method name
GET <resource> getUser<Resource>s fetchByUser
GET <resource>/<id> get<Resource>ById fetchById
POST <resource> add<Resource> add
PATCH <resource>/<id> edit<Resource> edit
DELETE <resource>/<id> delete<Resource> delete

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.

3 participants