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

Feature/pet #4

Merged
merged 147 commits into from
Jan 4, 2024
Merged

Feature/pet #4

merged 147 commits into from
Jan 4, 2024

Conversation

macgeargear
Copy link
Contributor

Update pet service & pet handler

Pet service

Add pet services

⚠️ ⚠️ ⚠️ pet service have no image urls return yet (will implement after image service and handler complete)

  • FindAll
  • FindOne
  • Create
  • Update
  • Delete
  • ChangeView

Add pet services test

  • TestFindAllSuccess
  • TestFindOneSuccess
  • TestFindOneNotFoundErr
  • TestFindOneGrpcErr
  • TestCreateSuccess
  • TestCreateGrpcErr
  • TestUpdateSuccess
  • TestUpdateNotFound
  • TestUpdateGrpcErr
  • TestDeleteSuccess
  • TestDeleteNotFound
  • TestDeleteGrpcErr
  • TestChangeViewSuccess
  • TestChangeViewNotFound
  • TestChangeViewGrpcErr

Pet handler

  • change argument in handler function from c *fiber.Ctx to router.IContext
  • change argument in ChangeView(id) to ChangeView(*dto.ChangeViewDto) (bool, *dto.ResponseErr)

Add pet handler

  • FindAll
  • FindOne
  • Create
  • Update
  • ChangeView
  • Delete

Add per handler test

  • TestFindAllSuccess
  • TestFindOneSuccess
  • TestFindOneNotFoundErr
  • TestFindOneGrpcErr
  • TestCreateSuccess
  • TestCreateGrpcErr
  • TestUpdateSuccess
  • TestUpdateNotFound
  • TestUpdateGrpcErr
  • TestDeleteSuccess
  • TestDeleteNotFound
  • TestDeleteGrpcErr
  • TestDeleteInvalidID
  • TestChangeViewSuccess
  • TestChangeViewNotFound
  • TestChangeViewGrpcErr

PetDto

  • Add CreatePetDto
  • FindOnePetDto
  • ChangeViewPetDto
  • UpdatePetDto
  • DeleteRequest (will be change to DeletePetDto)

Mock

  • Add Service and Client Mock for Handler and Service
  • Add Context mock for *fiber.Context

ALL UNIT TEST PASSED

  • Handler
Screenshot 2023-12-31 at 00 31 23
  • Service
Screenshot 2023-12-31 at 00 31 40

Problems

  • cannot run ./src/main.go
Screenshot 2023-12-31 at 00 30 20
  • I'll test manual after fixing pet service & handler to return image urls

Copy link
Member

@ImSoZRious ImSoZRious left a comment

Choose a reason for hiding this comment

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

👍

// @Success 200 {object} dto.PetDto
// @Failure 500 {object} dto.ResponseInternalErr "Internal service error"
// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down"
// @Router /v1/pet/ [get]
Copy link
Member

Choose a reason for hiding this comment

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

To follow convention this should be /v1/pets. Note the s and trailing slash.

// @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body"
// @Failure 500 {object} dto.ResponseInternalErr "Internal service error"
// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down"
// @Router /v1/pet/{id} [get]
Copy link
Member

Choose a reason for hiding this comment

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

Also here

Copy link
Contributor Author

@macgeargear macgeargear Jan 4, 2024

Choose a reason for hiding this comment

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

it was grouped by pet := GroupWithAuthMiddleware(r, "/pet", authGuard.Use) should i change this

Copy link
Member

Choose a reason for hiding this comment

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

yep

Copy link
Member

@ImSoZRious ImSoZRious left a comment

Choose a reason for hiding this comment

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

for 2,000 lines change, this is impressively good pr.

}

func (s *Service) FindOne(id string) (result *proto.Pet, err *dto.ResponseErr) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Please change all context to use the HTTP request context. I'm sure that fiber provide it.

Incoming requests to a server should create a Context, and outgoing calls to servers should accept a Context. The chain of function calls between them must propagate the Context, optionally replacing it with a derived Context created using WithCancel, WithDeadline, WithTimeout, or WithValue. When a Context is canceled, all Contexts derived from it are also canceled.

https://pkg.go.dev/context

Sorry for all the test for have to fix tho D:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💀

// @Failure 400 {object} dto.ResponseBadRequestErr "Invalid request body"
// @Failure 500 {object} dto.ResponseInternalErr "Internal service error"
// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down"
// @Router /v1/pet/{id} [get]
Copy link
Member

Choose a reason for hiding this comment

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

yep

src/app/service/pet/pet.service.go Show resolved Hide resolved
// @Failure 500 {object} dto.ResponseInternalErr "Internal service error"
// @Failure 503 {object} dto.ResponseServiceDownErr "Service is down"
// @Router /v1/pet/ [get]
func (h *Handler) FindAll(c router.IContext) {
Copy link
Member

Choose a reason for hiding this comment

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

drop the I IContext, It's historical reason. We want to move on, not repeat itself. Also to reduce techinal dept for the future :)

Shortly, I prefixed stand for Interface which many OOP-language like to use in the past. Nowadays, only c# still use this naming convention.

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 agree, i just use it because someone created before lamo

Copy link
Member

@ImSoZRious ImSoZRious Jan 4, 2024

Choose a reason for hiding this comment

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

Do you mention P Mo *cough* *cough*.. P' Modem?

Copy link
Member

Choose a reason for hiding this comment

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

It's time to move on, if you think something isn't right you can discuss.

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'll change all in next pr🫡 i think this pr is toooo much 🥶

@macgeargear macgeargear merged commit f9e4a26 into dev Jan 4, 2024
2 checks passed
@macgeargear macgeargear deleted the feature/pet branch January 4, 2024 07:59
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.

4 participants