Skip to content

Add solution for Challenge 13 by Kosench#835

Merged
RezaSi merged 2 commits intoRezaSi:mainfrom
Kosench:challenge-13-Kosench-1764541025
Nov 30, 2025
Merged

Add solution for Challenge 13 by Kosench#835
RezaSi merged 2 commits intoRezaSi:mainfrom
Kosench:challenge-13-Kosench-1764541025

Conversation

@Kosench
Copy link
Contributor

@Kosench Kosench commented Nov 30, 2025

Challenge 13 Solution

Submitted by: @Kosench
Challenge: Challenge 13

Description

This PR contains my solution for Challenge 13.

Changes

  • Added solution file to challenge-13/submissions/Kosench/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 30, 2025

Walkthrough

Adds a SQLite-backed ProductStore in Go: defines Product and ProductStore, provides InitDB with schema creation, NewProductStore, full CRUD (Create/Get/Update/Delete), ListProducts (optional category filter), BatchUpdateInventory within a transaction, and a main scaffold.

Changes

Cohort / File(s) Summary
Product Inventory System Implementation
challenge-13/submissions/Kosench/solution-template.go
Adds Product (ID, Name, Price, Quantity, Category) and ProductStore (*sql.DB), InitDB with products table schema and constraints, NewProductStore, CRUD methods (CreateProduct, GetProduct, UpdateProduct, DeleteProduct), ListProducts(category string), BatchUpdateInventory(updates map[int64]int) performing transactional updates with per-item validation and rollback, error wrapping, and a main() scaffold.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review transaction correctness and rollback paths in BatchUpdateInventory
  • Verify parameterized queries and filter handling in ListProducts
  • Confirm validation of price/quantity (≥ 0) and RowsAffected checks for updates/deletes
  • Inspect InitDB for proper connection handling and schema constraints

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a Challenge 13 solution by Kosench. It is concise, specific, and clearly conveys the primary purpose of the PR.
Description check ✅ Passed The description is well-related to the changeset, clearly explaining that it adds a Challenge 13 solution with supporting details about testing and code practices.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7820c4e and 57c9468.

📒 Files selected for processing (1)
  • challenge-13/submissions/Kosench/solution-template.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • challenge-13/submissions/Kosench/solution-template.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
challenge-13/submissions/Kosench/solution-template.go (1)

95-100: Wrap the error for consistency.

Non-ErrNoRows errors are returned unwrapped, which is inconsistent with the rest of the codebase and loses context about where the error originated.

 	if err != nil {
 		if errors.Is(err, sql.ErrNoRows) {
 			return nil, fmt.Errorf("product with ID %d not found", id)
 		}
-		return nil, err
+		return nil, fmt.Errorf("failed to get product: %w", err)
 	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 560ce41 and 7820c4e.

📒 Files selected for processing (1)
  • challenge-13/submissions/Kosench/solution-template.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
challenge-13/submissions/Kosench/solution-template.go (2)
challenge-13/submissions/Gandook/solution-template.go (1)
  • ID (144-144)
challenge-13/submissions/Ali-Fartoot/solution-template.go (1)
  • DB (29-29)
🔇 Additional comments (6)
challenge-13/submissions/Kosench/solution-template.go (6)

1-28: LGTM!

The package structure, imports, and type definitions are clean and idiomatic. The anonymous import for the SQLite driver and the struct designs follow Go conventions.


61-81: LGTM!

The CreateProduct implementation correctly inserts the product, retrieves the auto-generated ID, and updates the passed product struct. Error handling is appropriate.


105-134: LGTM!

The UpdateProduct implementation correctly updates all fields and validates that a row was actually affected, providing proper not-found detection.


136-155: LGTM!

The DeleteProduct implementation correctly handles the delete operation and validates that a row was actually deleted.


157-197: LGTM!

Good implementation with proper handling of the optional category filter. The defer rows.Close() and rows.Err() check after iteration are correct practices for preventing resource leaks and catching iteration errors.


238-240: LGTM!

The empty main function is appropriate for a solution template that will be tested externally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants