-
Notifications
You must be signed in to change notification settings - Fork 0
やりたいことボードのusecase層以下を実装 #31
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
base: feat/3/base
Are you sure you want to change the base?
Conversation
|
テストとかまだ作れてませんが、とりあえず実装までは済んだのでいったんレビューお願いします! |
akubi0w1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ざーっとコメントしましたー!何箇所か気になったところがあったので、みていただけると(ㅅ ;´꒳`;)
コード読みやすかったです、、、!(゚∀゚)
| GetWishBoard(ctx context.Context, wishBoardID int, authID string) (*wishboard.Entity, error) | ||
| UpdateTitle(ctx context.Context, wishBoardID int, title, authID string) error | ||
| UpdateBackgroundImage(ctx context.Context, wishBoardID int, backgroundImage []byte, authID string) error | ||
| DeleteWishBoard(ctx context.Context, wishBoardID int, authID string) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ただの気づきです。。。
interactor内のメソッドの引数、確かにauthIDのがいいかもな...!わたしuserIDで実装してたけど、userIDってよく考えたら取れないのか...!!( ゚д゚)
|
|
||
| func (i *interactor) CreateNewWishBoard(ctx context.Context, authID, title string, backgroundImage []byte) (*wishboard.Entity, error) { | ||
| // 空のタイトルは許容しない | ||
| if title == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感想ですー!
この辺のバリデーションなのだけど、項目増えていくと膨れ上がっていくから、関数として出しちゃってもいいかも。
公開にする必要はないだろうから、validateTitle(title string) errorくらいな感じで。
| GetByPK(ctx context.Context, masterTx repository.MasterTx, wishBoardID int) (*wishboard.Entity, error) | ||
| GetByOwner(ctx context.Context, masterTx repository.MasterTx, userID int) (wishboard.EntitySlice, error) | ||
| GetByMember(ctx context.Context, masterTx repository.MasterTx, userID int) (wishboard.EntitySlice, error) | ||
| UserBelongs(ctx context.Context, masterTx repository.MasterTx, userID, wishBoardID int) (bool, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感想です!
boolが返ってくるメソッドの名前は、IsXXXのが明確でいいかな、と思ったりなど。。。
IsUserBelongedとかかな...英語力...(ㅅ ;´꒳`;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど…
IsUserMemberでいこうかと思う!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
わざわざ主語書かなくてもいいだろうってことでIsMemberになりました!
|
|
||
| type Repository interface { | ||
| Insert(ctx context.Context, masterTx repository.MasterTx, userID, wishBoardID int) error | ||
| SelectByUserIDAndWishBoardID(ctx context.Context, masterTx repository.MasterTx, userID, wishBoardID int) (bool, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感想です〜
ここのメソッド、boolが返ってくるんで、名前がIsXXXの方が落ち着くかも
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかに変だよな〜
シンプルにExistsとかにしようかな
| return nil, werrors.FromConstant(err, werrors.ServerError) | ||
| } | ||
|
|
||
| bis := make([]int, 0, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの、3つめの引数の4って固定値、特に決まった値ってないはずなので、無理にmakeしなくていいかも!
rowsから件数取れんから、bis := []int{}でいいかなーと思う!
| } | ||
|
|
||
| // 現在時刻を取得 | ||
| now := time.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感想ですー
時刻の取得なんだけど、DBアクセス系の処理じゃないので、serviceとかでやった方がいいかも?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
了解!
| return nil, werrors.FromConstant(err, werrors.ServerError) | ||
| } | ||
|
|
||
| bs := make(wishboard.EntitySlice, 0, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの3つめの引数、固定値じゃない方がよいかもですー!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下、複数同じところがあるので、同じくって感じです!
| if err != nil { | ||
| if err == sql.ErrNoRows { | ||
| // 見つからなかったから空リストを返す | ||
| return []*wishboard.Entity{}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここのreturnで返すの、nil, nilで良いと思う!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そういえばgoの配列型ってnilでも空配列みたいな使い方できるんだっけ
了解、nilにしておく〜
| ErrorCode: http.StatusForbidden, | ||
| ErrorMessageJP: "ボードへのアクセスが許可されていません", | ||
| ErrorMessageEN: "you don't have access to wish_board", | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ナイス定義...!٩( 'ω' )و
|
修正しました! |
- insertとdeleteの引数をEntityに
TakumaKurosawa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いったんコメントしました!
| type Interactor interface { | ||
| CreateNewWishBoard(ctx context.Context, authID, title string, backgroundImage []byte) (*wishboard.Entity, error) | ||
| GetMyWishBoards(ctx context.Context, authID string) (wishboard.EntitySlice, error) | ||
| GetWishBoard(ctx context.Context, wishBoardID int, authID string) (*wishboard.Entity, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今回の実装では必要ないので消して欲しい!
| GetByPK(ctx context.Context, masterTx repository.MasterTx, wishBoardID int) (*wishboard.Entity, error) | ||
| GetByOwner(ctx context.Context, masterTx repository.MasterTx, userID int) (wishboard.EntitySlice, error) | ||
| GetByMember(ctx context.Context, masterTx repository.MasterTx, userID int) (wishboard.EntitySlice, error) | ||
| IsUserMember(ctx context.Context, masterTx repository.MasterTx, userID, wishBoardID int) (bool, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| IsUserMember(ctx context.Context, masterTx repository.MasterTx, userID, wishBoardID int) (bool, error) | |
| IsMember(ctx context.Context, masterTx repository.MasterTx, userID, wishBoardID int) (bool, error) |
| // 現在時刻を取得 | ||
| now := time.Now() | ||
|
|
||
| b := &wishboard.Entity{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bだとわかりづらいので、newBoardのように変数見ただけで何を表しているかわかるような名前にしてください!
他のところも同様!!
|
指摘のあった部分、修正しました! |
TakumaKurosawa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントした!
これが修正できたらまた見るのでレビュー依頼よろです!
| func validateTitle(ctx context.Context, title string) error { | ||
| if title == "" { | ||
| err := errors.New("title is empty") | ||
| tlog.PrintErrorLogWithCtx(ctx, err) | ||
| return werrors.FromConstant(err, werrors.BadRequest) | ||
| } | ||
|
|
||
| return nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これくらいの行数であれば、Privateメソッドに切り出す必要ないかなー。
バリデーションはその場で何をしているのか確認したかったりもするし、よっぽどメソッド切り分けしないイメージ。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはあくびとも話したんだけど、タイトルのバリデーション項目が増えたときのことを考えると
切り出した方がいいかな、って思った
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
了解!切り出さない方向で修正するね
| if err := validateTitle(ctx, title); err != nil { | ||
| return nil, werrors.Stack(err) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
privateメソッドに切り出さない方が良さそう。
| // TODO: 招待URLの自動生成 | ||
| inviteURL := "hoge" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uuidで自動生成するだけやと思うから、ここで実装しちゃっても良いかもね?w
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あと、実装する場合は、 wishBoardService.CreateInviteURLみたいにService層の実装として欲しい!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service層で実装する了解!
一応、仕様がはっきり決まるまでは実装しないでおく!
あと思ったんだけど、grpcで招待URLってどうやって使うんだろう…?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あと思ったんだけど、grpcで招待URLってどうやって使うんだろう…?
招待を受け付けるエンドポイントをRESTで用意してあげる必要があるね!
| row := tx.QueryRow(` | ||
| SELECT id FROM users_wish_boards WHERE user_id = ? AND wish_board_id = ? | ||
| `, userID, wishBoardID) | ||
|
|
||
| var i int | ||
| err = row.Scan(&i) | ||
| if err != nil { | ||
| if err == sql.ErrNoRows { | ||
| // 見つからなければfalseを返す | ||
| return false, nil | ||
| } | ||
| return false, werrors.FromConstant(err, werrors.ServerError) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
結局プログラムでやるのであれば、Service層で判定して欲しいかなー。
もしくは、関数名通り、MySQLのExists関数を使ってあげるかやなー。
https://qiita.com/mtanabe/items/5b8171a9d3ad9e559783
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existsなんてものがあったのね!
便利そうだから使う!
| return true, nil | ||
| } | ||
|
|
||
| func (r *repositoryImpliment) SelectByUserID(ctx context.Context, masterTx repository.MasterTx, userID int) ([]int, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SelectByUserIDという関数名から、 []intが返ってくるとは思わなくて驚きそうだから、再設計をしてみて!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目的語ちゃんと足しとくね
Issue
概要
やりたいことボード(WishBoard)のusecase層以下を実装
タスク整理