1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package honeycode
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/honeycode/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// The ListTableColumns API allows you to retrieve a list of all the columns in a
16// table in a workbook.
17func (c *Client) ListTableColumns(ctx context.Context, params *ListTableColumnsInput, optFns ...func(*Options)) (*ListTableColumnsOutput, error) {
18	if params == nil {
19		params = &ListTableColumnsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListTableColumns", params, optFns, addOperationListTableColumnsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListTableColumnsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListTableColumnsInput struct {
33
34	// The ID of the table whose columns are being retrieved. If a table with the
35	// specified id could not be found, this API throws ResourceNotFoundException.
36	//
37	// This member is required.
38	TableId *string
39
40	// The ID of the workbook that contains the table whose columns are being
41	// retrieved. If a workbook with the specified id could not be found, this API
42	// throws ResourceNotFoundException.
43	//
44	// This member is required.
45	WorkbookId *string
46
47	// This parameter is optional. If a nextToken is not specified, the API returns the
48	// first page of data. Pagination tokens expire after 1 hour. If you use a token
49	// that was returned more than an hour back, the API will throw
50	// ValidationException.
51	NextToken *string
52}
53
54type ListTableColumnsOutput struct {
55
56	// The list of columns in the table.
57	//
58	// This member is required.
59	TableColumns []types.TableColumn
60
61	// Provides the pagination token to load the next page if there are more results
62	// matching the request. If a pagination token is not present in the response, it
63	// means that all data matching the request has been loaded.
64	NextToken *string
65
66	// Indicates the cursor of the workbook at which the data returned by this request
67	// is read. Workbook cursor keeps increasing with every update and the increments
68	// are not sequential.
69	WorkbookCursor int64
70
71	// Metadata pertaining to the operation's result.
72	ResultMetadata middleware.Metadata
73}
74
75func addOperationListTableColumnsMiddlewares(stack *middleware.Stack, options Options) (err error) {
76	err = stack.Serialize.Add(&awsRestjson1_serializeOpListTableColumns{}, middleware.After)
77	if err != nil {
78		return err
79	}
80	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListTableColumns{}, middleware.After)
81	if err != nil {
82		return err
83	}
84	if err = addSetLoggerMiddleware(stack, options); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
88		return err
89	}
90	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
91		return err
92	}
93	if err = addResolveEndpointMiddleware(stack, options); err != nil {
94		return err
95	}
96	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
97		return err
98	}
99	if err = addRetryMiddlewares(stack, options); err != nil {
100		return err
101	}
102	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
103		return err
104	}
105	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
109		return err
110	}
111	if err = addClientUserAgent(stack); err != nil {
112		return err
113	}
114	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
115		return err
116	}
117	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addOpListTableColumnsValidationMiddleware(stack); err != nil {
121		return err
122	}
123	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTableColumns(options.Region), middleware.Before); err != nil {
124		return err
125	}
126	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
127		return err
128	}
129	if err = addResponseErrorMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addRequestResponseLogging(stack, options); err != nil {
133		return err
134	}
135	return nil
136}
137
138// ListTableColumnsAPIClient is a client that implements the ListTableColumns
139// operation.
140type ListTableColumnsAPIClient interface {
141	ListTableColumns(context.Context, *ListTableColumnsInput, ...func(*Options)) (*ListTableColumnsOutput, error)
142}
143
144var _ ListTableColumnsAPIClient = (*Client)(nil)
145
146// ListTableColumnsPaginatorOptions is the paginator options for ListTableColumns
147type ListTableColumnsPaginatorOptions struct {
148	// Set to true if pagination should stop if the service returns a pagination token
149	// that matches the most recent token provided to the service.
150	StopOnDuplicateToken bool
151}
152
153// ListTableColumnsPaginator is a paginator for ListTableColumns
154type ListTableColumnsPaginator struct {
155	options   ListTableColumnsPaginatorOptions
156	client    ListTableColumnsAPIClient
157	params    *ListTableColumnsInput
158	nextToken *string
159	firstPage bool
160}
161
162// NewListTableColumnsPaginator returns a new ListTableColumnsPaginator
163func NewListTableColumnsPaginator(client ListTableColumnsAPIClient, params *ListTableColumnsInput, optFns ...func(*ListTableColumnsPaginatorOptions)) *ListTableColumnsPaginator {
164	options := ListTableColumnsPaginatorOptions{}
165
166	for _, fn := range optFns {
167		fn(&options)
168	}
169
170	if params == nil {
171		params = &ListTableColumnsInput{}
172	}
173
174	return &ListTableColumnsPaginator{
175		options:   options,
176		client:    client,
177		params:    params,
178		firstPage: true,
179	}
180}
181
182// HasMorePages returns a boolean indicating whether more pages are available
183func (p *ListTableColumnsPaginator) HasMorePages() bool {
184	return p.firstPage || p.nextToken != nil
185}
186
187// NextPage retrieves the next ListTableColumns page.
188func (p *ListTableColumnsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTableColumnsOutput, error) {
189	if !p.HasMorePages() {
190		return nil, fmt.Errorf("no more pages available")
191	}
192
193	params := *p.params
194	params.NextToken = p.nextToken
195
196	result, err := p.client.ListTableColumns(ctx, &params, optFns...)
197	if err != nil {
198		return nil, err
199	}
200	p.firstPage = false
201
202	prevToken := p.nextToken
203	p.nextToken = result.NextToken
204
205	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
206		p.nextToken = nil
207	}
208
209	return result, nil
210}
211
212func newServiceMetadataMiddleware_opListTableColumns(region string) *awsmiddleware.RegisterServiceMetadata {
213	return &awsmiddleware.RegisterServiceMetadata{
214		Region:        region,
215		ServiceID:     ServiceID,
216		SigningName:   "honeycode",
217		OperationName: "ListTableColumns",
218	}
219}
220