in handlers/apigateway.go [54:74]
func (l *APIGatewayV2Handler) PutHandler(ctx context.Context, event events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
id, ok := event.PathParameters["id"]
if !ok {
return errResponse(http.StatusBadRequest, "missing 'id' parameter in path"), nil
}
if strings.TrimSpace(event.Body) == "" {
return errResponse(http.StatusBadRequest, "empty request body"), nil
}
product, err := l.products.PutProduct(ctx, id, []byte(event.Body))
if err != nil {
if errors.Is(err, domain.ErrJsonUnmarshal) || errors.Is(err, domain.ErrProductIdMismatch) {
return errResponse(http.StatusBadRequest, err.Error()), nil
} else {
return errResponse(http.StatusInternalServerError, err.Error()), nil
}
}
return response(http.StatusCreated, product), nil
}