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
c77996a8
Commit
c77996a8
authored
Feb 05, 2022
by
email
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: open api for get memos
parent
017bbfa6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
6 deletions
+48
-6
auth.go
server/auth.go
+1
-2
basic_auth.go
server/basic_auth.go
+4
-3
memo.go
server/memo.go
+2
-1
webhook.go
server/webhook.go
+41
-0
No files found.
server/auth.go
View file @
c77996a8
...
...
@@ -30,8 +30,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
// Compare the stored password
if
login
.
Password
!=
user
.
Password
{
// If the two passwords don't match, return a 401 status.
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Incorrect password"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Incorrect password"
)
.
SetInternal
(
err
)
}
err
=
setUserSession
(
c
,
user
)
...
...
server/basic_auth.go
View file @
c77996a8
...
...
@@ -72,14 +72,14 @@ func BasicAuthMiddleware(us api.UserService, next echo.HandlerFunc) echo.Handler
userId
,
err
:=
strconv
.
Atoi
(
fmt
.
Sprintf
(
"%v"
,
userIdValue
))
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
Status
Unauthorized
,
"Failed to malformatted user id in the session."
)
return
echo
.
NewHTTPError
(
http
.
Status
InternalServerError
,
"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.
principal
Find
:=
&
api
.
UserFind
{
user
Find
:=
&
api
.
UserFind
{
Id
:
&
userId
,
}
user
,
err
:=
us
.
FindUser
(
principal
Find
)
user
,
err
:=
us
.
FindUser
(
user
Find
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find user by ID: %d"
,
userId
))
.
SetInternal
(
err
)
}
...
...
@@ -89,6 +89,7 @@ func BasicAuthMiddleware(us api.UserService, next echo.HandlerFunc) echo.Handler
// Stores userId into context.
c
.
Set
(
getUserIdContextKey
(),
userId
)
return
next
(
c
)
}
}
server/memo.go
View file @
c77996a8
...
...
@@ -98,8 +98,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
memo
,
err
:=
s
.
MemoService
.
FindMemo
(
memoFind
)
if
err
!=
nil
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoId
))
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoId
))
.
SetInternal
(
err
)
}
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to delete memo ID: %v"
,
memoId
))
.
SetInternal
(
err
)
}
...
...
server/webhook.go
View file @
c77996a8
...
...
@@ -47,6 +47,47 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
openId
:=
c
.
Param
(
"openId"
)
userFind
:=
&
api
.
UserFind
{
OpenId
:
&
openId
,
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by open_id"
)
.
SetInternal
(
err
)
}
if
user
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Unauthorized: %s"
,
openId
))
}
memoFind
:=
&
api
.
MemoFind
{
CreatorId
:
&
user
.
Id
,
}
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
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch memo list"
)
.
SetInternal
(
err
)
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
list
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo list response"
)
.
SetInternal
(
err
)
}
return
nil
})
g
.
GET
(
"/r/:resourceId/:filename"
,
func
(
c
echo
.
Context
)
error
{
resourceId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
if
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