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
8f76120e
Commit
8f76120e
authored
Mar 28, 2022
by
email
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: clean server
parent
3c06c686
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
51 deletions
+21
-51
memo.go
api/memo.go
+1
-0
error.go
common/error.go
+0
-23
auth.go
server/auth.go
+9
-8
memo.go
server/memo.go
+3
-9
webhook.go
server/webhook.go
+3
-9
memo.go
store/memo.go
+3
-0
api.ts
web/src/helpers/api.ts
+2
-2
No files found.
api/memo.go
View file @
8f76120e
...
...
@@ -21,6 +21,7 @@ type MemoPatch struct {
Content
*
string
`json:"content"`
RowStatus
*
string
`json:"rowStatus"`
CreatedTs
*
int64
`json:"createdTs"`
}
type
MemoFind
struct
{
...
...
common/error.go
View file @
8f76120e
...
...
@@ -22,29 +22,6 @@ const (
DbConnectionFailure
Code
=
101
DbStatementSyntaxError
Code
=
102
DbExecutionError
Code
=
103
// 201 db migration error
// Db migration is a core feature, so we separate it from the db error
MigrationSchemaMissing
Code
=
201
MigrationAlreadyApplied
Code
=
202
MigrationOutOfOrder
Code
=
203
MigrationBaselineMissing
Code
=
204
// 301 task error
TaskTimingNotAllowed
Code
=
301
// 10001 advisor error code
CompatibilityDropDatabase
Code
=
10001
CompatibilityRenameTable
Code
=
10002
CompatibilityDropTable
Code
=
10003
CompatibilityRenameColumn
Code
=
10004
CompatibilityDropColumn
Code
=
10005
CompatibilityAddPrimaryKey
Code
=
10006
CompatibilityAddUniqueKey
Code
=
10007
CompatibilityAddForeignKey
Code
=
10008
CompatibilityAddCheck
Code
=
10009
CompatibilityAlterCheck
Code
=
10010
CompatibilityAlterColumn
Code
=
10011
)
// Error represents an application-specific error. Application errors can be
...
...
server/auth.go
View file @
8f76120e
...
...
@@ -23,10 +23,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to authenticate user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find user by name %s"
,
login
.
Name
)
)
.
SetInternal
(
err
)
}
if
user
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"User not found
:
%s"
,
login
.
Name
))
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"User not found
with name
%s"
,
login
.
Name
))
}
// Compare the stored hashed password, with the hashed version of the password that was received.
...
...
@@ -35,8 +35,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Incorrect password"
)
.
SetInternal
(
err
)
}
err
=
setUserSession
(
c
,
user
)
if
err
!=
nil
{
if
err
=
setUserSession
(
c
,
user
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to set login session"
)
.
SetInternal
(
err
)
}
...
...
@@ -64,10 +63,12 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted signup request"
)
.
SetInternal
(
err
)
}
if
len
(
signup
.
Name
)
<=
5
{
// Validate signup form.
// We can do stricter checks later.
if
len
(
signup
.
Name
)
<
6
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Username is too short, minimum length is 6."
)
}
if
len
(
signup
.
Password
)
<
=
5
{
if
len
(
signup
.
Password
)
<
6
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Password is too short, minimum length is 6."
)
}
...
...
@@ -76,10 +77,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
}
user
,
err
:=
s
.
UserService
.
FindUser
(
userFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to authenticate user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find user by name %s"
,
signup
.
Name
)
)
.
SetInternal
(
err
)
}
if
user
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
Status
Unauthorized
,
fmt
.
Sprintf
(
"Existed user found: %s"
,
signup
.
Name
))
return
echo
.
NewHTTPError
(
http
.
Status
BadRequest
,
fmt
.
Sprintf
(
"Existed user found: %s"
,
signup
.
Name
))
}
passwordHash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
signup
.
Password
),
bcrypt
.
DefaultCost
)
...
...
server/memo.go
View file @
8f76120e
...
...
@@ -65,16 +65,10 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
memoFind
:=
&
api
.
MemoFind
{
CreatorId
:
&
userId
,
}
showHiddenMemo
,
err
:=
strconv
.
ParseBool
(
c
.
QueryParam
(
"hidden"
))
if
err
!=
nil
{
showHiddenMemo
=
false
}
rowStatus
:=
"NORMAL"
if
showHiddenMemo
{
rowStatus
=
"HIDDEN"
}
rowStatus
:=
c
.
QueryParam
(
"rowStatus"
)
if
rowStatus
!=
""
{
memoFind
.
RowStatus
=
&
rowStatus
}
list
,
err
:=
s
.
MemoService
.
FindMemoList
(
memoFind
)
if
err
!=
nil
{
...
...
server/webhook.go
View file @
8f76120e
...
...
@@ -66,16 +66,10 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
memoFind
:=
&
api
.
MemoFind
{
CreatorId
:
&
user
.
Id
,
}
showHiddenMemo
,
err
:=
strconv
.
ParseBool
(
c
.
QueryParam
(
"hidden"
))
if
err
!=
nil
{
showHiddenMemo
=
false
}
rowStatus
:=
"NORMAL"
if
showHiddenMemo
{
rowStatus
=
"HIDDEN"
}
rowStatus
:=
c
.
QueryParam
(
"rowStatus"
)
if
rowStatus
!=
""
{
memoFind
.
RowStatus
=
&
rowStatus
}
list
,
err
:=
s
.
MemoService
.
FindMemoList
(
memoFind
)
if
err
!=
nil
{
...
...
store/memo.go
View file @
8f76120e
...
...
@@ -109,6 +109,9 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
if
v
:=
patch
.
RowStatus
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"row_status = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
patch
.
CreatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"created_ts = ?"
),
append
(
args
,
*
v
)
}
args
=
append
(
args
,
patch
.
Id
)
...
...
web/src/helpers/api.ts
View file @
8f76120e
...
...
@@ -113,14 +113,14 @@ namespace api {
export
function
getMyMemos
()
{
return
request
<
Model
.
Memo
[]
>
({
method
:
"GET"
,
url
:
"/api/memo"
,
url
:
"/api/memo
?rowStatus=NORMAL
"
,
});
}
export
function
getMyDeletedMemos
()
{
return
request
<
Model
.
Memo
[]
>
({
method
:
"GET"
,
url
:
"/api/memo?
hidden=true
"
,
url
:
"/api/memo?
rowStatus=HIDDEN
"
,
});
}
...
...
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