Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
21ad6cc8
Commit
21ad6cc8
authored
Nov 06, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update tag service creator
parent
c24181b2
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
294 additions
and
246 deletions
+294
-246
tag_service.go
api/v2/tag_service.go
+51
-10
tag_service.proto
proto/api/v2/tag_service.proto
+6
-2
user_service.proto
proto/api/v2/user_service.proto
+7
-7
README.md
proto/gen/api/v2/README.md
+2
-2
tag_service.pb.go
proto/gen/api/v2/tag_service.pb.go
+64
-61
user_service.pb.go
proto/gen/api/v2/user_service.pb.go
+162
-162
tag.ts
web/src/store/module/tag.ts
+2
-2
No files found.
api/v2/tag_service.go
View file @
21ad6cc8
...
...
@@ -2,7 +2,9 @@ package v2
import
(
"context"
"fmt"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
...
...
@@ -24,14 +26,31 @@ func (s *APIV2Service) UpsertTag(ctx context.Context, request *apiv2pb.UpsertTag
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to upsert tag: %v"
,
err
)
}
t
,
err
:=
s
.
convertTagFromStore
(
ctx
,
tag
)
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to convert tag: %v"
,
err
)
}
return
&
apiv2pb
.
UpsertTagResponse
{
Tag
:
convertTagFromStore
(
tag
)
,
Tag
:
t
,
},
nil
}
func
(
s
*
APIV2Service
)
ListTags
(
ctx
context
.
Context
,
request
*
apiv2pb
.
ListTagsRequest
)
(
*
apiv2pb
.
ListTagsResponse
,
error
)
{
username
,
err
:=
ExtractUsernameFromName
(
request
.
Creator
)
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"invalid username: %v"
,
err
)
}
user
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
,
})
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to get user: %v"
,
err
)
}
if
user
==
nil
{
return
nil
,
status
.
Errorf
(
codes
.
NotFound
,
"user not found"
)
}
tags
,
err
:=
s
.
Store
.
ListTags
(
ctx
,
&
store
.
FindTag
{
CreatorID
:
request
.
CreatorId
,
CreatorID
:
user
.
ID
,
})
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to list tags: %v"
,
err
)
...
...
@@ -39,26 +58,48 @@ func (s *APIV2Service) ListTags(ctx context.Context, request *apiv2pb.ListTagsRe
response
:=
&
apiv2pb
.
ListTagsResponse
{}
for
_
,
tag
:=
range
tags
{
response
.
Tags
=
append
(
response
.
Tags
,
convertTagFromStore
(
tag
))
t
,
err
:=
s
.
convertTagFromStore
(
ctx
,
tag
)
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to convert tag: %v"
,
err
)
}
response
.
Tags
=
append
(
response
.
Tags
,
t
)
}
return
response
,
nil
}
func
(
s
*
APIV2Service
)
DeleteTag
(
ctx
context
.
Context
,
request
*
apiv2pb
.
DeleteTagRequest
)
(
*
apiv2pb
.
DeleteTagResponse
,
error
)
{
err
:=
s
.
Store
.
DeleteTag
(
ctx
,
&
store
.
DeleteTag
{
Name
:
request
.
Tag
.
Name
,
CreatorID
:
request
.
Tag
.
CreatorId
,
username
,
err
:=
ExtractUsernameFromName
(
request
.
Tag
.
Creator
)
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"invalid username: %v"
,
err
)
}
user
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
,
})
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to get user: %v"
,
err
)
}
if
user
==
nil
{
return
nil
,
status
.
Errorf
(
codes
.
NotFound
,
"user not found"
)
}
if
err
:=
s
.
Store
.
DeleteTag
(
ctx
,
&
store
.
DeleteTag
{
Name
:
request
.
Tag
.
Name
,
CreatorID
:
user
.
ID
,
});
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to delete tag: %v"
,
err
)
}
return
&
apiv2pb
.
DeleteTagResponse
{},
nil
}
func
convertTagFromStore
(
tag
*
store
.
Tag
)
*
apiv2pb
.
Tag
{
return
&
apiv2pb
.
Tag
{
Name
:
tag
.
Name
,
CreatorId
:
int32
(
tag
.
CreatorID
),
func
(
s
*
APIV2Service
)
convertTagFromStore
(
ctx
context
.
Context
,
tag
*
store
.
Tag
)
(
*
apiv2pb
.
Tag
,
error
)
{
user
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
ID
:
&
tag
.
CreatorID
,
})
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to get user"
)
}
return
&
apiv2pb
.
Tag
{
Name
:
tag
.
Name
,
Creator
:
fmt
.
Sprintf
(
"%s%s"
,
UserNamePrefix
,
user
.
Username
),
},
nil
}
proto/api/v2/tag_service.proto
View file @
21ad6cc8
...
...
@@ -20,7 +20,9 @@ service TagService {
message
Tag
{
string
name
=
1
;
int32
creator_id
=
2
;
// The creator of tags.
// Format: users/{username}
string
creator
=
2
;
}
message
UpsertTagRequest
{
...
...
@@ -32,7 +34,9 @@ message UpsertTagResponse {
}
message
ListTagsRequest
{
int32
creator_id
=
1
;
// The creator of tags.
// Format: users/{username}
string
creator
=
1
;
}
message
ListTagsResponse
{
...
...
proto/api/v2/user_service.proto
View file @
21ad6cc8
...
...
@@ -108,6 +108,13 @@ message UpdateUserResponse {
User
user
=
1
;
}
message
UserAccessToken
{
string
access_token
=
1
;
string
description
=
2
;
google.protobuf.Timestamp
issued_at
=
3
;
google.protobuf.Timestamp
expires_at
=
4
;
}
message
ListUserAccessTokensRequest
{
// The name of the user.
// Format: users/{username}
...
...
@@ -141,10 +148,3 @@ message DeleteUserAccessTokenRequest {
}
message
DeleteUserAccessTokenResponse
{}
message
UserAccessToken
{
string
access_token
=
1
;
string
description
=
2
;
google.protobuf.Timestamp
issued_at
=
3
;
google.protobuf.Timestamp
expires_at
=
4
;
}
proto/gen/api/v2/README.md
View file @
21ad6cc8
...
...
@@ -928,7 +928,7 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| creator
_id |
[
int32
](
#int32
)
| |
|
| creator
|
[
string
](
#string
)
| | The creator of tags. Format: users/{username}
|
...
...
@@ -959,7 +959,7 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | |
| creator
_id |
[
int32
](
#int32
)
| |
|
| creator
|
[
string
](
#string
)
| | The creator of tags. Format: users/{username}
|
...
...
proto/gen/api/v2/tag_service.pb.go
View file @
21ad6cc8
This diff is collapsed.
Click to expand it.
proto/gen/api/v2/user_service.pb.go
View file @
21ad6cc8
This diff is collapsed.
Click to expand it.
web/src/store/module/tag.ts
View file @
21ad6cc8
...
...
@@ -13,7 +13,7 @@ export const useTagStore = () => {
const
fetchTags
=
async
()
=>
{
const
{
tags
}
=
await
tagServiceClient
.
listTags
({
creator
Id
:
currentUser
.
id
,
creator
:
currentUser
.
name
,
});
store
.
dispatch
(
setTags
(
tags
.
map
((
tag
)
=>
tag
.
name
)));
};
...
...
@@ -29,7 +29,7 @@ export const useTagStore = () => {
await
tagServiceClient
.
deleteTag
({
tag
:
{
name
:
tagName
,
creator
Id
:
currentUser
.
id
,
creator
:
currentUser
.
name
,
},
});
store
.
dispatch
(
deleteTagAction
(
tagName
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment