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
825bea59
Commit
825bea59
authored
Feb 04, 2022
by
email
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: user api
parent
3fa91816
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
82 additions
and
21 deletions
+82
-21
memo.go
api/memo.go
+1
-0
user.go
api/user.go
+3
-2
memo.go
server/memo.go
+11
-0
user.go
server/user.go
+41
-4
memo.go
store/memo.go
+5
-2
shortcut.go
store/shortcut.go
+2
-1
user.go
store/user.go
+9
-4
api.ts
web/src/helpers/api.ts
+5
-5
userService.ts
web/src/services/userService.ts
+5
-3
No files found.
api/memo.go
View file @
825bea59
...
@@ -25,6 +25,7 @@ type MemoPatch struct {
...
@@ -25,6 +25,7 @@ type MemoPatch struct {
type
MemoFind
struct
{
type
MemoFind
struct
{
Id
*
int
Id
*
int
CreatorId
*
int
CreatorId
*
int
RowStatus
*
string
}
}
type
MemoDelete
struct
{
type
MemoDelete
struct
{
...
...
api/user.go
View file @
825bea59
...
@@ -29,8 +29,9 @@ type UserPatch struct {
...
@@ -29,8 +29,9 @@ type UserPatch struct {
type
UserFind
struct
{
type
UserFind
struct
{
Id
*
int
`json:"id"`
Id
*
int
`json:"id"`
Name
*
string
`json:"name"`
Name
*
string
`json:"name"`
OpenId
*
string
Password
*
string
OpenId
*
string
}
}
type
UserRenameCheck
struct
{
type
UserRenameCheck
struct
{
...
...
server/memo.go
View file @
825bea59
...
@@ -63,6 +63,17 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -63,6 +63,17 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
memoFind
:=
&
api
.
MemoFind
{
memoFind
:=
&
api
.
MemoFind
{
CreatorId
:
&
userId
,
CreatorId
:
&
userId
,
}
}
showHiddenMemo
,
err
:=
strconv
.
ParseBool
(
c
.
QueryParam
(
"hidden"
))
if
err
!=
nil
{
showHiddenMemo
=
false
}
rowStatus
:=
"NORMAL"
if
showHiddenMemo
{
rowStatus
=
"HIDDEN"
}
memoFind
.
RowStatus
=
&
rowStatus
list
,
err
:=
s
.
MemoService
.
FindMemoList
(
memoFind
)
list
,
err
:=
s
.
MemoService
.
FindMemoList
(
memoFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch memo list"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch memo list"
)
.
SetInternal
(
err
)
...
...
server/user.go
View file @
825bea59
...
@@ -51,14 +51,51 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -51,14 +51,51 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
}
}
isUsable
:=
true
if
user
!=
nil
{
isUsable
=
false
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
user
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
isUsable
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to marshal user response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to marshal rename check response"
)
.
SetInternal
(
err
)
}
return
nil
})
g
.
POST
(
"/user/password_check"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
userPasswordCheck
:=
&
api
.
UserPasswordCheck
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPasswordCheck
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post user password check request"
)
.
SetInternal
(
err
)
}
if
userPasswordCheck
.
Password
==
""
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post user password check request"
)
}
userFind
:=
&
api
.
UserFind
{
Id
:
&
userId
,
Password
:
&
userPasswordCheck
.
Password
,
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
}
isValid
:=
false
if
user
!=
nil
{
isValid
=
true
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
isValid
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to marshal password check response"
)
.
SetInternal
(
err
)
}
}
return
nil
return
nil
})
})
g
.
PATCH
(
"user/me"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"
/
user/me"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
userPatch
:=
&
api
.
UserPatch
{
userPatch
:=
&
api
.
UserPatch
{
Id
:
userId
,
Id
:
userId
,
...
@@ -67,7 +104,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -67,7 +104,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch user request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch user request"
)
.
SetInternal
(
err
)
}
}
if
*
userPatch
.
ResetOpenId
{
if
userPatch
.
ResetOpenId
!=
nil
&&
*
userPatch
.
ResetOpenId
{
openId
:=
common
.
GenUUID
()
openId
:=
common
.
GenUUID
()
userPatch
.
OpenId
=
&
openId
userPatch
.
OpenId
=
&
openId
}
}
...
...
store/memo.go
View file @
825bea59
...
@@ -104,10 +104,10 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
...
@@ -104,10 +104,10 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
set
,
args
:=
[]
string
{},
[]
interface
{}{}
set
,
args
:=
[]
string
{},
[]
interface
{}{}
if
v
:=
patch
.
Content
;
v
!=
nil
{
if
v
:=
patch
.
Content
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"content = ?"
),
append
(
args
,
v
)
set
,
args
=
append
(
set
,
"content = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
patch
.
RowStatus
;
v
!=
nil
{
if
v
:=
patch
.
RowStatus
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"row_status = ?"
),
append
(
args
,
v
)
set
,
args
=
append
(
set
,
"row_status = ?"
),
append
(
args
,
*
v
)
}
}
args
=
append
(
args
,
patch
.
Id
)
args
=
append
(
args
,
patch
.
Id
)
...
@@ -150,6 +150,9 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
...
@@ -150,6 +150,9 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
if
v
:=
find
.
CreatorId
;
v
!=
nil
{
if
v
:=
find
.
CreatorId
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"creator_id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"creator_id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
RowStatus
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"row_status = ?"
),
append
(
args
,
*
v
)
}
rows
,
err
:=
db
.
Db
.
Query
(
`
rows
,
err
:=
db
.
Db
.
Query
(
`
SELECT
SELECT
...
...
store/shortcut.go
View file @
825bea59
...
@@ -69,7 +69,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
...
@@ -69,7 +69,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
INSERT INTO shortcut (
INSERT INTO shortcut (
title,
title,
payload,
payload,
creator_id
,
creator_id
)
)
VALUES (?, ?, ?)
VALUES (?, ?, ?)
RETURNING id, title, payload, creator_id, created_ts, updated_ts, row_status
RETURNING id, title, payload, creator_id, created_ts, updated_ts, row_status
...
@@ -103,6 +103,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
...
@@ -103,6 +103,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
func
patchShortcut
(
db
*
DB
,
patch
*
api
.
ShortcutPatch
)
(
*
api
.
Shortcut
,
error
)
{
func
patchShortcut
(
db
*
DB
,
patch
*
api
.
ShortcutPatch
)
(
*
api
.
Shortcut
,
error
)
{
set
,
args
:=
[]
string
{},
[]
interface
{}{}
set
,
args
:=
[]
string
{},
[]
interface
{}{}
if
v
:=
patch
.
Title
;
v
!=
nil
{
if
v
:=
patch
.
Title
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"title = ?"
),
append
(
args
,
*
v
)
set
,
args
=
append
(
set
,
"title = ?"
),
append
(
args
,
*
v
)
}
}
...
...
store/user.go
View file @
825bea59
...
@@ -57,7 +57,11 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
...
@@ -57,7 +57,11 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
)
)
VALUES (?, ?, ?)
VALUES (?, ?, ?)
RETURNING id, name, password, open_id, created_ts, updated_ts
RETURNING id, name, password, open_id, created_ts, updated_ts
`
)
`
,
create
.
Name
,
create
.
Password
,
create
.
OpenId
,
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
}
}
...
@@ -83,14 +87,15 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
...
@@ -83,14 +87,15 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
set
,
args
:=
[]
string
{},
[]
interface
{}{}
set
,
args
:=
[]
string
{},
[]
interface
{}{}
if
v
:=
patch
.
Name
;
v
!=
nil
{
if
v
:=
patch
.
Name
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"name = ?"
),
append
(
args
,
*
v
)
set
,
args
=
append
(
set
,
"name = ?"
),
append
(
args
,
v
)
}
}
if
v
:=
patch
.
Password
;
v
!=
nil
{
if
v
:=
patch
.
Password
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"password = ?"
),
append
(
args
,
*
v
)
set
,
args
=
append
(
set
,
"password = ?"
),
append
(
args
,
v
)
}
}
if
v
:=
patch
.
OpenId
;
v
!=
nil
{
if
v
:=
patch
.
OpenId
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"open_id = ?"
),
append
(
args
,
*
v
)
set
,
args
=
append
(
set
,
"open_id = ?"
),
append
(
args
,
v
)
}
}
args
=
append
(
args
,
patch
.
Id
)
args
=
append
(
args
,
patch
.
Id
)
row
,
err
:=
db
.
Db
.
Query
(
`
row
,
err
:=
db
.
Db
.
Query
(
`
...
...
web/src/helpers/api.ts
View file @
825bea59
...
@@ -78,7 +78,7 @@ namespace api {
...
@@ -78,7 +78,7 @@ namespace api {
export
function
checkUsernameUsable
(
name
:
string
)
{
export
function
checkUsernameUsable
(
name
:
string
)
{
return
request
<
boolean
>
({
return
request
<
boolean
>
({
method
:
"POST"
,
method
:
"POST"
,
url
:
"/api/user/
checkusername
"
,
url
:
"/api/user/
rename_check
"
,
data
:
{
data
:
{
name
,
name
,
},
},
...
@@ -88,15 +88,15 @@ namespace api {
...
@@ -88,15 +88,15 @@ namespace api {
export
function
checkPasswordValid
(
password
:
string
)
{
export
function
checkPasswordValid
(
password
:
string
)
{
return
request
<
boolean
>
({
return
request
<
boolean
>
({
method
:
"POST"
,
method
:
"POST"
,
url
:
"/api/user/
validpassword
"
,
url
:
"/api/user/
password_check
"
,
data
:
{
data
:
{
password
,
password
,
},
},
});
});
}
}
export
function
updateUserinfo
(
userinfo
:
Partial
<
{
name
:
string
;
password
:
string
}
>
)
{
export
function
updateUserinfo
(
userinfo
:
Partial
<
{
name
:
string
;
password
:
string
;
resetOpenId
:
boolean
}
>
)
{
return
request
({
return
request
<
Model
.
User
>
({
method
:
"PATCH"
,
method
:
"PATCH"
,
url
:
"/api/user/me"
,
url
:
"/api/user/me"
,
data
:
userinfo
,
data
:
userinfo
,
...
@@ -120,7 +120,7 @@ namespace api {
...
@@ -120,7 +120,7 @@ namespace api {
export
function
getMyDeletedMemos
()
{
export
function
getMyDeletedMemos
()
{
return
request
<
Model
.
Memo
[]
>
({
return
request
<
Model
.
Memo
[]
>
({
method
:
"GET"
,
method
:
"GET"
,
url
:
"/api/memo
/
?hidden=true"
,
url
:
"/api/memo?hidden=true"
,
});
});
}
}
...
...
web/src/services/userService.ts
View file @
825bea59
...
@@ -55,12 +55,14 @@ class UserService {
...
@@ -55,12 +55,14 @@ class UserService {
}
}
public
async
resetOpenId
():
Promise
<
string
>
{
public
async
resetOpenId
():
Promise
<
string
>
{
const
openId
=
await
api
.
resetOpenId
();
const
user
=
await
api
.
updateUserinfo
({
resetOpenId
:
true
,
});
appStore
.
dispatch
({
appStore
.
dispatch
({
type
:
"RESET_OPENID"
,
type
:
"RESET_OPENID"
,
payload
:
openId
,
payload
:
user
.
openId
,
});
});
return
openId
;
return
user
.
openId
;
}
}
private
convertResponseModelUser
(
user
:
Model
.
User
):
Model
.
User
{
private
convertResponseModelUser
(
user
:
Model
.
User
):
Model
.
User
{
...
...
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