add API boilerplate + /accounts/{accountID} and /accounts/@me endpoints

This commit is contained in:
sam 2023-09-06 02:23:06 +02:00
parent 0fa769a248
commit dfc116d828
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
7 changed files with 335 additions and 0 deletions

View file

@ -1,6 +1,9 @@
package web
import (
"git.sleepycat.moe/sam/mercury/internal/database"
"git.sleepycat.moe/sam/mercury/web/api"
"git.sleepycat.moe/sam/mercury/web/api/accounts"
"git.sleepycat.moe/sam/mercury/web/app"
"git.sleepycat.moe/sam/mercury/web/auth"
"git.sleepycat.moe/sam/mercury/web/frontend"
@ -31,4 +34,14 @@ func Routes(app *app.App) {
r.HandleFunc("/web/@{username}", frontend.ServeUser)
r.HandleFunc("/web/@{username}/posts/{postID}", frontend.ServeStatus)
})
// APIv1 handlers
app.Router.Route("/api/v1", func(r chi.Router) {
// account handlers
accounts := accounts.New(app)
r.With(app.APIAuth(database.TokenScopeAccountsRead, true)).
Get("/accounts/{accountID}", api.WrapHandlerT(accounts.GetID))
r.With(app.APIAuth(database.TokenScopeAccountsMe, false)).
Get("/accounts/@me", api.WrapHandlerT(accounts.GetMe))
})
}