1
0
go-rss-aggregator/models.go
2023-09-09 14:39:32 +03:00

80 lines
1.8 KiB
Go

package main
import (
"time"
"git.rpuzonas.com/rpuzonas/go-rss-aggregator/internal/database"
)
type User struct {
ID int64 `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
ApiKey string `json:"api_key"`
}
type Feed struct {
ID int64 `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
Url string `json:"url"`
UserID int64 `json:"user_id"`
}
type FeedFollow struct {
ID int64 `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
UserID int64 `json:"user_id"`
FeedID int64 `json:"feed_id"`
}
func databaseUserToUser(dbUser database.User) User {
return User{
ID: dbUser.ID,
CreatedAt: dbUser.CreatedAt,
UpdatedAt: dbUser.UpdatedAt,
Name: dbUser.Name,
ApiKey: dbUser.ApiKey.String,
}
}
func databaseFeedToFeed(dbFeed database.Feed) Feed {
return Feed{
ID: dbFeed.ID,
CreatedAt: dbFeed.CreatedAt,
UpdatedAt: dbFeed.UpdatedAt,
Name: dbFeed.Name,
Url: dbFeed.Url,
UserID: dbFeed.UserID,
}
}
func databaseFeedsToFeeds(dbFeeds []database.Feed) []Feed {
feeds := make([]Feed, len(dbFeeds))
for i, dbFeed := range dbFeeds {
feeds[i] = databaseFeedToFeed(dbFeed)
}
return feeds
}
func databaseFeedFollowToFeedFollow(dbFeedFollow database.FeedFollow) FeedFollow {
return FeedFollow{
ID: dbFeedFollow.ID,
CreatedAt: dbFeedFollow.CreatedAt,
UpdatedAt: dbFeedFollow.UpdatedAt,
UserID: dbFeedFollow.UserID,
FeedID: dbFeedFollow.FeedID,
}
}
func databaseFolllowFeedsToFollowFeeds(dbFeedFollows []database.FeedFollow) []FeedFollow {
feeds := make([]FeedFollow, len(dbFeedFollows))
for i, dbFeed := range dbFeedFollows {
feeds[i] = databaseFeedFollowToFeedFollow(dbFeed)
}
return feeds
}