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
ce390f3f
Commit
ce390f3f
authored
Aug 18, 2022
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add memo visibility with user setting
parent
43a8b7d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
4 deletions
+51
-4
user_setting.go
api/user_setting.go
+7
-1
memo.go
server/memo.go
+12
-0
user_setting.go
store/user_setting.go
+32
-3
No files found.
api/user_setting.go
View file @
ce390f3f
...
@@ -3,8 +3,10 @@ package api
...
@@ -3,8 +3,10 @@ package api
type
UserSettingKey
string
type
UserSettingKey
string
const
(
const
(
// UserSettingLocaleKey is the key type for user locale
// UserSettingLocaleKey is the key type for user locale
.
UserSettingLocaleKey
UserSettingKey
=
"locale"
UserSettingLocaleKey
UserSettingKey
=
"locale"
// UserSettingMemoVisibilityKey is the key type for user perference memo default visibility.
UserSettingMemoVisibilityKey
UserSettingKey
=
"memo-visibility"
)
)
// String returns the string format of UserSettingKey type.
// String returns the string format of UserSettingKey type.
...
@@ -12,6 +14,8 @@ func (key UserSettingKey) String() string {
...
@@ -12,6 +14,8 @@ func (key UserSettingKey) String() string {
switch
key
{
switch
key
{
case
UserSettingLocaleKey
:
case
UserSettingLocaleKey
:
return
"locale"
return
"locale"
case
UserSettingMemoVisibilityKey
:
return
"memo-visibility"
}
}
return
""
return
""
}
}
...
@@ -31,4 +35,6 @@ type UserSettingUpsert struct {
...
@@ -31,4 +35,6 @@ type UserSettingUpsert struct {
type
UserSettingFind
struct
{
type
UserSettingFind
struct
{
UserID
int
UserID
int
Key
*
UserSettingKey
`json:"key"`
}
}
server/memo.go
View file @
ce390f3f
...
@@ -27,6 +27,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -27,6 +27,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo request"
)
.
SetInternal
(
err
)
}
}
userSettingMemoVisibilityKey
:=
api
.
UserSettingMemoVisibilityKey
userMemoVisibilitySetting
,
err
:=
s
.
Store
.
FindUserSetting
(
ctx
,
&
api
.
UserSettingFind
{
UserID
:
userID
,
Key
:
&
userSettingMemoVisibilityKey
,
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user setting"
)
.
SetInternal
(
err
)
}
if
userMemoVisibilitySetting
!=
nil
{
memoCreate
.
Visibility
=
(
*
api
.
Visibility
)(
&
userMemoVisibilitySetting
.
Value
)
}
if
memoCreate
.
Visibility
==
nil
||
*
memoCreate
.
Visibility
==
""
{
if
memoCreate
.
Visibility
==
nil
||
*
memoCreate
.
Visibility
==
""
{
private
:=
api
.
Privite
private
:=
api
.
Privite
memoCreate
.
Visibility
=
&
private
memoCreate
.
Visibility
=
&
private
...
...
store/user_setting.go
View file @
ce390f3f
...
@@ -3,6 +3,7 @@ package store
...
@@ -3,6 +3,7 @@ package store
import
(
import
(
"context"
"context"
"database/sql"
"database/sql"
"strings"
"github.com/usememos/memos/api"
"github.com/usememos/memos/api"
)
)
...
@@ -62,6 +63,27 @@ func (s *Store) FindUserSettingList(ctx context.Context, find *api.UserSettingFi
...
@@ -62,6 +63,27 @@ func (s *Store) FindUserSettingList(ctx context.Context, find *api.UserSettingFi
return
list
,
nil
return
list
,
nil
}
}
func
(
s
*
Store
)
FindUserSetting
(
ctx
context
.
Context
,
find
*
api
.
UserSettingFind
)
(
*
api
.
UserSetting
,
error
)
{
tx
,
err
:=
s
.
db
.
BeginTx
(
ctx
,
nil
)
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
}
defer
tx
.
Rollback
()
list
,
err
:=
findUserSettingList
(
ctx
,
tx
,
find
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
list
)
==
0
{
return
nil
,
nil
}
userSetting
:=
list
[
0
]
.
toUserSetting
()
return
userSetting
,
nil
}
func
upsertUserSetting
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
upsert
*
api
.
UserSettingUpsert
)
(
*
userSettingRaw
,
error
)
{
func
upsertUserSetting
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
upsert
*
api
.
UserSettingUpsert
)
(
*
userSettingRaw
,
error
)
{
query
:=
`
query
:=
`
INSERT INTO user_setting (
INSERT INTO user_setting (
...
@@ -86,15 +108,22 @@ func upsertUserSetting(ctx context.Context, tx *sql.Tx, upsert *api.UserSettingU
...
@@ -86,15 +108,22 @@ func upsertUserSetting(ctx context.Context, tx *sql.Tx, upsert *api.UserSettingU
}
}
func
findUserSettingList
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
find
*
api
.
UserSettingFind
)
([]
*
userSettingRaw
,
error
)
{
func
findUserSettingList
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
find
*
api
.
UserSettingFind
)
([]
*
userSettingRaw
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
if
v
:=
find
.
Key
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"key = ?"
),
append
(
args
,
(
*
v
)
.
String
())
}
where
,
args
=
append
(
where
,
"user_id = ?"
),
append
(
args
,
find
.
UserID
)
query
:=
`
query
:=
`
SELECT
SELECT
user_id,
user_id,
key,
key,
value
value
FROM user_setting
FROM user_setting
WHERE user_id = ?
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
`
rows
,
err
:=
tx
.
QueryContext
(
ctx
,
query
,
args
...
)
rows
,
err
:=
tx
.
QueryContext
(
ctx
,
query
,
find
.
UserID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
}
}
...
...
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