( ctx context.Context, req *pb.PokemonUpdateRequest, )
| 100 | } |
| 101 | |
| 102 | func (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 | |
| 132 | func (s *Server) Delete( |
| 133 | ctx context.Context, |
nothing calls this directly
no test coverage detected