-
Notifications
You must be signed in to change notification settings - Fork 8
feat(gebura): impl AppCategory #122
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4b753b
feat(gebura): add AppCategory part 1
Tabing010102 3aeed92
feat(gebura): add ListAppCategory
Tabing010102 db21db0
feat(gebura): impl ListAppCategory
Tabing010102 e5958fb
chore(gebura): update style, fix typo
Tabing010102 1d3398f
fix(gebura): move all ops into tx in repo with tx
Tabing010102 f5702d2
chore(gebura): improve db ops for appcategory
Tabing010102 77ca3dc
fix(gebura): use tx for UpdateAppCategory
Tabing010102 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package bizgebura | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "github.com/tuihub/librarian/internal/biz/bizutils" | ||
| "github.com/tuihub/librarian/internal/lib/libauth" | ||
| "github.com/tuihub/librarian/internal/model" | ||
| "github.com/tuihub/librarian/internal/model/modelgebura" | ||
| pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1" | ||
| ) | ||
|
|
||
| func (g *Gebura) CreateAppCategory(ctx context.Context, ac *modelgebura.AppCategory) (*modelgebura.AppCategory, error) { | ||
| claims := libauth.FromContextAssertUserType(ctx) | ||
| if claims == nil { | ||
| return nil, bizutils.NoPermissionError() | ||
| } | ||
| id, err := g.id.New() | ||
| if err != nil { | ||
| return nil, pb.ErrorErrorReasonUnspecified("%s", err) | ||
| } | ||
| ac.ID = id | ||
| ac.VersionNumber = 1 | ||
| ac.VersionDate = time.Now() | ||
| if err = g.repo.CreateAppCategory(ctx, claims.UserID, ac); err != nil { | ||
| return nil, pb.ErrorErrorReasonUnspecified("%s", err.Error()) | ||
| } | ||
| return ac, nil | ||
| } | ||
|
|
||
| func (g *Gebura) ListAppCategories(ctx context.Context) ([]*modelgebura.AppCategory, error) { | ||
| claims := libauth.FromContextAssertUserType(ctx) | ||
| if claims == nil { | ||
| return nil, bizutils.NoPermissionError() | ||
| } | ||
| acList, err := g.repo.ListAppCategories(ctx, claims.UserID) | ||
| if err != nil { | ||
| return nil, pb.ErrorErrorReasonUnspecified("%s", err.Error()) | ||
| } | ||
| return acList, nil | ||
| } | ||
|
|
||
| func (g *Gebura) UpdateAppCategory(ctx context.Context, ac *modelgebura.AppCategory) error { | ||
| claims := libauth.FromContextAssertUserType(ctx) | ||
| if claims == nil { | ||
| return bizutils.NoPermissionError() | ||
| } | ||
| err := g.repo.UpdateAppCategory(ctx, claims.UserID, ac) | ||
| if err != nil { | ||
| return pb.ErrorErrorReasonUnspecified("%s", err.Error()) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (g *Gebura) DeleteAppCategory(ctx context.Context, id model.InternalID) error { | ||
| claims := libauth.FromContextAssertUserType(ctx) | ||
| if claims == nil { | ||
| return bizutils.NoPermissionError() | ||
| } | ||
| err := g.repo.DeleteAppCategory(ctx, claims.UserID, id) | ||
| if err != nil { | ||
| return pb.ErrorErrorReasonUnspecified("%s", err.Error()) | ||
| } | ||
| return nil | ||
| } |
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
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.