feat(api): add PATCH /users/@me/fields, finish POST /auth/discord/callback
This commit is contained in:
parent
020ac15a00
commit
52a03b4aa6
9 changed files with 261 additions and 17 deletions
|
@ -1,12 +1,14 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"codeberg.org/u1f320/pronouns.cc/backend/db"
|
||||
"codeberg.org/u1f320/pronouns.cc/backend/server/auth"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
// Revision is the git commit, filled at build time
|
||||
|
@ -39,6 +41,23 @@ func New() (*Server, error) {
|
|||
// enable authentication for all routes (but don't require it)
|
||||
s.Router.Use(s.maybeAuth)
|
||||
|
||||
// return an API error for not found + method not allowed
|
||||
s.Router.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
render.Status(r, errCodeStatuses[ErrNotFound])
|
||||
render.JSON(w, r, APIError{
|
||||
Code: ErrNotFound,
|
||||
Message: errCodeMessages[ErrNotFound],
|
||||
})
|
||||
})
|
||||
|
||||
s.Router.MethodNotAllowed(func(w http.ResponseWriter, r *http.Request) {
|
||||
render.Status(r, errCodeStatuses[ErrMethodNotAllowed])
|
||||
render.JSON(w, r, APIError{
|
||||
Code: ErrMethodNotAllowed,
|
||||
Message: errCodeMessages[ErrMethodNotAllowed],
|
||||
})
|
||||
})
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue