Skip to content

/comments エンドポイントの実装#49

Draft
yas-ako wants to merge 8 commits intofix/architecturefrom
feat/post-comment
Draft

/comments エンドポイントの実装#49
yas-ako wants to merge 8 commits intofix/architecturefrom
feat/post-comment

Conversation

@yas-ako
Copy link
Copy Markdown
Member

@yas-ako yas-ako commented Feb 8, 2026

close #44

  • まだ途中です

進捗

  • domainの実装は完了
  • Repositoryの実装は完了
  • usecaseの実装の途中
  • handlerはまだ

聞きたいこと

openapiの定義によれば、/comment エンドポイントにリクエストがあったとき、それが存在しないItemだった際は 404 エラーを返すことになっています。これを usecase/comment で実装しようとしたのですが、どのように実装すればいいのかがあまりよくわかっていないです。usecase/comment.goに次のように書いて依存先を追加する感じで良いのでしょうか?

type commentUseCase struct {
    CommentRepository domain.CommentRepository
    ItemRepository domain.ItemRepository // ← この行を追加する
}

そのうえで、

func NewCommentUseCase(commentRepository domain.CommentRepository, itemRepository domain.ItemRepository) CommentUseCase {
    return &commentUseCase{
        commentRepository: commentRepository,
        itemRepository:    itemRepository,
    }
}
func (u *commentUseCase) CreateComment(itemId int, userId string, text string) (*domain.Comment, error) {
    _, err := u.itemRepo.GetByID(itemId)
    // 省略
}

とする感じでしょうか?
書いたコードをまだ一度も実行していないため、正しく動くかはわかっていません。

@yas-ako yas-ako requested a review from kavos113 February 8, 2026 16:51
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 8, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/post-comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yas-ako yas-ako marked this pull request as draft February 8, 2026 16:52
@kavos113
Copy link
Copy Markdown
Contributor

kavos113 commented Feb 9, 2026

実装ありがとうございます。方針はとてもよいと思います!

質問については,その通りでusecaseにItemRepositoryの依存を加える形で実装を進めてください。
usecaseやhandlerはそれぞれ1つのrepo/usecaseに依存するのではなく,必要に応じて複数のrepo/usecaseに依存します。

go clean architecture などで調べると参考になりそうなコードが出てくるかもしれないので余裕があったら調べてみてください。

@yas-ako yas-ako force-pushed the feat/post-comment branch from 4f9e8d2 to 1b54b75 Compare March 3, 2026 04:20
@yas-ako yas-ako changed the base branch from fix/architecture to main March 3, 2026 04:46
@yas-ako yas-ako changed the base branch from main to fix/architecture March 3, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants