-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/wakape/user groups put api #1100
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
95d49e3
feat:user_groupsようにopenapiを編集、make genの実行
Wakai111 f612019
feat:user_group用のapiとしてのリポジトリとユースケースの作成
Wakai111 f49af36
feat:user_groups用のapiとしてのハンドラー実装、wire_gen実行
Wakai111 37931e8
feat:user_groups用のapiの年度管理対応
Wakai111 9c07fec
feat:user_groups用のapiの関数名、変数名修正
Wakai111 6da8a54
fix : user_groups用のapiの変数名の微修正
Wakai111 2ff6d63
fix : レスポンス返却時の不要なDB取得クエリを削除、リクエスト配列の重複排除処理追加
Wakai111 09559f8
fix : group_user用のapiの変数名修正
Wakai111 2df3d6e
feat: 所属グループ更新APIにuserIDとyearの存在確認、および不正リクエスト防止を追加
Wakai111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package repository | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
|
|
||
| "github.com/NUTFes/FinanSu/api/drivers/db" | ||
| "github.com/NUTFes/FinanSu/api/externals/repository/abstract" | ||
| goqu "github.com/doug-martin/goqu/v9" | ||
| _ "github.com/doug-martin/goqu/v9/dialect/mysql" | ||
| ) | ||
|
|
||
| type userGroupRepository struct { | ||
| client db.Client | ||
| crud abstract.Crud | ||
| } | ||
|
|
||
| type UserGroupRepository interface { | ||
| BulkInsert(context.Context, *sql.Tx, int, []int) error | ||
| BulkDelete(context.Context, *sql.Tx, int, []int) error | ||
| } | ||
|
|
||
| func NewUserGroupRepository(client db.Client, crud abstract.Crud) UserGroupRepository { | ||
| return &userGroupRepository{ | ||
| client: client, | ||
| crud: crud, | ||
| } | ||
| } | ||
|
|
||
| // 指定された (user_id, group_id) を登録。 | ||
| func (r *userGroupRepository) BulkInsert(ctx context.Context, tx *sql.Tx, userID int, insertGroupIDs []int) error { | ||
| if len(insertGroupIDs) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| // レコード作成 | ||
| var userGroupRecords []goqu.Record | ||
| for _, groupID := range insertGroupIDs { | ||
| userGroupRecords = append(userGroupRecords, goqu.Record{ | ||
| "user_id": userID, | ||
| "group_id": groupID, | ||
| }) | ||
| } | ||
|
|
||
| queryDataset := goqu.Dialect("mysql").Insert("user_groups").Rows(userGroupRecords) | ||
| query, args, err := queryDataset.ToSQL() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = tx.ExecContext(ctx, query, args...) | ||
| return err | ||
| } | ||
|
|
||
| // 指定された deleteGroupIDs を削除。 | ||
| func (r *userGroupRepository) BulkDelete(ctx context.Context, tx *sql.Tx, userID int, deleteGroupIDs []int) error { | ||
| if len(deleteGroupIDs) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| queryDataset := goqu.Dialect("mysql").Delete("user_groups").Where( | ||
| goqu.I("user_id").Eq(userID), | ||
| goqu.I("group_id").In(deleteGroupIDs), | ||
| ) | ||
|
|
||
| query, args, err := queryDataset.ToSQL() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = tx.ExecContext(ctx, query, args...) | ||
| return err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.