-
Notifications
You must be signed in to change notification settings - Fork 0
Add Delete Product Handler #45
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98994f6
Add Bruno collection for Product API endpoints
jlpdeveloper 66109b7
Add DeleteProduct handler with route and unit tests
jlpdeveloper 9236ec4
Add `lint` task to `justfile` for code linting with `golangci-lint`
jlpdeveloper ef9927c
Handle `sql.ErrNoRows` in `DeleteProduct` to prevent internal server …
jlpdeveloper f5a7bd0
Add unit tests for `DeleteProduct` to verify behavior with context ti…
jlpdeveloper 6b5f12d
Replace `sql.ErrNoRows` with `pgx.ErrNoRows` in `DeleteProduct` handl…
jlpdeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| info: | ||
| name: Create Product | ||
| type: http | ||
| seq: 1 | ||
|
|
||
| http: | ||
| method: POST | ||
| url: "{{baseUrl}}/api/products" | ||
| body: | ||
| type: json | ||
| data: |- | ||
| { | ||
| "platform_id": 3, | ||
| "name": "Product 1", | ||
| "description": "Test Product" | ||
| } | ||
| auth: inherit | ||
|
|
||
| settings: | ||
| encodeUrl: true | ||
| timeout: 0 | ||
| followRedirects: true | ||
| maxRedirects: 5 | ||
|
|
||
| examples: | ||
| - name: sample | ||
| request: | ||
| url: "{{baseUrl}}/api/products" | ||
| method: POST | ||
| body: | ||
| type: json | ||
| data: |- | ||
| { | ||
| "platform_id": 3, | ||
| "name": "Product 1", | ||
| "description": "Test Product" | ||
| } | ||
| response: | ||
| status: 201 | ||
| statusText: Created | ||
| headers: | ||
| - name: vary | ||
| value: Origin | ||
| - name: date | ||
| value: Mon, 04 May 2026 01:20:16 GMT | ||
| - name: content-length | ||
| value: "0" | ||
| body: | ||
| type: text | ||
| data: "" | ||
|
|
||
| docs: |- | ||
| # Create Product | ||
|
|
||
| Creates a new product | ||
|
|
||
| ## Possible Responses | ||
| | Status Code | Notes | | ||
| | -- | --| | ||
| | 201 | Successfully Created | | ||
| | 400 | Name Missing or platform missing | | ||
| | 500 | Error | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| info: | ||
| name: Delete Product | ||
| type: http | ||
| seq: 2 | ||
|
|
||
| http: | ||
| method: DELETE | ||
| url: "{{baseUrl}}/api/products/:id" | ||
| params: | ||
| - name: id | ||
| value: "1" | ||
| type: path | ||
| auth: inherit | ||
|
|
||
| settings: | ||
| encodeUrl: true | ||
| timeout: 0 | ||
| followRedirects: true | ||
| maxRedirects: 5 | ||
|
|
||
| examples: | ||
| - name: sample | ||
| request: | ||
| url: "{{baseUrl}}/api/products/:id" | ||
| method: DELETE | ||
| params: | ||
| - name: id | ||
| value: "1" | ||
| type: path | ||
| response: | ||
| status: 204 | ||
| statusText: No Content | ||
| headers: | ||
| - name: vary | ||
| value: Origin | ||
| - name: date | ||
| value: Mon, 04 May 2026 01:23:27 GMT | ||
| body: | ||
| type: text | ||
| data: "" | ||
|
|
||
| docs: |- | ||
| # Delete Product | ||
|
|
||
| Deletes a product. See sample response | ||
|
|
||
| ## Possible Responses | ||
| | Status Code | Notes | | ||
| | -- | --| | ||
| | 204 | Success | | ||
| | 400 | Invalid Id | | ||
| | 500 | Error | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| info: | ||
| name: Product | ||
| type: folder | ||
| seq: 2 | ||
|
|
||
| request: | ||
| auth: inherit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package productHandler | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "net/http" | ||
| "products/internal" | ||
| "time" | ||
|
|
||
| "github.com/jackc/pgx/v5" | ||
| ) | ||
|
|
||
| func (h *ProductHandler) DeleteProduct(w http.ResponseWriter, r *http.Request) { | ||
| id, ok := internal.GetIntFromRequestPath("id", r) | ||
| if !ok { | ||
| http.Error(w, "Invalid product ID", http.StatusBadRequest) | ||
| return | ||
| } | ||
| contextWithTimeOut, cancel := context.WithTimeout(r.Context(), 5*time.Second) | ||
| defer cancel() | ||
| err := h.queries.DeleteProduct(contextWithTimeOut, id) | ||
| if err != nil && !errors.Is(err, pgx.ErrNoRows) { | ||
| http.Error(w, "Failed to delete product", http.StatusInternalServerError) | ||
| return | ||
| } | ||
| w.WriteHeader(http.StatusNoContent) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,4 +57,8 @@ stop: | |
| main: | ||
| git switch main | ||
| git fetch | ||
| git pull | ||
| git pull | ||
|
|
||
| # Lint code | ||
| lint: | ||
| golangci-lint run | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.