Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 096431b

Browse files
authored
Merge pull request #60 from mitsu-yuki/57-remove-errorドメインの削除
remove: delete error domain
2 parents 45ce198 + 692b5c0 commit 096431b

File tree

6 files changed

+31
-51
lines changed

6 files changed

+31
-51
lines changed

internal/domain/author/author.go

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

8-
errDomain "github.com/mitsu-yuki/shisho-backend/internal/domain/error"
98
"github.com/mitsu-yuki/shisho-backend/pkg/text"
109
"github.com/mitsu-yuki/shisho-backend/pkg/ulid"
1110
)
@@ -34,26 +33,26 @@ func newAuthor(
3433
) (*Author, error) {
3534
// 名前のバリデーション
3635
if utf8.RuneCountInString(name) < nameLengthMin {
37-
return nil, errDomain.NewError(fmt.Sprintf("著者名は%d文字以上である必要があります", nameLengthMin))
36+
return nil, fmt.Errorf("著者名は%d文字以上である必要があります", nameLengthMin)
3837
}
3938

4039
// 名前(読み)のバリデーション
4140
if utf8.RuneCountInString(namePhonic) < namePhonicLengthMin {
42-
return nil, errDomain.NewError(fmt.Sprintf("著者名読みは%d文字以上である必要があります", namePhonicLengthMin))
41+
return nil, fmt.Errorf("著者名読みは%d文字以上である必要があります", namePhonicLengthMin)
4342
}
4443

4544
if !text.IsKatakana(namePhonic) {
46-
return nil, errDomain.NewError("著者名読みはカタカナである必要があります")
45+
return nil, fmt.Errorf("著者名読みはカタカナである必要があります")
4746
}
4847

4948
// 日付のバリデーション(lastUpdateAtのほうが後か)
5049
if lastUpdateAt.Before(createAt) {
51-
return nil, errDomain.NewError("更新日は作成日よりも後である必要があります")
50+
return nil, fmt.Errorf("更新日は作成日よりも後である必要があります")
5251
}
5352

5453
// 削除フラグが立ってない もしくは 削除日は作成日よりも後であるか
5554
if deletedAt != nil && deletedAt.Before(createAt) {
56-
return nil, errDomain.NewError("削除日は作成日よりも後である必要があります")
55+
return nil, fmt.Errorf("削除日は作成日よりも後である必要があります")
5756
}
5857

5958
return &Author{

internal/domain/book/book.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66
"unicode/utf8"
77

8-
errDomain "github.com/mitsu-yuki/shisho-backend/internal/domain/error"
98
"github.com/mitsu-yuki/shisho-backend/pkg/checkdigit"
109
"github.com/mitsu-yuki/shisho-backend/pkg/ulid"
1110
)
@@ -49,46 +48,46 @@ func newBook(
4948
) (*Book, error) {
5049
// ISBNがある場合には有効なISBNか調べる
5150
if isbn != nil && !checkdigit.ISBN13IsValid(*isbn) {
52-
return nil, errDomain.NewError("ISBNが不正です")
51+
return nil, fmt.Errorf("ISBNが不正です")
5352
}
5453

5554
// レーベルIDのバリデーション
5655
if !ulid.IsValid(labelID) {
57-
return nil, errDomain.NewError("レーベルIDが不正です")
56+
return nil, fmt.Errorf("レーベルIDが不正です")
5857
}
5958

6059
// 出版社IDのバリデーション
6160
if !ulid.IsValid(publishID) {
62-
return nil, errDomain.NewError("出版社IDが不正です")
61+
return nil, fmt.Errorf("出版社IDが不正です")
6362
}
6463

6564
// タイトルのバリデーション
6665
if utf8.RuneCountInString(title) < titleLengthMin {
67-
return nil, errDomain.NewError(fmt.Sprintf("タイトル名は%d文字以上である必要があります", titleLengthMin))
66+
return nil, fmt.Errorf("タイトル名は%d文字以上である必要があります", titleLengthMin)
6867
}
6968

7069
// 著者リストIDのバリデーション
7170
if len(authorIDs) < bookAuthorsLengthMin {
72-
return nil, errDomain.NewError(fmt.Sprintf("著者は%d人以上である必要があります", bookAuthorsLengthMin))
71+
return nil, fmt.Errorf("著者は%d人以上である必要があります", bookAuthorsLengthMin)
7372
}
7473

7574
// 発売日のバリデーション
7675
if releaseDay.IsZero() {
77-
return nil, errDomain.NewError("発売日はゼロ値以外である必要があります")
76+
return nil, fmt.Errorf("発売日はゼロ値以外である必要があります")
7877
}
7978

8079
// 金額のバリデーション
8180
if price < priceMin {
82-
return nil, errDomain.NewError(fmt.Sprintf("金額は%d円以上である必要があります", priceMin))
81+
return nil, fmt.Errorf("金額は%d円以上である必要があります", priceMin)
8382
}
8483
// 日付のバリデーション(lastUpdateAtのほうが後か)
8584
if lastUpdateAt.Before(createAt) {
86-
return nil, errDomain.NewError("更新日は作成日よりも後である必要があります")
85+
return nil, fmt.Errorf("更新日は作成日よりも後である必要があります")
8786
}
8887

8988
// 削除フラグが立ってない もしくは 削除日は作成日よりも後であるか
9089
if deletedAt != nil && deletedAt.Before(createAt) {
91-
return nil, errDomain.NewError("削除日は作成日よりも後である必要があります")
90+
return nil, fmt.Errorf("削除日は作成日よりも後である必要があります")
9291
}
9392
return &Book{
9493
id: id,

internal/domain/error/error.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

internal/domain/label/label.go

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

8-
errDomain "github.com/mitsu-yuki/shisho-backend/internal/domain/error"
98
"github.com/mitsu-yuki/shisho-backend/pkg/text"
109
"github.com/mitsu-yuki/shisho-backend/pkg/ulid"
1110
)
@@ -34,31 +33,31 @@ func newLabel(
3433
) (*Label, error) {
3534
// IDのバリデーション
3635
if !ulid.IsValid(id) {
37-
return nil, errDomain.NewError("レーベルIDが不正です")
36+
return nil, fmt.Errorf("レーベルIDが不正です")
3837
}
3938

4039
// レーベル名のバリデーション
4140
if utf8.RuneCountInString(name) < nameLengthMin {
42-
return nil, errDomain.NewError(fmt.Sprintf("レーベル名は%d文字以上である必要があります", nameLengthMin))
41+
return nil, fmt.Errorf("レーベル名は%d文字以上である必要があります", nameLengthMin)
4342
}
4443

4544
// レーベル名(読み)のバリデーション
4645
if utf8.RuneCountInString(namePhonic) < namePhonicLengthMin {
47-
return nil, errDomain.NewError(fmt.Sprintf("レーベル名読みは%d文字以上である必要があります", namePhonicLengthMin))
46+
return nil, fmt.Errorf("レーベル名読みは%d文字以上である必要があります", namePhonicLengthMin)
4847
}
4948

5049
if !text.IsKatakana(namePhonic) {
51-
return nil, errDomain.NewError("レーベル名読みはカタカナである必要があります")
50+
return nil, fmt.Errorf("レーベル名読みはカタカナである必要があります")
5251
}
5352

5453
// 日付のバリデーション(lastUpdateAtのほうが後か)
5554
if lastUpdateAt.Before(createAt) {
56-
return nil, errDomain.NewError("更新日は作成日よりも後である必要があります")
55+
return nil, fmt.Errorf("更新日は作成日よりも後である必要があります")
5756
}
5857

5958
// 削除フラグが立ってない もしくは 削除日は作成日よりも後であるか
6059
if deletedAt != nil && deletedAt.Before(createAt) {
61-
return nil, errDomain.NewError("削除日は作成日よりも後である必要があります")
60+
return nil, fmt.Errorf("削除日は作成日よりも後である必要があります")
6261
}
6362

6463
return &Label{

internal/domain/publish/publish.go

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

8-
errDomain "github.com/mitsu-yuki/shisho-backend/internal/domain/error"
98
"github.com/mitsu-yuki/shisho-backend/pkg/text"
109
"github.com/mitsu-yuki/shisho-backend/pkg/ulid"
1110
)
@@ -34,26 +33,26 @@ func newPublish(
3433
) (*Publish, error) {
3534
// 名前のバリデーション
3635
if utf8.RuneCountInString(name) < nameLengthMin {
37-
return nil, errDomain.NewError(fmt.Sprintf("出版社名は%d文字以上である必要があります", nameLengthMin))
36+
return nil, fmt.Errorf("出版社名は%d文字以上である必要があります", nameLengthMin)
3837
}
3938

4039
// 名前(読み)のバリデーション
4140
if utf8.RuneCountInString(namePhonic) < namePhonicLengthMin {
42-
return nil, errDomain.NewError(fmt.Sprintf("出版社名読みは%d文字以上である必要があります", namePhonicLengthMin))
41+
return nil, fmt.Errorf("出版社名読みは%d文字以上である必要があります", namePhonicLengthMin)
4342
}
4443

4544
if !text.IsKatakana(namePhonic) {
46-
return nil, errDomain.NewError("出版社名読みはカタカナである必要があります")
45+
return nil, fmt.Errorf("出版社名読みはカタカナである必要があります")
4746
}
4847

4948
// 日付のバリデーション(lastUpdateAtのほうが後か)
5049
if lastUpdateAt.Before(createAt) {
51-
return nil, errDomain.NewError("更新日は作成日よりも後である必要があります")
50+
return nil, fmt.Errorf("更新日は作成日よりも後である必要があります")
5251
}
5352

5453
// 削除フラグが立ってない もしくは 削除日は作成日よりも後であるか
5554
if deletedAt != nil && deletedAt.Before(createAt) {
56-
return nil, errDomain.NewError("削除日は作成日よりも後である必要があります")
55+
return nil, fmt.Errorf("削除日は作成日よりも後である必要があります")
5756
}
5857
return &Publish{
5958
id: id,

internal/domain/series/series.go

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

8-
errDomain "github.com/mitsu-yuki/shisho-backend/internal/domain/error"
98
"github.com/mitsu-yuki/shisho-backend/pkg/ulid"
109
)
1110

@@ -35,32 +34,32 @@ func newSeries(
3534
) (*Series, error) {
3635
// シリーズIDのバリデーション
3736
if !ulid.IsValid(id) {
38-
return nil, errDomain.NewError("シリーズIDが不正です")
37+
return nil, fmt.Errorf("シリーズIDが不正です")
3938
}
4039

4140
// シリーズ名のバリデーション
4241
if utf8.RuneCountInString(name) < seriesNameLengthMin {
43-
return nil, errDomain.NewError(fmt.Sprintf("タイトル名は%d文字以上である必要があります", seriesNameLengthMin))
42+
return nil, fmt.Errorf("タイトル名は%d文字以上である必要があります", seriesNameLengthMin)
4443
}
4544

4645
// シリーズが内包する作品数のバリデーション
4746
if len(books) < seriesBooksLengthMin {
48-
return nil, errDomain.NewError(fmt.Sprintf("シリーズ作品は%d作品以上である必要があります", seriesBooksLengthMin))
47+
return nil, fmt.Errorf("シリーズ作品は%d作品以上である必要があります", seriesBooksLengthMin)
4948
}
5049

5150
// ステータスのバリデーション
5251
if !ulid.IsValid(statusID) {
53-
return nil, errDomain.NewError("ステータスIDが不正です")
52+
return nil, fmt.Errorf("ステータスIDが不正です")
5453
}
5554

5655
// 日付のバリデーション(lastUpdateAtのほうが後か)
5756
if lastUpdateAt.Before(createAt) {
58-
return nil, errDomain.NewError("更新日は作成日よりも後である必要があります")
57+
return nil, fmt.Errorf("更新日は作成日よりも後である必要があります")
5958
}
6059

6160
// 削除フラグが立ってない もしくは 削除日は作成日よりも後であるか
6261
if deletedAt != nil && deletedAt.Before(createAt) {
63-
return nil, errDomain.NewError("削除日は作成日よりも後である必要があります")
62+
return nil, fmt.Errorf("削除日は作成日よりも後である必要があります")
6463
}
6564
return &Series{
6665
id: id,

0 commit comments

Comments
 (0)