chore: revert "feat: add `visibility` field to resource (#743)" (#751)

Revert "feat: add `visibility` field to resource (#743)"

This reverts commit b68cc08592.
pull/753/head
boojack 3 years ago committed by GitHub
parent b68cc08592
commit 575a0610a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,7 +13,6 @@ type Resource struct {
Blob []byte `json:"-"` Blob []byte `json:"-"`
Type string `json:"type"` Type string `json:"type"`
Size int64 `json:"size"` Size int64 `json:"size"`
Visibility Visibility `json:"visibility"`
// Related fields // Related fields
LinkedMemoAmount int `json:"linkedMemoAmount"` LinkedMemoAmount int `json:"linkedMemoAmount"`
@ -28,7 +27,6 @@ type ResourceCreate struct {
Blob []byte `json:"blob"` Blob []byte `json:"blob"`
Type string `json:"type"` Type string `json:"type"`
Size int64 `json:"size"` Size int64 `json:"size"`
Visibility Visibility `json:"visibility"`
} }
type ResourceFind struct { type ResourceFind struct {
@ -40,7 +38,6 @@ type ResourceFind struct {
// Domain specific fields // Domain specific fields
Filename *string `json:"filename"` Filename *string `json:"filename"`
MemoID *int MemoID *int
Visibility *Visibility `json:"visibility"`
} }
type ResourcePatch struct { type ResourcePatch struct {
@ -51,7 +48,6 @@ type ResourcePatch struct {
// Domain specific fields // Domain specific fields
Filename *string `json:"filename"` Filename *string `json:"filename"`
Visibility *Visibility `json:"visibility"`
} }
type ResourceDelete struct { type ResourceDelete struct {

@ -75,8 +75,7 @@ CREATE TABLE resource (
blob BLOB DEFAULT NULL, blob BLOB DEFAULT NULL,
external_link TEXT NOT NULL DEFAULT '', external_link TEXT NOT NULL DEFAULT '',
type 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 -- memo_resource

@ -1,2 +0,0 @@
-- Add visibility field to resource
ALTER TABLE resource ADD COLUMN visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED' 'PRIVATE')) DEFAULT 'PRIVATE';

@ -26,7 +26,6 @@ type resourceRaw struct {
Blob []byte Blob []byte
Type string Type string
Size int64 Size int64
Visibility api.Visibility
} }
func (raw *resourceRaw) toResource() *api.Resource { func (raw *resourceRaw) toResource() *api.Resource {
@ -43,7 +42,6 @@ func (raw *resourceRaw) toResource() *api.Resource {
Blob: raw.Blob, Blob: raw.Blob,
Type: raw.Type, Type: raw.Type,
Size: raw.Size, Size: raw.Size,
Visibility: raw.Visibility,
} }
} }
@ -219,20 +217,18 @@ func createResource(ctx context.Context, tx *sql.Tx, create *api.ResourceCreate)
blob, blob,
type, type,
size, size,
visibility,
creator_id creator_id
) )
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
RETURNING id, filename, blob, type, size, visibility, creator_id, created_ts, updated_ts RETURNING id, filename, blob, type, size, creator_id, created_ts, updated_ts
` `
var resourceRaw resourceRaw var resourceRaw resourceRaw
if err := tx.QueryRowContext(ctx, query, create.Filename, create.Blob, create.Type, create.Size, create.Visibility, create.CreatorID).Scan( if err := tx.QueryRowContext(ctx, query, create.Filename, create.Blob, create.Type, create.Size, create.CreatorID).Scan(
&resourceRaw.ID, &resourceRaw.ID,
&resourceRaw.Filename, &resourceRaw.Filename,
&resourceRaw.Blob, &resourceRaw.Blob,
&resourceRaw.Type, &resourceRaw.Type,
&resourceRaw.Size, &resourceRaw.Size,
&resourceRaw.Visibility,
&resourceRaw.CreatorID, &resourceRaw.CreatorID,
&resourceRaw.CreatedTs, &resourceRaw.CreatedTs,
&resourceRaw.UpdatedTs, &resourceRaw.UpdatedTs,
@ -252,9 +248,6 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*
if v := patch.Filename; v != nil { if v := patch.Filename; v != nil {
set, args = append(set, "filename = ?"), append(args, *v) 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) args = append(args, patch.ID)
@ -262,7 +255,7 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*
UPDATE resource UPDATE resource
SET ` + strings.Join(set, ", ") + ` SET ` + strings.Join(set, ", ") + `
WHERE id = ? WHERE id = ?
RETURNING id, filename, blob, type, size, visibility, creator_id, created_ts, updated_ts RETURNING id, filename, blob, type, size, creator_id, created_ts, updated_ts
` `
var resourceRaw resourceRaw var resourceRaw resourceRaw
if err := tx.QueryRowContext(ctx, query, args...).Scan( if err := tx.QueryRowContext(ctx, query, args...).Scan(
@ -271,7 +264,6 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*
&resourceRaw.Blob, &resourceRaw.Blob,
&resourceRaw.Type, &resourceRaw.Type,
&resourceRaw.Size, &resourceRaw.Size,
&resourceRaw.Visibility,
&resourceRaw.CreatorID, &resourceRaw.CreatorID,
&resourceRaw.CreatedTs, &resourceRaw.CreatedTs,
&resourceRaw.UpdatedTs, &resourceRaw.UpdatedTs,
@ -294,9 +286,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
if v := find.Filename; v != nil { if v := find.Filename; v != nil {
where, args = append(where, "filename = ?"), append(args, *v) 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 { if v := find.MemoID; v != nil {
where, args = append(where, "id in (SELECT resource_id FROM memo_resource WHERE memo_id = ?)"), append(args, *v) where, args = append(where, "id in (SELECT resource_id FROM memo_resource WHERE memo_id = ?)"), append(args, *v)
} }
@ -308,7 +297,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
blob, blob,
type, type,
size, size,
visibility,
creator_id, creator_id,
created_ts, created_ts,
updated_ts updated_ts
@ -331,7 +319,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
&resourceRaw.Blob, &resourceRaw.Blob,
&resourceRaw.Type, &resourceRaw.Type,
&resourceRaw.Size, &resourceRaw.Size,
&resourceRaw.Visibility,
&resourceRaw.CreatorID, &resourceRaw.CreatorID,
&resourceRaw.CreatedTs, &resourceRaw.CreatedTs,
&resourceRaw.UpdatedTs, &resourceRaw.UpdatedTs,

Loading…
Cancel
Save