feat(tag): make private things private

This commit is contained in:
2026-01-07 09:17:15 +01:00
parent f1e0c1c1c2
commit 5af5ab2a0c
3 changed files with 33 additions and 33 deletions

View File

@@ -10,11 +10,11 @@ import (
)
type Db interface {
Insert(ctx context.Context, tag Tag) (*Tag, error)
Update(ctx context.Context, tag Tag) (*Tag, error)
Delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) error
Get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Tag, error)
GetAll(ctx context.Context, userId uuid.UUID) ([]Tag, error)
insert(ctx context.Context, tag Tag) (*Tag, error)
update(ctx context.Context, tag Tag) (*Tag, error)
delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) error
get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Tag, error)
getAll(ctx context.Context, userId uuid.UUID) ([]Tag, error)
}
type DbSqlite struct {
@@ -25,7 +25,7 @@ func NewDbSqlite(db *sqlx.DB) *DbSqlite {
return &DbSqlite{db: db}
}
func (db DbSqlite) Insert(ctx context.Context, tag Tag) (*Tag, error) {
func (db DbSqlite) insert(ctx context.Context, tag Tag) (*Tag, error) {
r, err := db.db.ExecContext(ctx, `
INSERT INTO tag (id, user_id, name, created_at, created_by, updated_at, updated_by)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
@@ -36,10 +36,10 @@ func (db DbSqlite) Insert(ctx context.Context, tag Tag) (*Tag, error) {
return nil, core.ErrInternal
}
return db.Get(ctx, tag.UserId, tag.Id)
return db.get(ctx, tag.UserId, tag.Id)
}
func (db DbSqlite) Update(ctx context.Context, tag Tag) (*Tag, error) {
func (db DbSqlite) update(ctx context.Context, tag Tag) (*Tag, error) {
_, err := db.db.ExecContext(ctx, `
UPDATE tag
SET name = ?,
@@ -54,10 +54,10 @@ func (db DbSqlite) Update(ctx context.Context, tag Tag) (*Tag, error) {
return nil, core.ErrInternal
}
return db.Get(ctx, tag.UserId, tag.Id)
return db.get(ctx, tag.UserId, tag.Id)
}
func (db DbSqlite) Delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) error {
func (db DbSqlite) delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) error {
r, err := db.db.ExecContext(
ctx,
"DELETE FROM tag WHERE user_id = ? AND id = ?",
@@ -71,7 +71,7 @@ func (db DbSqlite) Delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) e
return nil
}
func (db DbSqlite) Get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Tag, error) {
func (db DbSqlite) get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Tag, error) {
var tag Tag
err := db.db.Get(&tag, "SELECT * FROM tag WHERE id = ? AND user_id = ?", id, userId)
@@ -83,7 +83,7 @@ func (db DbSqlite) Get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Ta
return &tag, nil
}
func (db DbSqlite) GetAll(ctx context.Context, userId uuid.UUID) ([]Tag, error) {
func (db DbSqlite) getAll(ctx context.Context, userId uuid.UUID) ([]Tag, error) {
var tags []Tag
err := db.db.Select(&tags, "SELECT * FROM tag WHERE user_id = ?", userId)

View File

@@ -46,7 +46,7 @@ func (h HandlerImpl) handlePage() http.HandlerFunc {
return
}
tags, err := h.s.GetAll(r.Context(), user)
tags, err := h.s.getAll(r.Context(), user)
if err != nil {
h.r.RenderLayout(r, w, core.ErrorComp(err), user)
return
@@ -88,7 +88,7 @@ func (h HandlerImpl) handleEdit() http.HandlerFunc {
return
}
tag, err := h.s.Get(r.Context(), user, id)
tag, err := h.s.get(r.Context(), user, id)
if err != nil {
core.HandleError(w, r, fmt.Errorf("could not parse Id: %w", core.ErrBadRequest))
return
@@ -134,13 +134,13 @@ func (h HandlerImpl) handlePost() http.HandlerFunc {
}
if idStr == "new" {
_, err = h.s.Add(r.Context(), user, input)
_, err = h.s.add(r.Context(), user, input)
if err != nil {
core.HandleError(w, r, err)
return
}
} else {
_, err = h.s.Update(r.Context(), user, input)
_, err = h.s.update(r.Context(), user, input)
if err != nil {
core.HandleError(w, r, err)
return
@@ -168,7 +168,7 @@ func (h HandlerImpl) handleDelete() http.HandlerFunc {
return
}
err = h.s.Delete(r.Context(), user, id)
err = h.s.delete(r.Context(), user, id)
if err != nil {
core.HandleError(w, r, err)
return

View File

@@ -9,11 +9,11 @@ import (
)
type Service interface {
Add(ctx context.Context, user *auth_types.User, tag Tag) (*Tag, error)
Update(ctx context.Context, user *auth_types.User, tag Tag) (*Tag, error)
Delete(ctx context.Context, user *auth_types.User, tagId uuid.UUID) error
Get(ctx context.Context, user *auth_types.User, tagId uuid.UUID) (*Tag, error)
GetAll(ctx context.Context, user *auth_types.User) ([]Tag, error)
add(ctx context.Context, user *auth_types.User, tag Tag) (*Tag, error)
update(ctx context.Context, user *auth_types.User, tag Tag) (*Tag, error)
delete(ctx context.Context, user *auth_types.User, tagId uuid.UUID) error
get(ctx context.Context, user *auth_types.User, tagId uuid.UUID) (*Tag, error)
getAll(ctx context.Context, user *auth_types.User) ([]Tag, error)
}
type ServiceImpl struct {
@@ -30,7 +30,7 @@ func NewService(db Db, random core.Random, clock core.Clock) Service {
}
}
func (s ServiceImpl) Add(ctx context.Context, user *auth_types.User, tag Tag) (*Tag, error) {
func (s ServiceImpl) add(ctx context.Context, user *auth_types.User, tag Tag) (*Tag, error) {
if user == nil {
return nil, core.ErrUnauthorized
}
@@ -50,15 +50,15 @@ func (s ServiceImpl) Add(ctx context.Context, user *auth_types.User, tag Tag) (*
tag.CreatedBy = user.Id
tag.CreatedAt = s.clock.Now()
return s.db.Insert(ctx, tag)
return s.db.insert(ctx, tag)
}
func (s ServiceImpl) Update(ctx context.Context, user *auth_types.User, input Tag) (*Tag, error) {
func (s ServiceImpl) update(ctx context.Context, user *auth_types.User, input Tag) (*Tag, error) {
if user == nil {
return nil, core.ErrUnauthorized
}
tag, err := s.Get(ctx, user, input.Id)
tag, err := s.get(ctx, user, input.Id)
if err != nil {
return nil, err
}
@@ -78,31 +78,31 @@ func (s ServiceImpl) Update(ctx context.Context, user *auth_types.User, input Ta
now := s.clock.Now()
tag.UpdatedAt = &now
return s.db.Update(ctx, *tag)
return s.db.update(ctx, *tag)
}
func (s ServiceImpl) Delete(ctx context.Context, user *auth_types.User, tagId uuid.UUID) error {
func (s ServiceImpl) delete(ctx context.Context, user *auth_types.User, tagId uuid.UUID) error {
if user == nil {
return core.ErrUnauthorized
}
return s.db.Delete(ctx, user.Id, tagId)
return s.db.delete(ctx, user.Id, tagId)
}
func (s ServiceImpl) Get(ctx context.Context, user *auth_types.User, tagId uuid.UUID) (*Tag, error) {
func (s ServiceImpl) get(ctx context.Context, user *auth_types.User, tagId uuid.UUID) (*Tag, error) {
if user == nil {
return nil, core.ErrUnauthorized
}
return s.db.Get(ctx, user.Id, tagId)
return s.db.get(ctx, user.Id, tagId)
}
func (s ServiceImpl) GetAll(ctx context.Context, user *auth_types.User) ([]Tag, error) {
func (s ServiceImpl) getAll(ctx context.Context, user *auth_types.User) ([]Tag, error) {
if user == nil {
return nil, core.ErrUnauthorized
}
return s.db.GetAll(ctx, user.Id)
return s.db.getAll(ctx, user.Id)
}
func (s ServiceImpl) isTagValid(tag Tag) bool {