Skip to content

Add solution for fiber challenge-1-basic-routing by mutantkeyboard#1648

Open
mutantkeyboard wants to merge 1 commit into
RezaSi:mainfrom
mutantkeyboard:package-fiber-challenge-1-basic-routing-mutantkeyboard
Open

Add solution for fiber challenge-1-basic-routing by mutantkeyboard#1648
mutantkeyboard wants to merge 1 commit into
RezaSi:mainfrom
mutantkeyboard:package-fiber-challenge-1-basic-routing-mutantkeyboard

Conversation

@mutantkeyboard
Copy link
Copy Markdown

fiber challenge-1-basic-routing Solution

Submitted by: @mutantkeyboard
Package: fiber
Challenge: challenge-1-basic-routing

Description

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

Changes

  • Added solution file to packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.go

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Walkthrough

A new submission file implements a thread-safe, in-memory task management API using Fiber. It provides a Task struct and TaskStore with CRUD operations, exposes HTTP endpoints for task management on port 3000, and includes a seeded sample dataset.

Changes

Task Management API Implementation

Layer / File(s) Summary
Data Types
packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.go
Task struct with ID, Title, Description, Completed fields; TaskStore with mutex-protected tasks map and nextID counter for thread-safe operations.
Store Operations
packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.go
Methods on TaskStore: NewTaskStore() pre-seeds two sample tasks; GetAll(), GetByID(), Create(), Update(), Delete() implement standard CRUD with read/write locking.
HTTP Route Handlers
packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.go
setupApp() registers six routes: GET /ping returns {"message":"pong"}; GET /tasks and POST /tasks handle all-tasks retrieval and creation; GET /tasks/:id, PUT /tasks/:id, DELETE /tasks/:id handle single-task operations with ID parsing, error handling, and appropriate HTTP status codes (400, 404, 201, 204).
Server Entry Point
packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.go
Global taskStore variable initialized at package level; main() constructs the app via setupApp() and starts listening on :3000.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A hopping hare did code with care,
Task routes now routed everywhere!
With fiber spun and tasks well done,
REST endpoints shine in the sun.
PUT, GET, DELETE with glee—
CRUD-ities dance so merrily! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the pull request as a solution submission for the fiber challenge-1-basic-routing challenge by mutantkeyboard, directly matching the changeset.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the solution submission, listing the specific file added, and documenting the testing status.
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.

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

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.11.4)

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

Copy link
Copy Markdown
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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a21a81e-7981-4f4a-acf2-c968167f1b8f

📥 Commits

Reviewing files that changed from the base of the PR and between e6e278b and 08414ac.

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

Comment on lines +134 to +137
id, err := strconv.Atoi(c.Params("id"))
if err != nil{
return err
}
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Return 400 Bad Request for malformed task IDs.

Returning the raw Atoi error turns a client input mistake into a 500 and leaks parse details. Match the other handlers and send a 400 here instead.

Comment on lines +152 to +205
// GetAll returns all tasks
func (ts *TaskStore) GetAll() []*Task {
ts.mu.RLock()
defer ts.mu.RUnlock()

tasks := make([]*Task, 0, len(ts.tasks))
for _, task := range ts.tasks {
tasks = append(tasks, task)
}
return tasks
}

// GetByID returns a task by ID
func (ts *TaskStore) GetByID(id int) (*Task, bool) {
ts.mu.RLock()
defer ts.mu.RUnlock()

task, exists := ts.tasks[id]
return task, exists
}

// Create adds a new task and returns it
func (ts *TaskStore) Create(title, description string, completed bool) *Task {
ts.mu.Lock()
defer ts.mu.Unlock()

task := &Task{
ID: ts.nextID,
Title: title,
Description: description,
Completed: completed,
}

ts.tasks[ts.nextID] = task
ts.nextID++

return task
}

// Update modifies an existing task
func (ts *TaskStore) Update(id int, title, description string, completed bool) (*Task, bool) {
ts.mu.Lock()
defer ts.mu.Unlock()

task, exists := ts.tasks[id]
if !exists {
return nil, false
}

task.Title = title
task.Description = description
task.Completed = completed

return task, true
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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Return snapshots instead of live *Task pointers.

GetAll, GetByID, and Update hand callers the store’s internal objects. That means JSON encoding happens outside the lock, so concurrent updates can race with reads, and GetAll also emits tasks in nondeterministic map order. Return copied values before releasing the mutex, and sort by ID if response order matters.

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