Skip to content

Commit 9db363d

Browse files
committed
refactor: make NoteSlugDTO type as string alias
1 parent bcf5056 commit 9db363d

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

internal/dtos/note.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"github.com/gofrs/uuid/v5"
77
)
88

9-
type NoteSlugDTO string
10-
11-
func (n NoteSlugDTO) String() string { return string(n) }
9+
type NoteSlugDTO = string
1210

1311
type NoteDTO struct {
1412
Content string

internal/service/notesrv/notesrv.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func (n *NoteSrv) Create(
4444
}
4545

4646
if !userID.IsNil() {
47-
if err := n.noterepo.SetAuthorIDBySlug(ctx, dtos.NoteSlugDTO(inp.Slug), userID); err != nil {
47+
if err := n.noterepo.SetAuthorIDBySlug(ctx, inp.Slug, userID); err != nil {
4848
return "", err
4949
}
5050
}
5151

52-
return dtos.NoteSlugDTO(inp.Slug), nil
52+
return inp.Slug, nil
5353
}
5454

5555
func (n *NoteSrv) GetBySlugAndRemoveIfNeeded(
@@ -79,5 +79,5 @@ func (n *NoteSrv) GetBySlugAndRemoveIfNeeded(
7979

8080
// TODO: in future not remove, leave some metadata
8181
// to shot user that note was alreasy seen
82-
return note, n.noterepo.DeleteBySlug(ctx, dtos.NoteSlugDTO(note.Slug))
82+
return note, n.noterepo.DeleteBySlug(ctx, note.Slug)
8383
}

internal/store/psql/noterepo/noterepo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (s *NoteRepo) SetAuthorIDBySlug(
9898
defer tx.Rollback(ctx) //nolint:errcheck
9999

100100
var noteID uuid.UUID
101-
err = tx.QueryRow(ctx, "select id from notes where slug = $1", slug.String()).Scan(&noteID)
101+
err = tx.QueryRow(ctx, "select id from notes where slug = $1", slug).Scan(&noteID)
102102
if err != nil {
103103
if errors.Is(err, pgx.ErrNoRows) {
104104
return models.ErrNoteNotFound

internal/transport/http/apiv1/note.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (a *APIV1) createNoteHandler(c *gin.Context) {
5353
return
5454
}
5555

56-
c.JSON(http.StatusCreated, createNoteResponse{slug.String()})
56+
c.JSON(http.StatusCreated, createNoteResponse{slug})
5757
}
5858

5959
type getNoteBySlugResponse struct {
@@ -64,7 +64,7 @@ type getNoteBySlugResponse struct {
6464

6565
func (a *APIV1) getNoteBySlugHandler(c *gin.Context) {
6666
slug := c.Param("slug")
67-
note, err := a.notesrv.GetBySlugAndRemoveIfNeeded(c.Request.Context(), dtos.NoteSlugDTO(slug))
67+
note, err := a.notesrv.GetBySlugAndRemoveIfNeeded(c.Request.Context(), slug)
6868
if err != nil {
6969
errorResponse(c, err)
7070
return

0 commit comments

Comments
 (0)