Skip to content

Add solution for Challenge 13 by manik23#1256

Open
manik23 wants to merge 7 commits intoRezaSi:mainfrom
manik23:challenge-13-manik23
Open

Add solution for Challenge 13 by manik23#1256
manik23 wants to merge 7 commits intoRezaSi:mainfrom
manik23:challenge-13-manik23

Conversation

@manik23
Copy link
Contributor

@manik23 manik23 commented Feb 2, 2026

Challenge 13 Solution

Submitted by: @manik23
Challenge: Challenge 13

Description

This PR contains my solution for Challenge 13.

Changes

  • Added solution file to challenge-13/submissions/manik23/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 Feb 2, 2026

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a solution submission for Challenge 13 by a specific author.
Description check ✅ Passed The description is directly related to the changeset, explaining that it contains the Challenge 13 solution submission and listing the specific file added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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: 2

🤖 Fix all issues with AI agents
In `@challenge-13/submissions/manik23/solution-template.go`:
- Around line 148-173: The ListProducts function opens a rows result set but
never closes it, leaking DB connections; after successfully getting rows in
ProductStore.ListProducts, add a defer rows.Close() immediately after the nil
err check (right after ps.db.Query returns) so the rows are always closed even
on early returns or errors during scanning/iteration; reference the rows
variable and the ListProducts method to locate where to insert the defer.
- Around line 31-57: In InitDB, fix the schema typo and resource leak: change
the SQL in initTable so the price column uses REAL NOT NULL (not READ), ensure
that if sql.Open succeeds but db.Ping() or db.Exec(initTable) fails you call
db.Close() before returning, and wrap the Ping error with fmt.Errorf("%w", err)
(or similar) when returning the Ping failure; reference InitDB, sql.Open,
db.Ping, initTable, and db.Exec in your changes.

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: 2

🤖 Fix all issues with AI agents
In `@challenge-13/submissions/manik23/solution-template.go`:
- Around line 85-96: The scan into p.Category will fail if category is NULL;
update the ps.db.QueryRow(...) scan to use a sql.NullString (e.g., declare a
local variable named category sql.NullString) and scan into &category instead of
&p.Category, then set p.Category = category.String (which yields empty string
when NULL); alternatively modify the SQL query to use COALESCE(category, '') AS
category and continue scanning into &p.Category. Ensure the change is applied
where QueryRow is called (ps.db.QueryRow, Product struct population) and handle
sql.ErrNoRows as before.
- Around line 154-169: ListProducts is scanning the DB category into a plain
string which panics/returns NULL when category is NULL; change the SELECT to use
COALESCE(category, '') or scan into sql.NullString and assign Product.Category =
ns.String (or ""), e.g. update the query variable used in ListProducts and/or
replace the rows.Scan target for category so null DB values are safely converted
to an empty string before appending Product instances.
🧹 Nitpick comments (3)
challenge-13/submissions/manik23/solution-template.go (3)

32-34: Remove leftover TODO comments.

The implementation is complete, but the placeholder TODO comments remain. Consider removing them to keep the code clean.

♻️ Proposed fix
 // InitDB sets up a new SQLite database and creates the products table
 func InitDB(dbPath string) (*sql.DB, error) {
-	// TODO: Open a SQLite database connection
-	// TODO: Create the products table if it doesn't exist
-	// The table should have columns: id, name, price, quantity, category
-
 	db, err := sql.Open("sqlite3", dbPath)

82-83: Remove leftover TODO comments.

Implementation is complete; these placeholders should be removed.


151-153: Remove leftover TODO comments.

Implementation is complete; these placeholders should be removed.

manik23 and others added 2 commits February 2, 2026 22:42
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

1 participant