Add solution for fiber challenge-1-basic-routing by mutantkeyboard#1648
Conversation
WalkthroughA new submission file implements a thread-safe, in-memory task management API using Fiber. It provides a ChangesTask Management API Implementation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7a21a81e-7981-4f4a-acf2-c968167f1b8f
📒 Files selected for processing (1)
packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.go
| id, err := strconv.Atoi(c.Params("id")) | ||
| if err != nil{ | ||
| return err | ||
| } |
There was a problem hiding this comment.
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.
| // 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 |
There was a problem hiding this comment.
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.
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
packages/fiber/challenge-1-basic-routing/submissions/mutantkeyboard/solution.goTesting
Thank you for reviewing my submission! 🚀