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

33
web/api/account.go Normal file
View file

@ -0,0 +1,33 @@
package api
import (
"git.sleepycat.moe/sam/mercury/internal/database"
"github.com/oklog/ulid/v2"
)
// Account is the basic user returned by endpoints, without any private data.
type Account struct {
ID ulid.ULID `json:"id"`
Username string `json:"username"`
Domain *string `json:"domain"`
}
type SelfAccount struct {
Account
Email string `json:"email"`
}
func DBAccountToAccount(a database.Account) Account {
return Account{
ID: a.ID,
Username: a.Username,
Domain: a.Domain,
}
}
func DBAccountToSelfAccount(a database.Account) SelfAccount {
return SelfAccount{
Account: DBAccountToAccount(a),
Email: *a.Email,
}
}