feat(accounts): added endpoint to fetch accounts of user

This commit is contained in:
overflowerror 2021-08-14 19:35:31 +02:00
parent ad9bbed9be
commit 7afad69041
5 changed files with 34 additions and 0 deletions

View file

@ -18,6 +18,8 @@ type Data interface {
UpdateTweet(tweet *models.Tweet) error
GetAccountsByUser(user *models.User) ([]models.Account, error)
GetScheduledThreads() ([]models.Thread, error)
GetTweetsForThread(thread *models.Thread) ([]models.Tweet, error)
UpdateThread(thread *models.Thread) error

View file

@ -5,4 +5,6 @@ import "threadule/backend/internal/data/models"
type Logic interface {
AuthenticateSession(token string) (*models.User, error)
Login(username, password string) (string, error)
GetAccounts(user *models.User) ([]models.Account, error)
}

View file

@ -0,0 +1,21 @@
package data
import "threadule/backend/internal/data/models"
func (d *Data) GetAccountsByUser(user *models.User) ([]models.Account, error) {
var accounts []models.Account
err := d.db.
Where("user_id = ?", user.ID).
Find(&accounts).
Error
if err != nil {
return nil, err
} else {
for i := range accounts {
accounts[i].AccessToken = nil
accounts[i].AccessTokenSecret = nil
}
return accounts, nil
}
}

View file

@ -0,0 +1,7 @@
package logic
import "threadule/backend/internal/data/models"
func (l *Logic) GetAccounts(user *models.User) ([]models.Account, error) {
return l.ctx.Data.GetAccountsByUser(user)
}

View file

@ -13,5 +13,7 @@ func Setup(ctx *app.Context) http.Handler {
router.POST("/authentication", Login)
router.GET("/authentication", authenticated(GetAuthenticationData))
router.GET("/account/", authenticated(GetAccounts))
return router
}