Skip to content

Commit 2491f4d

Browse files
committed
refactor: standardize variable naming and formatting across repositories
1 parent 93bf8e6 commit 2491f4d

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed

internal/db/command_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (r *CommandRepository) FindById(
150150
) (*command.Command, error) {
151151
var (
152152
commandID uuid.UUID
153-
dbDeviceID uuid.UUID
153+
dbDeviceID uuid.UUID
154154
commandName string
155155
payload []byte
156156
status string

internal/db/device_repository.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (r *DeviceRepository) FindById(
6969
) (*device.Device, error) {
7070
var (
7171
deviceID uuid.UUID
72-
dbUserID uuid.UUID
72+
uID uuid.UUID
7373
name string
7474
deviceType string
7575
status string
@@ -84,7 +84,7 @@ func (r *DeviceRepository) FindById(
8484
WHERE id = $1 AND user_id = $2
8585
`
8686

87-
err := r.db.QueryRow(ctx, query, id, dbUserID).Scan(
87+
err := r.db.QueryRow(ctx, query, id, uID).Scan(
8888
&deviceID,
8989
&userID,
9090
&name,
@@ -104,8 +104,8 @@ func (r *DeviceRepository) FindById(
104104
}
105105

106106
return device.RehydrateDevice(
107-
device.DeviceID(deviceID),
108-
user.UserID(userID),
107+
deviceID,
108+
uID,
109109
name,
110110
deviceType,
111111
status,
@@ -182,8 +182,8 @@ func (r *DeviceRepository) FindDevices(
182182
}
183183

184184
dev, err := device.RehydrateDevice(
185-
device.DeviceID(deviceID),
186-
user.UserID(uID),
185+
deviceID,
186+
uID,
187187
name,
188188
deviceType,
189189
status,

internal/db/user_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ func (r *UserRepository) FindByEmail(ctx context.Context, email user.Email) (*us
8787
return nil, fmt.Errorf("failed to find user: %w", err)
8888
}
8989

90-
return user.RehydrateUser(user.UserID(id), emailStr, usernameStr, passwordHash, createdAt, updatedAt)
90+
return user.RehydrateUser(id, emailStr, usernameStr, passwordHash, createdAt, updatedAt)
9191
}

internal/domain/command/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func (s *Service) ListDeviceCommands(
4141
}
4242

4343
func (s *Service) UpdateCommandStatus(
44-
ctx context.Context,
44+
ctx context.Context,
4545
id CommandID,
4646
deviceID device.DeviceID,
4747
status Status,
48-
executedAt ExecutedAt,
48+
executedAt ExecutedAt,
4949
) (*Command, error) {
5050
cmd, err := s.repo.FindById(ctx, id, deviceID)
5151
if err != nil {

internal/domain/device/device.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"time"
77

8+
"github.com/google/uuid"
89
"github.com/raphico/go-device-telemetry-api/internal/domain/user"
910
)
1011

@@ -52,8 +53,8 @@ func (d *Device) UpdateMetadata(m map[string]any) {
5253
}
5354

5455
func RehydrateDevice(
55-
id DeviceID,
56-
userID user.UserID,
56+
id uuid.UUID,
57+
userID uuid.UUID,
5758
name string,
5859
deviceType string,
5960
status string,
@@ -87,8 +88,8 @@ func RehydrateDevice(
8788
}
8889

8990
return &Device{
90-
ID: id,
91-
UserID: userID,
91+
ID: DeviceID(id),
92+
UserID: user.UserID(userID),
9293
Name: n,
9394
Status: s,
9495
DeviceType: dt,

internal/domain/user/user.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package user
33
import (
44
"fmt"
55
"time"
6+
7+
"github.com/google/uuid"
68
)
79

810
type User struct {
@@ -23,7 +25,7 @@ func NewUser(email Email, username Username, password Password) *User {
2325
}
2426

2527
func RehydrateUser(
26-
id UserID,
28+
id uuid.UUID,
2729
emailStr string,
2830
usernameStr string,
2931
passwordHash []byte,
@@ -39,7 +41,7 @@ func RehydrateUser(
3941
}
4042

4143
return &User{
42-
ID: id,
44+
ID: UserID(id),
4345
Email: e,
4446
Username: uname,
4547
Password: PasswordFromHash(passwordHash),

internal/http/command_handler.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ func (h *CommandHandler) HandleGetDeviceCommands(w http.ResponseWriter, r *http.
154154
WriteJSON(w, http.StatusOK, out, meta)
155155
}
156156

157-
158157
type updateCommandStatusRequest struct {
159-
Status string `json:"status"`
160-
ExecutedAt string `json:"executed_at"`
158+
Status string `json:"status"`
159+
ExecutedAt string `json:"executed_at"`
161160
}
162161

163162
func (h *CommandHandler) HandleUpdateCommandStatus(w http.ResponseWriter, r *http.Request) {
@@ -175,7 +174,6 @@ func (h *CommandHandler) HandleUpdateCommandStatus(w http.ResponseWriter, r *htt
175174
return
176175
}
177176

178-
179177
var req updateCommandStatusRequest
180178
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
181179
WriteJSONError(w, http.StatusBadRequest, invalidRequest, "Invalid request body")
@@ -187,7 +185,7 @@ func (h *CommandHandler) HandleUpdateCommandStatus(w http.ResponseWriter, r *htt
187185
WriteJSONError(w, http.StatusBadRequest, invalidRequest, err.Error())
188186
return
189187
}
190-
188+
191189
executedAt, err := command.NewExecutedAt(req.ExecutedAt)
192190
if err != nil {
193191
WriteJSONError(w, http.StatusBadRequest, invalidRequest, err.Error())

0 commit comments

Comments
 (0)