Skip to content

Commit 38e81c9

Browse files
hatappiclaude
andauthored
Add phaseDurationSec field to GraphQL schema and models (#288)
- Add phaseDurationSec field to Pomodoro and EventPomodoroPayload types - Update core models to include PhaseDuration field for accurate phase timing - Implement resolvers to return original phase duration instead of calculated values - Update event system to propagate phase duration information - Regenerate GraphQL code and models 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 8e6a24a commit 38e81c9

File tree

10 files changed

+153
-8
lines changed

10 files changed

+153
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/go-chi/chi/v5 v5.2.1
1212
github.com/go-playground/validator/v10 v10.23.0
1313
github.com/golangci/golangci-lint v1.63.4
14-
github.com/google/go-cmp v0.6.0
1514
github.com/google/uuid v1.6.0
1615
github.com/gorilla/websocket v1.5.3
1716
github.com/hatappi/go-kit v0.0.14
@@ -101,6 +100,7 @@ require (
101100
github.com/golangci/plugin-module-register v0.1.1 // indirect
102101
github.com/golangci/revgrep v0.5.3 // indirect
103102
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
103+
github.com/google/go-cmp v0.6.0 // indirect
104104
github.com/gordonklaus/ineffassign v0.1.0 // indirect
105105
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
106106
github.com/gostaticanalysis/comment v1.4.2 // indirect

internal/core/event/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type PomodoroEvent struct {
7979
TaskID string `json:"task_id,omitempty"`
8080
Phase PomodoroPhase `json:"phase"`
8181
PhaseCount int `json:"phase_count"`
82+
PhaseDuration time.Duration `json:"phase_duration"`
8283
}
8384

8485
// GetEventType returns the event type.

internal/core/pomodoro.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Pomodoro struct {
2626
ElapsedTime time.Duration `json:"elapsed_time"`
2727
Phase event.PomodoroPhase `json:"phase"`
2828
PhaseCount int `json:"phase_count"`
29+
PhaseDuration time.Duration `json:"phase_duration"`
2930
TaskID string `json:"task_id,omitempty"`
3031
}
3132

@@ -70,6 +71,16 @@ func (s *PomodoroService) Start(
7071
longBreakDuration,
7172
)
7273

74+
var phaseDuration time.Duration
75+
switch phase {
76+
case storage.PomodoroPhaseLongBreak:
77+
phaseDuration = longBreakDuration
78+
case storage.PomodoroPhaseShortBreak:
79+
phaseDuration = breakDuration
80+
default:
81+
phaseDuration = workDuration
82+
}
83+
7384
pomodoro := &storage.Pomodoro{
7485
ID: uuid.New().String(),
7586
State: storage.PomodoroStateActive,
@@ -79,6 +90,7 @@ func (s *PomodoroService) Start(
7990
LongBreakDuration: longBreakDuration,
8091
RemainingTime: duration,
8192
Phase: phase,
93+
PhaseDuration: phaseDuration,
8294
PhaseCount: phaseCount,
8395
TaskID: taskID,
8496
}
@@ -300,6 +312,7 @@ func (s *PomodoroService) publishPomodoroEvent(eventType event.EventType, p *sto
300312
TaskID: p.TaskID,
301313
Phase: event.PomodoroPhase(p.Phase),
302314
PhaseCount: p.PhaseCount,
315+
PhaseDuration: p.PhaseDuration,
303316
}
304317

305318
s.eventBus.Publish(e)
@@ -320,6 +333,7 @@ func (s *PomodoroService) storagePomodoroToCore(p *storage.Pomodoro) *Pomodoro {
320333
RemainingTime: p.RemainingTime,
321334
ElapsedTime: p.ElapsedTime,
322335
Phase: event.PomodoroPhase(p.Phase),
336+
PhaseDuration: p.PhaseDuration,
323337
PhaseCount: p.PhaseCount,
324338
TaskID: p.TaskID,
325339
}

internal/graph/conv/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func ConvertPomodoroEventToModelEvent(evt event.PomodoroEvent) (*model.Event, er
5252
TaskID: &evt.TaskID,
5353
Phase: phase,
5454
PhaseCount: evt.PhaseCount,
55+
PhaseDurationSec: int(evt.PhaseDuration.Seconds()),
5556
}
5657

5758
return &model.Event{

internal/graph/conv/pomodoro.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ func FromPomodoro(pomodoro *core.Pomodoro) (*model.Pomodoro, error) {
2323
}
2424

2525
return &model.Pomodoro{
26-
ID: pomodoro.ID,
27-
State: state,
28-
TaskID: pomodoro.TaskID,
29-
StartTime: pomodoro.StartTime,
30-
Phase: phase,
31-
32-
PhaseCount: pomodoro.PhaseCount,
26+
ID: pomodoro.ID,
27+
State: state,
28+
TaskID: pomodoro.TaskID,
29+
StartTime: pomodoro.StartTime,
30+
Phase: phase,
31+
PhaseCount: pomodoro.PhaseCount,
3332
RemainingTimeSec: int(pomodoro.RemainingTime.Seconds()),
3433
ElapsedTimeSec: int(pomodoro.ElapsedTime.Seconds()),
34+
PhaseDurationSec: int(pomodoro.PhaseDuration.Seconds()),
3535
}, nil
3636
}

internal/graph/generated.go

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graph/model/models_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graph/schema/event.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type EventPomodoroPayload {
3737
taskId: ID
3838
phase: PomodoroPhase!
3939
phaseCount: Int!
40+
phaseDurationSec: Int!
4041
}
4142

4243
type EventTaskPayload {

internal/graph/schema/pomodoro.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Pomodoro {
77
phaseCount: Int!
88
remainingTimeSec: Int!
99
elapsedTimeSec: Int!
10+
phaseDurationSec: Int!
1011
}
1112

1213
input StartPomodoroInput {

internal/storage/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Pomodoro struct {
4040
RemainingTime time.Duration `json:"remaining_time"`
4141
ElapsedTime time.Duration `json:"elapsed_time"`
4242
Phase PomodoroPhase `json:"phase"`
43+
PhaseDuration time.Duration `json:"phase_duration"`
4344
PhaseCount int `json:"phase_count"`
4445
TaskID string `json:"task_id,omitempty"`
4546
}

0 commit comments

Comments
 (0)