mirror of
https://github.com/sigmasternchen/threadule
synced 2025-03-15 08:09:01 +00:00
feat(accounts): added endpoint to fetch accounts of user
This commit is contained in:
parent
ad9bbed9be
commit
7afad69041
5 changed files with 34 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
21
backend/internal/data/account.go
Normal file
21
backend/internal/data/account.go
Normal 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
|
||||
}
|
||||
}
|
7
backend/internal/logic/account.go
Normal file
7
backend/internal/logic/account.go
Normal 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)
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue