Let’s now implement the final gRPC handler function of our Rocket microservice.
Our DeleteRocket Handler
// DeleteRocket - handler for deleting a rocket
func (h Handler) DeleteRocket(ctx context.Context, req *rkt.DeleteRocketRequest) (*rkt.DeleteRocketResponse, error) {
log.Print("delete rocket gRPC endpoint hit")
err := h.RocketService.DeleteRocket(ctx, req.Rocket.Id)
if err != nil {
return &rkt.DeleteRocketResponse{}, err
}
return &rkt.DeleteRocketResponse{
Status: "successfully delete rocket",
}, nil
}
Our DB Package Updates:
// DeleteRocket - attempts to delete a rocket from the database return err if error
func (s Store) DeleteRocket(id string) error {
uid, err := uuid.FromString(id)
if err != nil {
return err
}
_, err = s.db.Exec(
`DELETE FROM rockets where id = $1`,
uid,
)
if err != nil {
return err
}
return nil
}
Testing with BloomRPC
Let’s navigate into BloomRPC and import our rocket.proto
file from the Protobuf monorepo and then attempt both an DeleteRocket
gRPC request using one of the UUID’s from a rocket we have previously created.
Conclusion
Awesome, we have now fully implemented the DeleteRocket
gRPC handler function and we have validated that we can delete rockets from the database based on their UUID.