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
b68cc085
Unverified
Commit
b68cc085
authored
Dec 15, 2022
by
boojack
Committed by
GitHub
Dec 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add `visibility` field to resource (#743)
parent
d51af7e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
24 deletions
+44
-24
resource.go
api/resource.go
+15
-11
LATEST__SCHEMA.sql
store/db/migration/dev/LATEST__SCHEMA.sql
+2
-1
00__resource_visibility.sql
store/db/migration/prod/0.9/00__resource_visibility.sql
+2
-0
resource.go
store/resource.go
+25
-12
No files found.
api/resource.go
View file @
b68cc085
...
...
@@ -9,10 +9,11 @@ type Resource struct {
UpdatedTs
int64
`json:"updatedTs"`
// Domain specific fields
Filename
string
`json:"filename"`
Blob
[]
byte
`json:"-"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Filename
string
`json:"filename"`
Blob
[]
byte
`json:"-"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Visibility
Visibility
`json:"visibility"`
// Related fields
LinkedMemoAmount
int
`json:"linkedMemoAmount"`
...
...
@@ -23,10 +24,11 @@ type ResourceCreate struct {
CreatorID
int
// Domain specific fields
Filename
string
`json:"filename"`
Blob
[]
byte
`json:"blob"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Filename
string
`json:"filename"`
Blob
[]
byte
`json:"blob"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Visibility
Visibility
`json:"visibility"`
}
type
ResourceFind
struct
{
...
...
@@ -36,8 +38,9 @@ type ResourceFind struct {
CreatorID
*
int
`json:"creatorId"`
// Domain specific fields
Filename
*
string
`json:"filename"`
MemoID
*
int
Filename
*
string
`json:"filename"`
MemoID
*
int
Visibility
*
Visibility
`json:"visibility"`
}
type
ResourcePatch
struct
{
...
...
@@ -47,7 +50,8 @@ type ResourcePatch struct {
UpdatedTs
*
int64
// Domain specific fields
Filename
*
string
`json:"filename"`
Filename
*
string
`json:"filename"`
Visibility
*
Visibility
`json:"visibility"`
}
type
ResourceDelete
struct
{
...
...
store/db/migration/dev/LATEST__SCHEMA.sql
View file @
b68cc085
...
...
@@ -75,7 +75,8 @@ CREATE TABLE resource (
blob
BLOB
DEFAULT
NULL
,
external_link
TEXT
NOT
NULL
DEFAULT
''
,
type
TEXT
NOT
NULL
DEFAULT
''
,
size
INTEGER
NOT
NULL
DEFAULT
0
size
INTEGER
NOT
NULL
DEFAULT
0
,
visibility
TEXT
NOT
NULL
CHECK
(
visibility
IN
(
'PUBLIC'
,
'PROTECTED'
,
'PRIVATE'
))
DEFAULT
'PRIVATE'
);
-- memo_resource
...
...
store/db/migration/prod/0.9/00__resource_visibility.sql
0 → 100644
View file @
b68cc085
-- Add visibility field to resource
ALTER
TABLE
resource
ADD
COLUMN
visibility
TEXT
NOT
NULL
CHECK
(
visibility
IN
(
'PUBLIC'
,
'PROTECTED'
'PRIVATE'
))
DEFAULT
'PRIVATE'
;
store/resource.go
View file @
b68cc085
...
...
@@ -22,10 +22,11 @@ type resourceRaw struct {
UpdatedTs
int64
// Domain specific fields
Filename
string
Blob
[]
byte
Type
string
Size
int64
Filename
string
Blob
[]
byte
Type
string
Size
int64
Visibility
api
.
Visibility
}
func
(
raw
*
resourceRaw
)
toResource
()
*
api
.
Resource
{
...
...
@@ -38,10 +39,11 @@ func (raw *resourceRaw) toResource() *api.Resource {
UpdatedTs
:
raw
.
UpdatedTs
,
// Domain specific fields
Filename
:
raw
.
Filename
,
Blob
:
raw
.
Blob
,
Type
:
raw
.
Type
,
Size
:
raw
.
Size
,
Filename
:
raw
.
Filename
,
Blob
:
raw
.
Blob
,
Type
:
raw
.
Type
,
Size
:
raw
.
Size
,
Visibility
:
raw
.
Visibility
,
}
}
...
...
@@ -217,18 +219,20 @@ func createResource(ctx context.Context, tx *sql.Tx, create *api.ResourceCreate)
blob,
type,
size,
visibility,
creator_id
)
VALUES (?, ?, ?, ?, ?)
RETURNING id, filename, blob, type, size, creator_id, created_ts, updated_ts
VALUES (?, ?, ?, ?, ?
, ?
)
RETURNING id, filename, blob, type, size,
visibility,
creator_id, created_ts, updated_ts
`
var
resourceRaw
resourceRaw
if
err
:=
tx
.
QueryRowContext
(
ctx
,
query
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
)
.
Scan
(
if
err
:=
tx
.
QueryRowContext
(
ctx
,
query
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
Visibility
,
create
.
CreatorID
)
.
Scan
(
&
resourceRaw
.
ID
,
&
resourceRaw
.
Filename
,
&
resourceRaw
.
Blob
,
&
resourceRaw
.
Type
,
&
resourceRaw
.
Size
,
&
resourceRaw
.
Visibility
,
&
resourceRaw
.
CreatorID
,
&
resourceRaw
.
CreatedTs
,
&
resourceRaw
.
UpdatedTs
,
...
...
@@ -248,6 +252,9 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*
if
v
:=
patch
.
Filename
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"filename = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
patch
.
Visibility
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"visibility = ?"
),
append
(
args
,
*
v
)
}
args
=
append
(
args
,
patch
.
ID
)
...
...
@@ -255,7 +262,7 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*
UPDATE resource
SET `
+
strings
.
Join
(
set
,
", "
)
+
`
WHERE id = ?
RETURNING id, filename, blob, type, size, creator_id, created_ts, updated_ts
RETURNING id, filename, blob, type, size,
visibility,
creator_id, created_ts, updated_ts
`
var
resourceRaw
resourceRaw
if
err
:=
tx
.
QueryRowContext
(
ctx
,
query
,
args
...
)
.
Scan
(
...
...
@@ -264,6 +271,7 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*
&
resourceRaw
.
Blob
,
&
resourceRaw
.
Type
,
&
resourceRaw
.
Size
,
&
resourceRaw
.
Visibility
,
&
resourceRaw
.
CreatorID
,
&
resourceRaw
.
CreatedTs
,
&
resourceRaw
.
UpdatedTs
,
...
...
@@ -286,6 +294,9 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
if
v
:=
find
.
Filename
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"filename = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
Visibility
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"visibility = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
MemoID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"id in (SELECT resource_id FROM memo_resource WHERE memo_id = ?)"
),
append
(
args
,
*
v
)
}
...
...
@@ -297,6 +308,7 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
blob,
type,
size,
visibility,
creator_id,
created_ts,
updated_ts
...
...
@@ -319,6 +331,7 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
&
resourceRaw
.
Blob
,
&
resourceRaw
.
Type
,
&
resourceRaw
.
Size
,
&
resourceRaw
.
Visibility
,
&
resourceRaw
.
CreatorID
,
&
resourceRaw
.
CreatedTs
,
&
resourceRaw
.
UpdatedTs
,
...
...
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