Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make shorten api #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

make shorten api #5

wants to merge 4 commits into from

Conversation

Arashi-K
Copy link

No description provided.

@Arashi-K Arashi-K changed the title publish api key make functions to publish api key Dec 23, 2019
@Arashi-K Arashi-K changed the title make functions to publish api key make shorten api Dec 23, 2019
@Arashi-K Arashi-K self-assigned this Dec 23, 2019
@Arashi-K Arashi-K added the wip work in progress label Dec 23, 2019
@@ -12,6 +12,8 @@ func (web *Web) authenticate(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, _ := web.store.Get(r, "scvl")
userID, ok := session.Values["user_id"].(uint)
userID = 1
ok = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

Comment on lines 109 to 112
_, err = e.sqlClient.FindUserByAPIKey(req.APIKey)
if err != nil {
return
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if _, err = e.sqlClient.FindUserByAPIKey(req.APIKey); err != nil {
return
}

Comment on lines 118 to 121
err = e.sqlClient.CreatePage(page)
if err != nil {
return
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err = e.sqlClient.CreatePage(page); err != nil {
return
}

}

page = &domain.Page{
Slug: domain.GenerateSlug(5),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2箇所以上で使うんだったら定数を定義するのもあり。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

どの部分のことですか?

@@ -36,6 +36,8 @@ func (web *Web) Start(port string) error {
r.Handle("/", web.authenticate(web.rootHandler)).Methods(http.MethodGet)
r.Handle("/logout", web.authenticate(web.logoutHandler)).Methods(http.MethodPost)
r.Handle("/shorten", web.authenticate(web.shortenHandler)).Methods(http.MethodPost)
r.HandleFunc("/api/shorten", web.shortenByAPIHandler).Methods(http.MethodPost)
r.Handle("/api/publish", web.authenticate(web.publishAPIKeyHandler)).Methods(http.MethodPost)
Copy link

@ttexan1 ttexan1 Dec 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path名がこれだと(keyではなく)apiをpublishすることになりそう。
あと、RestでURLを考える場合は基本的に何をするかはAction(get post put delete)で定義されているから、Path中に動詞を入れると冗長になると言われている。
例えば /api/key とかの方がいいかも

@Arashi-K Arashi-K removed the wip work in progress label Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants