-
Notifications
You must be signed in to change notification settings - Fork 4
Add PreviewPdfAsync methods for invoice PDF preview #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new PreviewPdfAsync method to enable invoice PDF preview functionality before stamping. This feature allows users to preview how an invoice PDF will look without actually creating the invoice.
Key changes:
- Added
PreviewPdfAsyncmethod toInvoiceWrapperclass - Added corresponding route helper in
InvoiceRouter - Updated version to 4.10.0
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| facturapi-net.csproj | Version bump to 4.10.0 |
| Wrappers/InvoiceWrapper.cs | Added PreviewPdfAsync method implementation |
| Router/InvoiceRouter.cs | Added PreviewPdf route helper method |
| CHANGELOG.md | Added changelog entry for new feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| var response = await client.GetAsync(Router.PreviewPdf(query)); | ||
| if (!response.IsSuccessStatusCode) | ||
| { | ||
| var resultString = await response.Content.ReadAsStringAsync(); | ||
| var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings); | ||
| throw new FacturapiException(error["message"].ToString()); | ||
| } | ||
| var stream = await response.Content.ReadAsStreamAsync(); | ||
| return stream; |
Copilot
AI
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method doesn't dispose of the HTTP response, which can lead to resource leaks. The response should be wrapped in a using statement or the stream should be copied to avoid keeping the HTTP connection open.
| var response = await client.GetAsync(Router.PreviewPdf(query)); | |
| if (!response.IsSuccessStatusCode) | |
| { | |
| var resultString = await response.Content.ReadAsStringAsync(); | |
| var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings); | |
| throw new FacturapiException(error["message"].ToString()); | |
| } | |
| var stream = await response.Content.ReadAsStreamAsync(); | |
| return stream; | |
| using (var response = await client.GetAsync(Router.PreviewPdf(query))) | |
| { | |
| if (!response.IsSuccessStatusCode) | |
| { | |
| var resultString = await response.Content.ReadAsStringAsync(); | |
| var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings); | |
| throw new FacturapiException(error["message"].ToString()); | |
| } | |
| var responseStream = await response.Content.ReadAsStreamAsync(); | |
| var memoryStream = new MemoryStream(); | |
| await responseStream.CopyToAsync(memoryStream); | |
| memoryStream.Position = 0; | |
| return memoryStream; | |
| } |
| { | ||
| var resultString = await response.Content.ReadAsStringAsync(); | ||
| var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings); | ||
| throw new FacturapiException(error["message"].ToString()); |
Copilot
AI
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference exception if the response JSON doesn't contain a 'message' field. The code should check if error['message'] exists before calling ToString().
No description provided.