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
d947a512
Commit
d947a512
authored
May 02, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: typo `Id` to `ID`
parent
13093b6f
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
143 additions
and
142 deletions
+143
-142
memo.go
api/memo.go
+7
-7
resource.go
api/resource.go
+6
-6
shortcut.go
api/shortcut.go
+7
-7
user.go
api/user.go
+8
-8
auth.go
server/auth.go
+1
-1
basic_auth.go
server/basic_auth.go
+14
-14
memo.go
server/memo.go
+13
-13
resource.go
server/resource.go
+7
-7
shortcut.go
server/shortcut.go
+11
-11
user.go
server/user.go
+17
-16
webhook.go
server/webhook.go
+11
-11
memo.go
store/memo.go
+11
-11
resource.go
store/resource.go
+7
-7
shortcut.go
store/shortcut.go
+11
-11
user.go
store/user.go
+12
-12
No files found.
api/memo.go
View file @
d947a512
package
api
package
api
type
Memo
struct
{
type
Memo
struct
{
I
d
int
`json:"id"`
I
D
int
`json:"id"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
RowStatus
string
`json:"rowStatus"`
RowStatus
string
`json:"rowStatus"`
Content
string
`json:"content"`
Content
string
`json:"content"`
CreatorI
d
int
`json:"creatorId"`
CreatorI
D
int
`json:"creatorId"`
}
}
type
MemoCreate
struct
{
type
MemoCreate
struct
{
CreatorI
d
int
CreatorI
D
int
Content
string
`json:"content"`
Content
string
`json:"content"`
}
}
type
MemoPatch
struct
{
type
MemoPatch
struct
{
I
d
int
I
D
int
Content
*
string
`json:"content"`
Content
*
string
`json:"content"`
RowStatus
*
string
`json:"rowStatus"`
RowStatus
*
string
`json:"rowStatus"`
...
@@ -25,13 +25,13 @@ type MemoPatch struct {
...
@@ -25,13 +25,13 @@ type MemoPatch struct {
}
}
type
MemoFind
struct
{
type
MemoFind
struct
{
I
d
*
int
`json:"id"`
I
D
*
int
`json:"id"`
CreatorI
d
*
int
`json:"creatorId"`
CreatorI
D
*
int
`json:"creatorId"`
RowStatus
*
string
`json:"rowStatus"`
RowStatus
*
string
`json:"rowStatus"`
}
}
type
MemoDelete
struct
{
type
MemoDelete
struct
{
I
d
*
int
`json:"id"`
I
D
*
int
`json:"id"`
}
}
type
MemoService
interface
{
type
MemoService
interface
{
...
...
api/resource.go
View file @
d947a512
package
api
package
api
type
Resource
struct
{
type
Resource
struct
{
I
d
int
`json:"id"`
I
D
int
`json:"id"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
...
@@ -10,7 +10,7 @@ type Resource struct {
...
@@ -10,7 +10,7 @@ type Resource struct {
Type
string
`json:"type"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Size
int64
`json:"size"`
CreatorI
d
int
`json:"creatorId"`
CreatorI
D
int
`json:"creatorId"`
}
}
type
ResourceCreate
struct
{
type
ResourceCreate
struct
{
...
@@ -19,17 +19,17 @@ type ResourceCreate struct {
...
@@ -19,17 +19,17 @@ type ResourceCreate struct {
Type
string
`json:"type"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Size
int64
`json:"size"`
CreatorI
d
int
CreatorI
D
int
}
}
type
ResourceFind
struct
{
type
ResourceFind
struct
{
I
d
*
int
`json:"id"`
I
D
*
int
`json:"id"`
CreatorI
d
*
int
`json:"creatorId"`
CreatorI
D
*
int
`json:"creatorId"`
Filename
*
string
`json:"filename"`
Filename
*
string
`json:"filename"`
}
}
type
ResourceDelete
struct
{
type
ResourceDelete
struct
{
I
d
int
I
D
int
}
}
type
ResourceService
interface
{
type
ResourceService
interface
{
...
...
api/shortcut.go
View file @
d947a512
package
api
package
api
type
Shortcut
struct
{
type
Shortcut
struct
{
I
d
int
`json:"id"`
I
D
int
`json:"id"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
Title
string
`json:"title"`
Title
string
`json:"title"`
Payload
string
`json:"payload"`
Payload
string
`json:"payload"`
RowStatus
string
`json:"rowStatus"`
RowStatus
string
`json:"rowStatus"`
CreatorI
d
int
CreatorI
D
int
}
}
type
ShortcutCreate
struct
{
type
ShortcutCreate
struct
{
// Standard fields
// Standard fields
CreatorI
d
int
CreatorI
D
int
// Domain specific fields
// Domain specific fields
Title
string
`json:"title"`
Title
string
`json:"title"`
...
@@ -21,7 +21,7 @@ type ShortcutCreate struct {
...
@@ -21,7 +21,7 @@ type ShortcutCreate struct {
}
}
type
ShortcutPatch
struct
{
type
ShortcutPatch
struct
{
I
d
int
I
D
int
Title
*
string
`json:"title"`
Title
*
string
`json:"title"`
Payload
*
string
`json:"payload"`
Payload
*
string
`json:"payload"`
...
@@ -29,17 +29,17 @@ type ShortcutPatch struct {
...
@@ -29,17 +29,17 @@ type ShortcutPatch struct {
}
}
type
ShortcutFind
struct
{
type
ShortcutFind
struct
{
I
d
*
int
I
D
*
int
// Standard fields
// Standard fields
CreatorI
d
*
int
CreatorI
D
*
int
// Domain specific fields
// Domain specific fields
Title
*
string
`json:"title"`
Title
*
string
`json:"title"`
}
}
type
ShortcutDelete
struct
{
type
ShortcutDelete
struct
{
I
d
int
I
D
int
}
}
type
ShortcutService
interface
{
type
ShortcutService
interface
{
...
...
api/user.go
View file @
d947a512
package
api
package
api
type
User
struct
{
type
User
struct
{
I
d
int
`json:"id"`
I
D
int
`json:"id"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
OpenI
d
string
`json:"openId"`
OpenI
D
string
`json:"openId"`
Name
string
`json:"name"`
Name
string
`json:"name"`
PasswordHash
string
`json:"-"`
PasswordHash
string
`json:"-"`
}
}
type
UserCreate
struct
{
type
UserCreate
struct
{
OpenI
d
string
OpenI
D
string
Name
string
Name
string
PasswordHash
string
PasswordHash
string
}
}
type
UserPatch
struct
{
type
UserPatch
struct
{
I
d
int
I
D
int
OpenI
d
*
string
OpenI
D
*
string
PasswordHash
*
string
PasswordHash
*
string
Name
*
string
`json:"name"`
Name
*
string
`json:"name"`
Password
*
string
`json:"password"`
Password
*
string
`json:"password"`
ResetOpenI
d
*
bool
`json:"resetOpenId"`
ResetOpenI
D
*
bool
`json:"resetOpenId"`
}
}
type
UserFind
struct
{
type
UserFind
struct
{
I
d
*
int
`json:"id"`
I
D
*
int
`json:"id"`
Name
*
string
`json:"name"`
Name
*
string
`json:"name"`
OpenI
d
*
string
OpenI
D
*
string
}
}
type
UserRenameCheck
struct
{
type
UserRenameCheck
struct
{
...
...
server/auth.go
View file @
d947a512
...
@@ -91,7 +91,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
...
@@ -91,7 +91,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
userCreate
:=
&
api
.
UserCreate
{
userCreate
:=
&
api
.
UserCreate
{
Name
:
signup
.
Name
,
Name
:
signup
.
Name
,
PasswordHash
:
string
(
passwordHash
),
PasswordHash
:
string
(
passwordHash
),
OpenI
d
:
common
.
GenUUID
(),
OpenI
D
:
common
.
GenUUID
(),
}
}
user
,
err
=
s
.
UserService
.
CreateUser
(
userCreate
)
user
,
err
=
s
.
UserService
.
CreateUser
(
userCreate
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/basic_auth.go
View file @
d947a512
...
@@ -13,11 +13,11 @@ import (
...
@@ -13,11 +13,11 @@ import (
)
)
var
(
var
(
userI
d
ContextKey
=
"user-id"
userI
D
ContextKey
=
"user-id"
)
)
func
getUserI
d
ContextKey
()
string
{
func
getUserI
D
ContextKey
()
string
{
return
userI
d
ContextKey
return
userI
D
ContextKey
}
}
func
setUserSession
(
c
echo
.
Context
,
user
*
api
.
User
)
error
{
func
setUserSession
(
c
echo
.
Context
,
user
*
api
.
User
)
error
{
...
@@ -27,7 +27,7 @@ func setUserSession(c echo.Context, user *api.User) error {
...
@@ -27,7 +27,7 @@ func setUserSession(c echo.Context, user *api.User) error {
MaxAge
:
1000
*
3600
*
24
*
30
,
MaxAge
:
1000
*
3600
*
24
*
30
,
HttpOnly
:
true
,
HttpOnly
:
true
,
}
}
sess
.
Values
[
userI
dContextKey
]
=
user
.
Id
sess
.
Values
[
userI
DContextKey
]
=
user
.
ID
err
:=
sess
.
Save
(
c
.
Request
(),
c
.
Response
())
err
:=
sess
.
Save
(
c
.
Request
(),
c
.
Response
())
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to set session, err: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to set session, err: %w"
,
err
)
...
@@ -43,7 +43,7 @@ func removeUserSession(c echo.Context) error {
...
@@ -43,7 +43,7 @@ func removeUserSession(c echo.Context) error {
MaxAge
:
0
,
MaxAge
:
0
,
HttpOnly
:
true
,
HttpOnly
:
true
,
}
}
sess
.
Values
[
userI
d
ContextKey
]
=
nil
sess
.
Values
[
userI
D
ContextKey
]
=
nil
err
:=
sess
.
Save
(
c
.
Request
(),
c
.
Response
())
err
:=
sess
.
Save
(
c
.
Request
(),
c
.
Response
())
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to set session, err: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to set session, err: %w"
,
err
)
...
@@ -65,30 +65,30 @@ func BasicAuthMiddleware(us api.UserService, next echo.HandlerFunc) echo.Handler
...
@@ -65,30 +65,30 @@ func BasicAuthMiddleware(us api.UserService, next echo.HandlerFunc) echo.Handler
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing session"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing session"
)
.
SetInternal
(
err
)
}
}
userI
dValue
:=
sess
.
Values
[
userId
ContextKey
]
userI
DValue
:=
sess
.
Values
[
userID
ContextKey
]
if
userI
d
Value
==
nil
{
if
userI
D
Value
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing userI
d
in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing userI
D
in session"
)
}
}
userI
d
,
err
:=
strconv
.
Atoi
(
fmt
.
Sprintf
(
"%v"
,
userId
Value
))
userI
D
,
err
:=
strconv
.
Atoi
(
fmt
.
Sprintf
(
"%v"
,
userID
Value
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to malformatted user id in the session."
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to malformatted user id in the session."
)
.
SetInternal
(
err
)
}
}
// Even if there is no error, we still need to make sure the user still exists.
// Even if there is no error, we still need to make sure the user still exists.
userFind
:=
&
api
.
UserFind
{
userFind
:=
&
api
.
UserFind
{
I
d
:
&
userId
,
I
D
:
&
userID
,
}
}
user
,
err
:=
us
.
FindUser
(
userFind
)
user
,
err
:=
us
.
FindUser
(
userFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find user by ID: %d"
,
userI
d
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find user by ID: %d"
,
userI
D
))
.
SetInternal
(
err
)
}
}
if
user
==
nil
{
if
user
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Not found user ID: %d"
,
userI
d
))
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Not found user ID: %d"
,
userI
D
))
}
}
// Stores userI
d
into context.
// Stores userI
D
into context.
c
.
Set
(
getUserI
dContextKey
(),
userId
)
c
.
Set
(
getUserI
DContextKey
(),
userID
)
return
next
(
c
)
return
next
(
c
)
}
}
...
...
server/memo.go
View file @
d947a512
...
@@ -13,9 +13,9 @@ import (
...
@@ -13,9 +13,9 @@ import (
func
(
s
*
Server
)
registerMemoRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
Server
)
registerMemoRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
memoCreate
:=
&
api
.
MemoCreate
{
memoCreate
:=
&
api
.
MemoCreate
{
CreatorI
d
:
userId
,
CreatorI
D
:
userID
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoCreate
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoCreate
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo request"
)
.
SetInternal
(
err
)
...
@@ -35,13 +35,13 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -35,13 +35,13 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
})
})
g
.
PATCH
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
memoI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
memoPatch
:=
&
api
.
MemoPatch
{
memoPatch
:=
&
api
.
MemoPatch
{
I
d
:
memoId
,
I
D
:
memoID
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoPatch
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoPatch
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch memo request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch memo request"
)
.
SetInternal
(
err
)
...
@@ -61,9 +61,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -61,9 +61,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
})
})
g
.
GET
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
memoFind
:=
&
api
.
MemoFind
{
memoFind
:=
&
api
.
MemoFind
{
CreatorI
d
:
&
userId
,
CreatorI
D
:
&
userID
,
}
}
rowStatus
:=
c
.
QueryParam
(
"rowStatus"
)
rowStatus
:=
c
.
QueryParam
(
"rowStatus"
)
if
rowStatus
!=
""
{
if
rowStatus
!=
""
{
...
@@ -84,21 +84,21 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -84,21 +84,21 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
})
})
g
.
GET
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
memoI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
memoFind
:=
&
api
.
MemoFind
{
memoFind
:=
&
api
.
MemoFind
{
I
d
:
&
memoId
,
I
D
:
&
memoID
,
}
}
memo
,
err
:=
s
.
MemoService
.
FindMemo
(
memoFind
)
memo
,
err
:=
s
.
MemoService
.
FindMemo
(
memoFind
)
if
err
!=
nil
{
if
err
!=
nil
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoI
d
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoI
D
))
.
SetInternal
(
err
)
}
}
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to
delete memo ID: %v"
,
memoId
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to
find memo by ID: %v"
,
memoID
))
.
SetInternal
(
err
)
}
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
...
@@ -110,18 +110,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -110,18 +110,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
})
})
g
.
DELETE
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
memoI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
memoDelete
:=
&
api
.
MemoDelete
{
memoDelete
:=
&
api
.
MemoDelete
{
I
d
:
&
memoId
,
I
D
:
&
memoID
,
}
}
err
=
s
.
MemoService
.
DeleteMemo
(
memoDelete
)
err
=
s
.
MemoService
.
DeleteMemo
(
memoDelete
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to delete memo ID: %v"
,
memoI
d
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to delete memo ID: %v"
,
memoI
D
))
.
SetInternal
(
err
)
}
}
c
.
JSON
(
http
.
StatusOK
,
true
)
c
.
JSON
(
http
.
StatusOK
,
true
)
...
...
server/resource.go
View file @
d947a512
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
func
(
s
*
Server
)
registerResourceRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
Server
)
registerResourceRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
err
:=
c
.
Request
()
.
ParseMultipartForm
(
5
<<
20
)
err
:=
c
.
Request
()
.
ParseMultipartForm
(
5
<<
20
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -44,7 +44,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -44,7 +44,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
Type
:
filetype
,
Type
:
filetype
,
Size
:
size
,
Size
:
size
,
Blob
:
fileBytes
,
Blob
:
fileBytes
,
CreatorI
d
:
userId
,
CreatorI
D
:
userID
,
}
}
resource
,
err
:=
s
.
ResourceService
.
CreateResource
(
resourceCreate
)
resource
,
err
:=
s
.
ResourceService
.
CreateResource
(
resourceCreate
)
...
@@ -54,16 +54,16 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -54,16 +54,16 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
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
(
resource
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
resource
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode
shortcut
response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode
resource
response"
)
.
SetInternal
(
err
)
}
}
return
nil
return
nil
})
})
g
.
GET
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
resourceFind
:=
&
api
.
ResourceFind
{
resourceFind
:=
&
api
.
ResourceFind
{
CreatorI
d
:
&
userId
,
CreatorI
D
:
&
userID
,
}
}
list
,
err
:=
s
.
ResourceService
.
FindResourceList
(
resourceFind
)
list
,
err
:=
s
.
ResourceService
.
FindResourceList
(
resourceFind
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -79,13 +79,13 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -79,13 +79,13 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
})
})
g
.
DELETE
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
resourceI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
resourceI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
resourceDelete
:=
&
api
.
ResourceDelete
{
resourceDelete
:=
&
api
.
ResourceDelete
{
I
d
:
resourceId
,
I
D
:
resourceID
,
}
}
if
err
:=
s
.
ResourceService
.
DeleteResource
(
resourceDelete
);
err
!=
nil
{
if
err
:=
s
.
ResourceService
.
DeleteResource
(
resourceDelete
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to delete resource"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to delete resource"
)
.
SetInternal
(
err
)
...
...
server/shortcut.go
View file @
d947a512
...
@@ -12,9 +12,9 @@ import (
...
@@ -12,9 +12,9 @@ import (
func
(
s
*
Server
)
registerShortcutRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
Server
)
registerShortcutRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
shortcutCreate
:=
&
api
.
ShortcutCreate
{
shortcutCreate
:=
&
api
.
ShortcutCreate
{
CreatorI
d
:
userId
,
CreatorI
D
:
userID
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutCreate
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutCreate
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post shortcut request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post shortcut request"
)
.
SetInternal
(
err
)
...
@@ -34,13 +34,13 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -34,13 +34,13 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
})
})
g
.
PATCH
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
shortcutI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
shortcutI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
}
}
shortcutPatch
:=
&
api
.
ShortcutPatch
{
shortcutPatch
:=
&
api
.
ShortcutPatch
{
I
d
:
shortcutId
,
I
D
:
shortcutID
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutPatch
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutPatch
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch shortcut request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch shortcut request"
)
.
SetInternal
(
err
)
...
@@ -60,9 +60,9 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -60,9 +60,9 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
})
})
g
.
GET
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
shortcutFind
:=
&
api
.
ShortcutFind
{
shortcutFind
:=
&
api
.
ShortcutFind
{
CreatorI
d
:
&
userId
,
CreatorI
D
:
&
userID
,
}
}
list
,
err
:=
s
.
ShortcutService
.
FindShortcutList
(
shortcutFind
)
list
,
err
:=
s
.
ShortcutService
.
FindShortcutList
(
shortcutFind
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -78,17 +78,17 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -78,17 +78,17 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
})
})
g
.
GET
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
shortcutI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
shortcutI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
}
}
shortcutFind
:=
&
api
.
ShortcutFind
{
shortcutFind
:=
&
api
.
ShortcutFind
{
I
d
:
&
shortcutId
,
I
D
:
&
shortcutID
,
}
}
shortcut
,
err
:=
s
.
ShortcutService
.
FindShortcut
(
shortcutFind
)
shortcut
,
err
:=
s
.
ShortcutService
.
FindShortcut
(
shortcutFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch shortcut"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to fetch shortcut by ID %d"
,
*
shortcutFind
.
ID
)
)
.
SetInternal
(
err
)
}
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
...
@@ -100,13 +100,13 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -100,13 +100,13 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
})
})
g
.
DELETE
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
shortcutI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
shortcutI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
}
}
shortcutDelete
:=
&
api
.
ShortcutDelete
{
shortcutDelete
:=
&
api
.
ShortcutDelete
{
I
d
:
shortcutId
,
I
D
:
shortcutID
,
}
}
if
err
:=
s
.
ShortcutService
.
DeleteShortcut
(
shortcutDelete
);
err
!=
nil
{
if
err
:=
s
.
ShortcutService
.
DeleteShortcut
(
shortcutDelete
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to delete shortcut"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to delete shortcut"
)
.
SetInternal
(
err
)
...
...
server/user.go
View file @
d947a512
...
@@ -2,6 +2,7 @@ package server
...
@@ -2,6 +2,7 @@ package server
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"memos/api"
"memos/api"
"memos/common"
"memos/common"
"net/http"
"net/http"
...
@@ -13,14 +14,14 @@ import (
...
@@ -13,14 +14,14 @@ import (
func
(
s
*
Server
)
registerUserRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
Server
)
registerUserRoutes
(
g
*
echo
.
Group
)
{
// GET /api/user/me is used to check if the user is logged in.
// GET /api/user/me is used to check if the user is logged in.
g
.
GET
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
userSessionI
d
:=
c
.
Get
(
getUserId
ContextKey
())
userSessionI
D
:=
c
.
Get
(
getUserID
ContextKey
())
if
userSessionI
d
==
nil
{
if
userSessionI
D
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing
auth
session"
)
}
}
userI
d
:=
userSessionId
.
(
int
)
userI
D
:=
userSessionID
.
(
int
)
userFind
:=
&
api
.
UserFind
{
userFind
:=
&
api
.
UserFind
{
I
d
:
&
userId
,
I
D
:
&
userID
,
}
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -42,7 +43,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -42,7 +43,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
}
}
if
userRenameCheck
.
Name
==
""
{
if
userRenameCheck
.
Name
==
""
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"
Malformatted post user rename check request
"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"
New name needed
"
)
}
}
userFind
:=
&
api
.
UserFind
{
userFind
:=
&
api
.
UserFind
{
...
@@ -50,7 +51,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -50,7 +51,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
}
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find user by name %s"
,
*
userFind
.
Name
)
)
.
SetInternal
(
err
)
}
}
isUsable
:=
true
isUsable
:=
true
...
@@ -67,22 +68,22 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -67,22 +68,22 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
})
})
g
.
POST
(
"/user/password_check"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/user/password_check"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
userPasswordCheck
:=
&
api
.
UserPasswordCheck
{}
userPasswordCheck
:=
&
api
.
UserPasswordCheck
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPasswordCheck
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPasswordCheck
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post user password check request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post user password check request"
)
.
SetInternal
(
err
)
}
}
if
userPasswordCheck
.
Password
==
""
{
if
userPasswordCheck
.
Password
==
""
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"
Malformatted post user password check request
"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"
Password needed
"
)
}
}
userFind
:=
&
api
.
UserFind
{
userFind
:=
&
api
.
UserFind
{
I
d
:
&
userId
,
I
D
:
&
userID
,
}
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user
by password
"
)
.
SetInternal
(
err
)
}
}
isValid
:=
false
isValid
:=
false
...
@@ -100,17 +101,17 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -100,17 +101,17 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
})
})
g
.
PATCH
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
userI
d
:=
c
.
Get
(
getUserId
ContextKey
())
.
(
int
)
userI
D
:=
c
.
Get
(
getUserID
ContextKey
())
.
(
int
)
userPatch
:=
&
api
.
UserPatch
{
userPatch
:=
&
api
.
UserPatch
{
I
d
:
userId
,
I
D
:
userID
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPatch
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPatch
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch user request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch user request"
)
.
SetInternal
(
err
)
}
}
if
userPatch
.
ResetOpenI
d
!=
nil
&&
*
userPatch
.
ResetOpenId
{
if
userPatch
.
ResetOpenI
D
!=
nil
&&
*
userPatch
.
ResetOpenID
{
openI
d
:=
common
.
GenUUID
()
openI
D
:=
common
.
GenUUID
()
userPatch
.
OpenI
d
=
&
openId
userPatch
.
OpenI
D
=
&
openID
}
}
if
userPatch
.
Password
!=
nil
&&
*
userPatch
.
Password
!=
""
{
if
userPatch
.
Password
!=
nil
&&
*
userPatch
.
Password
!=
""
{
...
...
server/webhook.go
View file @
d947a512
...
@@ -16,21 +16,21 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
...
@@ -16,21 +16,21 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
})
})
g
.
POST
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
openI
d
:=
c
.
Param
(
"openId"
)
openI
D
:=
c
.
Param
(
"openId"
)
userFind
:=
&
api
.
UserFind
{
userFind
:=
&
api
.
UserFind
{
OpenI
d
:
&
openId
,
OpenI
D
:
&
openID
,
}
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by open_id"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by open_id"
)
.
SetInternal
(
err
)
}
}
if
user
==
nil
{
if
user
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"User openId not found: %s"
,
openI
d
))
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"User openId not found: %s"
,
openI
D
))
}
}
memoCreate
:=
&
api
.
MemoCreate
{
memoCreate
:=
&
api
.
MemoCreate
{
CreatorI
d
:
user
.
Id
,
CreatorI
D
:
user
.
ID
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoCreate
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoCreate
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo request by open api"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo request by open api"
)
.
SetInternal
(
err
)
...
@@ -50,21 +50,21 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
...
@@ -50,21 +50,21 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
})
})
g
.
GET
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
openI
d
:=
c
.
Param
(
"openId"
)
openI
D
:=
c
.
Param
(
"openId"
)
userFind
:=
&
api
.
UserFind
{
userFind
:=
&
api
.
UserFind
{
OpenI
d
:
&
openId
,
OpenI
D
:
&
openID
,
}
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by open_id"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by open_id"
)
.
SetInternal
(
err
)
}
}
if
user
==
nil
{
if
user
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Unauthorized: %s"
,
openI
d
))
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Unauthorized: %s"
,
openI
D
))
}
}
memoFind
:=
&
api
.
MemoFind
{
memoFind
:=
&
api
.
MemoFind
{
CreatorI
d
:
&
user
.
Id
,
CreatorI
D
:
&
user
.
ID
,
}
}
rowStatus
:=
c
.
QueryParam
(
"rowStatus"
)
rowStatus
:=
c
.
QueryParam
(
"rowStatus"
)
if
rowStatus
!=
""
{
if
rowStatus
!=
""
{
...
@@ -85,7 +85,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
...
@@ -85,7 +85,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
})
})
g
.
GET
(
"/r/:resourceId/:filename"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/r/:resourceId/:filename"
,
func
(
c
echo
.
Context
)
error
{
resourceI
d
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
resourceI
D
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -93,13 +93,13 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
...
@@ -93,13 +93,13 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
filename
:=
c
.
Param
(
"filename"
)
filename
:=
c
.
Param
(
"filename"
)
resourceFind
:=
&
api
.
ResourceFind
{
resourceFind
:=
&
api
.
ResourceFind
{
I
d
:
&
resourceId
,
I
D
:
&
resourceID
,
Filename
:
&
filename
,
Filename
:
&
filename
,
}
}
resource
,
err
:=
s
.
ResourceService
.
FindResource
(
resourceFind
)
resource
,
err
:=
s
.
ResourceService
.
FindResource
(
resourceFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to fetch resource ID: %v"
,
resourceI
d
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to fetch resource ID: %v"
,
resourceI
D
))
.
SetInternal
(
err
)
}
}
c
.
Response
()
.
Writer
.
WriteHeader
(
http
.
StatusOK
)
c
.
Response
()
.
Writer
.
WriteHeader
(
http
.
StatusOK
)
...
...
store/memo.go
View file @
d947a512
...
@@ -73,7 +73,7 @@ func createMemo(db *DB, create *api.MemoCreate) (*api.Memo, error) {
...
@@ -73,7 +73,7 @@ func createMemo(db *DB, create *api.MemoCreate) (*api.Memo, error) {
VALUES (?, ?)
VALUES (?, ?)
RETURNING id, creator_id, created_ts, updated_ts, content, row_status
RETURNING id, creator_id, created_ts, updated_ts, content, row_status
`
,
`
,
create
.
CreatorI
d
,
create
.
CreatorI
D
,
create
.
Content
,
create
.
Content
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -87,8 +87,8 @@ func createMemo(db *DB, create *api.MemoCreate) (*api.Memo, error) {
...
@@ -87,8 +87,8 @@ func createMemo(db *DB, create *api.MemoCreate) (*api.Memo, error) {
var
memo
api
.
Memo
var
memo
api
.
Memo
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
memo
.
I
d
,
&
memo
.
I
D
,
&
memo
.
CreatorI
d
,
&
memo
.
CreatorI
D
,
&
memo
.
CreatedTs
,
&
memo
.
CreatedTs
,
&
memo
.
UpdatedTs
,
&
memo
.
UpdatedTs
,
&
memo
.
Content
,
&
memo
.
Content
,
...
@@ -113,7 +113,7 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
...
@@ -113,7 +113,7 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
set
,
args
=
append
(
set
,
"created_ts = ?"
),
append
(
args
,
*
v
)
set
,
args
=
append
(
set
,
"created_ts = ?"
),
append
(
args
,
*
v
)
}
}
args
=
append
(
args
,
patch
.
I
d
)
args
=
append
(
args
,
patch
.
I
D
)
row
,
err
:=
db
.
Db
.
Query
(
`
row
,
err
:=
db
.
Db
.
Query
(
`
UPDATE memo
UPDATE memo
...
@@ -132,7 +132,7 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
...
@@ -132,7 +132,7 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
var
memo
api
.
Memo
var
memo
api
.
Memo
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
memo
.
I
d
,
&
memo
.
I
D
,
&
memo
.
CreatedTs
,
&
memo
.
CreatedTs
,
&
memo
.
UpdatedTs
,
&
memo
.
UpdatedTs
,
&
memo
.
Content
,
&
memo
.
Content
,
...
@@ -147,10 +147,10 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
...
@@ -147,10 +147,10 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
func
findMemoList
(
db
*
DB
,
find
*
api
.
MemoFind
)
([]
*
api
.
Memo
,
error
)
{
func
findMemoList
(
db
*
DB
,
find
*
api
.
MemoFind
)
([]
*
api
.
Memo
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
if
v
:=
find
.
I
d
;
v
!=
nil
{
if
v
:=
find
.
I
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
CreatorI
d
;
v
!=
nil
{
if
v
:=
find
.
CreatorI
D
;
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
{
if
v
:=
find
.
RowStatus
;
v
!=
nil
{
...
@@ -178,8 +178,8 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
...
@@ -178,8 +178,8 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
for
rows
.
Next
()
{
for
rows
.
Next
()
{
var
memo
api
.
Memo
var
memo
api
.
Memo
if
err
:=
rows
.
Scan
(
if
err
:=
rows
.
Scan
(
&
memo
.
I
d
,
&
memo
.
I
D
,
&
memo
.
CreatorI
d
,
&
memo
.
CreatorI
D
,
&
memo
.
CreatedTs
,
&
memo
.
CreatedTs
,
&
memo
.
UpdatedTs
,
&
memo
.
UpdatedTs
,
&
memo
.
Content
,
&
memo
.
Content
,
...
@@ -199,14 +199,14 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
...
@@ -199,14 +199,14 @@ func findMemoList(db *DB, find *api.MemoFind) ([]*api.Memo, error) {
}
}
func
deleteMemo
(
db
*
DB
,
delete
*
api
.
MemoDelete
)
error
{
func
deleteMemo
(
db
*
DB
,
delete
*
api
.
MemoDelete
)
error
{
result
,
err
:=
db
.
Db
.
Exec
(
`DELETE FROM memo WHERE id = ?`
,
delete
.
I
d
)
result
,
err
:=
db
.
Db
.
Exec
(
`DELETE FROM memo WHERE id = ?`
,
delete
.
I
D
)
if
err
!=
nil
{
if
err
!=
nil
{
return
FormatError
(
err
)
return
FormatError
(
err
)
}
}
rows
,
_
:=
result
.
RowsAffected
()
rows
,
_
:=
result
.
RowsAffected
()
if
rows
==
0
{
if
rows
==
0
{
return
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"memo ID not found: %d"
,
delete
.
I
d
)}
return
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"memo ID not found: %d"
,
delete
.
I
D
)}
}
}
return
nil
return
nil
...
...
store/resource.go
View file @
d947a512
...
@@ -71,7 +71,7 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
...
@@ -71,7 +71,7 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
create
.
Blob
,
create
.
Blob
,
create
.
Type
,
create
.
Type
,
create
.
Size
,
create
.
Size
,
create
.
CreatorI
d
,
create
.
CreatorI
D
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
...
@@ -84,7 +84,7 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
...
@@ -84,7 +84,7 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
var
resource
api
.
Resource
var
resource
api
.
Resource
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
resource
.
I
d
,
&
resource
.
I
D
,
&
resource
.
Filename
,
&
resource
.
Filename
,
&
resource
.
Blob
,
&
resource
.
Blob
,
&
resource
.
Type
,
&
resource
.
Type
,
...
@@ -101,10 +101,10 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
...
@@ -101,10 +101,10 @@ func createResource(db *DB, create *api.ResourceCreate) (*api.Resource, error) {
func
findResourceList
(
db
*
DB
,
find
*
api
.
ResourceFind
)
([]
*
api
.
Resource
,
error
)
{
func
findResourceList
(
db
*
DB
,
find
*
api
.
ResourceFind
)
([]
*
api
.
Resource
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
if
v
:=
find
.
I
d
;
v
!=
nil
{
if
v
:=
find
.
I
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
CreatorI
d
;
v
!=
nil
{
if
v
:=
find
.
CreatorI
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"creator_id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"creator_id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
Filename
;
v
!=
nil
{
if
v
:=
find
.
Filename
;
v
!=
nil
{
...
@@ -133,7 +133,7 @@ func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
...
@@ -133,7 +133,7 @@ func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
for
rows
.
Next
()
{
for
rows
.
Next
()
{
var
resource
api
.
Resource
var
resource
api
.
Resource
if
err
:=
rows
.
Scan
(
if
err
:=
rows
.
Scan
(
&
resource
.
I
d
,
&
resource
.
I
D
,
&
resource
.
Filename
,
&
resource
.
Filename
,
&
resource
.
Blob
,
&
resource
.
Blob
,
&
resource
.
Type
,
&
resource
.
Type
,
...
@@ -155,14 +155,14 @@ func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
...
@@ -155,14 +155,14 @@ func findResourceList(db *DB, find *api.ResourceFind) ([]*api.Resource, error) {
}
}
func
deleteResource
(
db
*
DB
,
delete
*
api
.
ResourceDelete
)
error
{
func
deleteResource
(
db
*
DB
,
delete
*
api
.
ResourceDelete
)
error
{
result
,
err
:=
db
.
Db
.
Exec
(
`DELETE FROM resource WHERE id = ?`
,
delete
.
I
d
)
result
,
err
:=
db
.
Db
.
Exec
(
`DELETE FROM resource WHERE id = ?`
,
delete
.
I
D
)
if
err
!=
nil
{
if
err
!=
nil
{
return
FormatError
(
err
)
return
FormatError
(
err
)
}
}
rows
,
_
:=
result
.
RowsAffected
()
rows
,
_
:=
result
.
RowsAffected
()
if
rows
==
0
{
if
rows
==
0
{
return
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"resource ID not found: %d"
,
delete
.
I
d
)}
return
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"resource ID not found: %d"
,
delete
.
I
D
)}
}
}
return
nil
return
nil
...
...
store/shortcut.go
View file @
d947a512
...
@@ -76,7 +76,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
...
@@ -76,7 +76,7 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
`
,
`
,
create
.
Title
,
create
.
Title
,
create
.
Payload
,
create
.
Payload
,
create
.
CreatorI
d
,
create
.
CreatorI
D
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -87,10 +87,10 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
...
@@ -87,10 +87,10 @@ func createShortcut(db *DB, create *api.ShortcutCreate) (*api.Shortcut, error) {
row
.
Next
()
row
.
Next
()
var
shortcut
api
.
Shortcut
var
shortcut
api
.
Shortcut
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
shortcut
.
I
d
,
&
shortcut
.
I
D
,
&
shortcut
.
Title
,
&
shortcut
.
Title
,
&
shortcut
.
Payload
,
&
shortcut
.
Payload
,
&
shortcut
.
CreatorI
d
,
&
shortcut
.
CreatorI
D
,
&
shortcut
.
CreatedTs
,
&
shortcut
.
CreatedTs
,
&
shortcut
.
UpdatedTs
,
&
shortcut
.
UpdatedTs
,
&
shortcut
.
RowStatus
,
&
shortcut
.
RowStatus
,
...
@@ -114,7 +114,7 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
...
@@ -114,7 +114,7 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
set
,
args
=
append
(
set
,
"row_status = ?"
),
append
(
args
,
*
v
)
set
,
args
=
append
(
set
,
"row_status = ?"
),
append
(
args
,
*
v
)
}
}
args
=
append
(
args
,
patch
.
I
d
)
args
=
append
(
args
,
patch
.
I
D
)
row
,
err
:=
db
.
Db
.
Query
(
`
row
,
err
:=
db
.
Db
.
Query
(
`
UPDATE shortcut
UPDATE shortcut
...
@@ -133,7 +133,7 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
...
@@ -133,7 +133,7 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
var
shortcut
api
.
Shortcut
var
shortcut
api
.
Shortcut
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
shortcut
.
I
d
,
&
shortcut
.
I
D
,
&
shortcut
.
Title
,
&
shortcut
.
Title
,
&
shortcut
.
Payload
,
&
shortcut
.
Payload
,
&
shortcut
.
CreatedTs
,
&
shortcut
.
CreatedTs
,
...
@@ -149,10 +149,10 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
...
@@ -149,10 +149,10 @@ func patchShortcut(db *DB, patch *api.ShortcutPatch) (*api.Shortcut, error) {
func
findShortcutList
(
db
*
DB
,
find
*
api
.
ShortcutFind
)
([]
*
api
.
Shortcut
,
error
)
{
func
findShortcutList
(
db
*
DB
,
find
*
api
.
ShortcutFind
)
([]
*
api
.
Shortcut
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
if
v
:=
find
.
I
d
;
v
!=
nil
{
if
v
:=
find
.
I
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
CreatorI
d
;
v
!=
nil
{
if
v
:=
find
.
CreatorI
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"creator_id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"creator_id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
Title
;
v
!=
nil
{
if
v
:=
find
.
Title
;
v
!=
nil
{
...
@@ -181,10 +181,10 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
...
@@ -181,10 +181,10 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
for
rows
.
Next
()
{
for
rows
.
Next
()
{
var
shortcut
api
.
Shortcut
var
shortcut
api
.
Shortcut
if
err
:=
rows
.
Scan
(
if
err
:=
rows
.
Scan
(
&
shortcut
.
I
d
,
&
shortcut
.
I
D
,
&
shortcut
.
Title
,
&
shortcut
.
Title
,
&
shortcut
.
Payload
,
&
shortcut
.
Payload
,
&
shortcut
.
CreatorI
d
,
&
shortcut
.
CreatorI
D
,
&
shortcut
.
CreatedTs
,
&
shortcut
.
CreatedTs
,
&
shortcut
.
UpdatedTs
,
&
shortcut
.
UpdatedTs
,
&
shortcut
.
RowStatus
,
&
shortcut
.
RowStatus
,
...
@@ -203,14 +203,14 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
...
@@ -203,14 +203,14 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) {
}
}
func
deleteShortcut
(
db
*
DB
,
delete
*
api
.
ShortcutDelete
)
error
{
func
deleteShortcut
(
db
*
DB
,
delete
*
api
.
ShortcutDelete
)
error
{
result
,
err
:=
db
.
Db
.
Exec
(
`DELETE FROM shortcut WHERE id = ?`
,
delete
.
I
d
)
result
,
err
:=
db
.
Db
.
Exec
(
`DELETE FROM shortcut WHERE id = ?`
,
delete
.
I
D
)
if
err
!=
nil
{
if
err
!=
nil
{
return
FormatError
(
err
)
return
FormatError
(
err
)
}
}
rows
,
_
:=
result
.
RowsAffected
()
rows
,
_
:=
result
.
RowsAffected
()
if
rows
==
0
{
if
rows
==
0
{
return
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"shortcut ID not found: %d"
,
delete
.
I
d
)}
return
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"shortcut ID not found: %d"
,
delete
.
I
D
)}
}
}
return
nil
return
nil
...
...
store/user.go
View file @
d947a512
...
@@ -60,7 +60,7 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
...
@@ -60,7 +60,7 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
`
,
`
,
create
.
Name
,
create
.
Name
,
create
.
PasswordHash
,
create
.
PasswordHash
,
create
.
OpenI
d
,
create
.
OpenI
D
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
...
@@ -70,10 +70,10 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
...
@@ -70,10 +70,10 @@ func createUser(db *DB, create *api.UserCreate) (*api.User, error) {
row
.
Next
()
row
.
Next
()
var
user
api
.
User
var
user
api
.
User
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
user
.
I
d
,
&
user
.
I
D
,
&
user
.
Name
,
&
user
.
Name
,
&
user
.
PasswordHash
,
&
user
.
PasswordHash
,
&
user
.
OpenI
d
,
&
user
.
OpenI
D
,
&
user
.
CreatedTs
,
&
user
.
CreatedTs
,
&
user
.
UpdatedTs
,
&
user
.
UpdatedTs
,
);
err
!=
nil
{
);
err
!=
nil
{
...
@@ -92,11 +92,11 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
...
@@ -92,11 +92,11 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
if
v
:=
patch
.
PasswordHash
;
v
!=
nil
{
if
v
:=
patch
.
PasswordHash
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"password_hash = ?"
),
append
(
args
,
v
)
set
,
args
=
append
(
set
,
"password_hash = ?"
),
append
(
args
,
v
)
}
}
if
v
:=
patch
.
OpenI
d
;
v
!=
nil
{
if
v
:=
patch
.
OpenI
D
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"open_id = ?"
),
append
(
args
,
v
)
set
,
args
=
append
(
set
,
"open_id = ?"
),
append
(
args
,
v
)
}
}
args
=
append
(
args
,
patch
.
I
d
)
args
=
append
(
args
,
patch
.
I
D
)
row
,
err
:=
db
.
Db
.
Query
(
`
row
,
err
:=
db
.
Db
.
Query
(
`
UPDATE user
UPDATE user
...
@@ -112,10 +112,10 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
...
@@ -112,10 +112,10 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
if
row
.
Next
()
{
if
row
.
Next
()
{
var
user
api
.
User
var
user
api
.
User
if
err
:=
row
.
Scan
(
if
err
:=
row
.
Scan
(
&
user
.
I
d
,
&
user
.
I
D
,
&
user
.
Name
,
&
user
.
Name
,
&
user
.
PasswordHash
,
&
user
.
PasswordHash
,
&
user
.
OpenI
d
,
&
user
.
OpenI
D
,
&
user
.
CreatedTs
,
&
user
.
CreatedTs
,
&
user
.
UpdatedTs
,
&
user
.
UpdatedTs
,
);
err
!=
nil
{
);
err
!=
nil
{
...
@@ -125,19 +125,19 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
...
@@ -125,19 +125,19 @@ func patchUser(db *DB, patch *api.UserPatch) (*api.User, error) {
return
&
user
,
nil
return
&
user
,
nil
}
}
return
nil
,
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"user ID not found: %d"
,
patch
.
I
d
)}
return
nil
,
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"user ID not found: %d"
,
patch
.
I
D
)}
}
}
func
findUserList
(
db
*
DB
,
find
*
api
.
UserFind
)
([]
*
api
.
User
,
error
)
{
func
findUserList
(
db
*
DB
,
find
*
api
.
UserFind
)
([]
*
api
.
User
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
if
v
:=
find
.
I
d
;
v
!=
nil
{
if
v
:=
find
.
I
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"id = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
Name
;
v
!=
nil
{
if
v
:=
find
.
Name
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"name = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"name = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
OpenI
d
;
v
!=
nil
{
if
v
:=
find
.
OpenI
D
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"open_id = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"open_id = ?"
),
append
(
args
,
*
v
)
}
}
...
@@ -162,10 +162,10 @@ func findUserList(db *DB, find *api.UserFind) ([]*api.User, error) {
...
@@ -162,10 +162,10 @@ func findUserList(db *DB, find *api.UserFind) ([]*api.User, error) {
for
rows
.
Next
()
{
for
rows
.
Next
()
{
var
user
api
.
User
var
user
api
.
User
if
err
:=
rows
.
Scan
(
if
err
:=
rows
.
Scan
(
&
user
.
I
d
,
&
user
.
I
D
,
&
user
.
Name
,
&
user
.
Name
,
&
user
.
PasswordHash
,
&
user
.
PasswordHash
,
&
user
.
OpenI
d
,
&
user
.
OpenI
D
,
&
user
.
CreatedTs
,
&
user
.
CreatedTs
,
&
user
.
UpdatedTs
,
&
user
.
UpdatedTs
,
);
err
!=
nil
{
);
err
!=
nil
{
...
...
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