Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] DBエラーメッセージ露出を防止 #135

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/infrastructure/userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"backend/app/domain/repository"

"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
)

type userinfoRepositoryImpl struct {
Expand All @@ -28,7 +29,7 @@ func (ur *userinfoRepositoryImpl) SelectUserinfoByUserID(userID string) (*entity
"WHERE UP.user_id = ? LIMIT 1;",
userID)
if err != nil {
return nil, err
return nil, errors.New("failed to retrieve user profile")
}
}

Expand All @@ -44,7 +45,7 @@ func (ur *userinfoRepositoryImpl) SelectUserinfoByUserID(userID string) (*entity
"WHERE user_id = ?;",
userID)
if err != nil {
return nil, err
return nil, errors.New("failed to retrieve joined groups")
}
}

Expand All @@ -56,7 +57,7 @@ func (ur *userinfoRepositoryImpl) SelectUserinfoByUserID(userID string) (*entity
"SELECT skill_name, user_id FROM skills WHERE user_id = ?;",
userID)
if err != nil {
return nil, err
return nil, errors.New("failed to retrieve skills")
}
}

Expand All @@ -68,7 +69,7 @@ func (ur *userinfoRepositoryImpl) SelectUserinfoByUserID(userID string) (*entity
"SELECT user_id, sns FROM sns WHERE user_id = ?;",
userID)
if err != nil {
return nil, err
return nil, errors.New("failed to retrieve sns")
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/interfaces/handler/userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (h *UserinfoHandler) GetUserinfo(w http.ResponseWriter, r *http.Request) {
userinfo, works, err := h.userinfoUseCase.GetUserinfo(userID)
if err != nil {
log.Println(err)
_ = response.ReturnErrorResponse(w, http.StatusBadRequest, err.Error())
http.Error(w, "Failed to fetch user information", http.StatusInternalServerError)
return
}

Expand Down
9 changes: 5 additions & 4 deletions app/usecase/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package usecase
import (
"backend/app/domain/entity"
"backend/app/domain/repository"
"errors"
)

type WorkUseCase struct {
Expand Down Expand Up @@ -58,14 +59,14 @@ func (w *WorkUseCase) ReadWorks(numberOfWorks uint, tag string) (*[]*entity.Read
if len(tag) == 0 {
works, err := w.workRepository.SelectWorks(numberOfWorks)
if err != nil {
return &[]*entity.ReadWorksList{}, err
return &[]*entity.ReadWorksList{}, errors.New("failed to retrieve works")
}

return works, nil
} else {
works, err := w.workRepository.SelectWorksByTag(numberOfWorks, tag)
if err != nil {
return &[]*entity.ReadWorksList{}, err
return &[]*entity.ReadWorksList{}, errors.New("failed to retrieve works by tag")
}

return works, nil
Expand All @@ -75,12 +76,12 @@ func (w *WorkUseCase) ReadWorks(numberOfWorks uint, tag string) (*[]*entity.Read
func (w *WorkUseCase) ReadWork(workID string) (*entity.ReadWork, *entity.User, error) {
work, err := w.workRepository.SelectWork(workID)
if err != nil {
return nil, nil, err
return nil, nil, errors.New("failed to retrieve work")
}

user, err := w.workRepository.SelectWorkUser(work.UserId)
if err != nil {
return nil, nil, err
return nil, nil, errors.New("failed to retrieve work user")
}

return work, user, nil
Expand Down
5 changes: 3 additions & 2 deletions db/migration/sql/20240701062632_create_comments_table.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ CREATE TABLE `comment` (
`id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'コメントID',
`user_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'ユーザーID',
`works_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '作品ID',
`text` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '本文',
`content` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '本文',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '作成日時',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新日時',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
CONSTRAINT `fk_comment_works` FOREIGN KEY (`works_id`) REFERENCES `works` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;