Skip to content

Add solution for gin challenge-1-basic-routing by WHFF521 - #1925

Merged
github-actions[bot] merged 1 commit into
RezaSi:mainfrom
WHFF521:package-gin-challenge-1-basic-routing-WHFF521
Jul 31, 2026
Merged

Add solution for gin challenge-1-basic-routing by WHFF521#1925
github-actions[bot] merged 1 commit into
RezaSi:mainfrom
WHFF521:package-gin-challenge-1-basic-routing-WHFF521

Conversation

@WHFF521

@WHFF521 WHFF521 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

gin challenge-1-basic-routing Solution

Submitted by: @WHFF521
Package: gin
Challenge: challenge-1-basic-routing

Description

This PR contains my solution for gin challenge-1-basic-routing.

Changes

  • Added solution file to packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a Gin-based in-memory user REST API on port 8000. The API supports user listing, retrieval, creation, replacement, and deletion. It also defines case-insensitive name search logic, but does not register a search route.

Changes

User API

Layer / File(s) Summary
Server contracts and route wiring
packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go
Defines exported User and Response models, seeds users, registers CRUD routes, and starts the server on port 8000.
CRUD handlers and validation
packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go
Implements user lookup, validation, listing, retrieval, creation, replacement, and deletion with HTTP status responses.
Name search handler
packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go
Adds case-insensitive name search and rejects blank queries, but does not register the handler as a route.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A rabbit hops through routes so neat,
With users stored in memory sweet.
Create, update, delete, and find,
Search by name, case-insensitive kind.
Port eight thousand starts the show—
Hop, hop, Gin, and off we go!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Gin challenge and the added solution from WHFF521.
Description check ✅ Passed The description relates directly to the added Gin challenge solution and identifies the submitted file and claimed testing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 790c5ea2-ffa4-4966-9745-debe2d2319aa

📥 Commits

Reviewing files that changed from the base of the PR and between cf760ca and 5f2c61a.

📒 Files selected for processing (1)
  • packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go

Comment on lines +28 to +34
// In-memory storage
var users = []User{
{ID: 1, Name: "John Doe", Email: "john@example.com", Age: 30},
{ID: 2, Name: "Jane Smith", Email: "jane@example.com", Age: 25},
{ID: 3, Name: "Bob Wilson", Email: "bob@example.com", Age: 35},
}
var nextID = 4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go --items all --type function
rg -n -C 4 '\b(users|nextID)\b|func (getAllUsers|getUserByID|createUser|updateUser|deleteUser|searchUsers|findUserByID)' \
  packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go

Repository: RezaSi/go-interview-practice

Length of output: 3989


🏁 Script executed:

#!/bin/bash
set -euo pipefail

cat -n packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go | sed -n '1,270p'
rg -n 'sync\.' packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go || true

Repository: RezaSi/go-interview-practice

Length of output: 7982


Synchronize users and nextID with sync.RWMutex.

Gin handles requests concurrently, and getAllUsers, getUserByID, createUser, updateUser, deleteUser, searchUsers, and findUserByID all access shared users and nextID without locking. Hold RLock for reads and Lock for write operations to prevent lost updates, duplicate IDs, and read races.

Comment on lines +48 to +50
// GET /users/search - Search users by name

r.Run(":8000")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go --items all --type function
rg -n -C 4 'GET\("/users/search"|func searchUsers|GET\("/users/:id"' \
  packages/gin/challenge-1-basic-routing/submissions/WHFF521/solution.go \
  packages/gin/challenge-1-basic-routing/solution-template_test.go

Repository: RezaSi/go-interview-practice

Length of output: 3612


Register the search route.

searchUsers handles GET /users/search?name=value, but the router only registers GET /users/:id. That request reaches getUserByID, fails integer parsing for search, and returns HTTP 400 instead of executing the handler.

Proposed fix
 	// GET /users/search - Search users by name
+	r.GET("/users/search", searchUsers)
 
 	r.Run(":8000")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// GET /users/search - Search users by name
r.Run(":8000")
// GET /users/search - Search users by name
r.GET("/users/search", searchUsers)
r.Run(":8000")

Comment on lines +188 to +193
if err != nil {
c.JSON(http.StatusBadRequest, Response{
Success: false,
Error: "",
Code: http.StatusNotFound,
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Set Response.Code to the transmitted status.

This branch sends HTTP 400 but serializes code: 404. Clients that consume the response body receive contradictory error status data.

 	    c.JSON(http.StatusBadRequest, Response{
 	        Success: false,
 	        Error: "",
-	        Code: http.StatusNotFound,
+	        Code: http.StatusBadRequest,
 	    })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err != nil {
c.JSON(http.StatusBadRequest, Response{
Success: false,
Error: "",
Code: http.StatusNotFound,
})
if err != nil {
c.JSON(http.StatusBadRequest, Response{
Success: false,
Error: "",
Code: http.StatusBadRequest,
})

@github-actions
github-actions Bot merged commit 7876c90 into RezaSi:main Jul 31, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Auto-merged!

This PR was automatically merged after 2 days with all checks passing.

Thank you for your contribution, @WHFF521!

📊 Scoreboards and badges will be updated shortly.

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