MCPcopy Index your code
hub / github.com/dreamsofcode-io/grpc / Update

Method Update

pokemon-api/pokedex/server.go:102–130  ·  view source on GitHub ↗
(
	ctx context.Context,
	req *pb.PokemonUpdateRequest,
)

Source from the content-addressed store, hash-verified

100}
101
102func (s *Server) Update(
103 ctx context.Context,
104 req *pb.PokemonUpdateRequest,
105) (*pb.Pokemon, error) {
106 p, err := s.repository.FindByID(ctx, req.Id)
107 if err != nil {
108 return nil, status.Errorf(codes.NotFound, "failed to find pokemon")
109 }
110
111 strTypes := make([]string, len(req.Type))
112 for i, t := range req.Type {
113 strTypes[i] = t.String()
114 }
115
116 p.UpdatedAt = time.Now()
117 p.Name = req.Name
118 p.Types = strTypes
119
120 err = s.repository.Update(ctx, p)
121 if errors.Is(err, ErrNotFound) {
122 return nil, status.Errorf(codes.NotFound, "failed to update pokemon")
123 } else if err != nil {
124 return nil, status.Errorf(codes.Internal, "failed to update pokemon")
125 }
126
127 res := pokemonToResponse(p)
128
129 return &res, nil
130}
131
132func (s *Server) Delete(
133 ctx context.Context,

Callers

nothing calls this directly

Calls 4

pokemonToResponseFunction · 0.85
FindByIDMethod · 0.80
UpdateMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected