templ per komponen, scroll horizontal
This commit is contained in:
80
services/landingpage.services.go
Normal file
80
services/landingpage.services.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/emarifer/go-templ-project-structure/db"
|
||||
)
|
||||
|
||||
func NewServicesLandingPage(u LandingPage, uStore db.XsampleStore) *ServiceLandingPage {
|
||||
|
||||
return &ServiceLandingPage{
|
||||
LandingPage: u,
|
||||
XsampleStore: uStore,
|
||||
}
|
||||
}
|
||||
|
||||
type LandingPage struct {
|
||||
ID int `json:"id"`
|
||||
Xsamplename string `json:"Xsamplename"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
}
|
||||
|
||||
type ServiceLandingPage struct {
|
||||
LandingPage LandingPage
|
||||
XsampleStore db.XsampleStore
|
||||
}
|
||||
|
||||
func (su *ServiceLandingPage) GetAllXsamples() ([]LandingPage, error) {
|
||||
query := `SELECT id, Xsamplename, email, created_at FROM Xsamples ORDER BY created_at DESC`
|
||||
|
||||
rows, err := su.XsampleStore.Db.Query(query)
|
||||
if err != nil {
|
||||
return []LandingPage{}, err
|
||||
}
|
||||
// We close the resource
|
||||
defer rows.Close()
|
||||
|
||||
Xsamples := []LandingPage{}
|
||||
for rows.Next() {
|
||||
rows.Scan(
|
||||
&su.LandingPage.ID,
|
||||
&su.LandingPage.Xsamplename,
|
||||
&su.LandingPage.Email,
|
||||
&su.LandingPage.CreatedAt,
|
||||
)
|
||||
|
||||
Xsamples = append(Xsamples, su.LandingPage)
|
||||
}
|
||||
|
||||
return Xsamples, nil
|
||||
}
|
||||
|
||||
func (su *ServiceLandingPage) GetXsampleById(id int) (LandingPage, error) {
|
||||
|
||||
query := `SELECT id, Xsamplename, email, created_at FROM Xsamples
|
||||
WHERE id = ?`
|
||||
|
||||
stmt, err := su.XsampleStore.Db.Prepare(query)
|
||||
if err != nil {
|
||||
return LandingPage{}, err
|
||||
}
|
||||
|
||||
defer stmt.Close()
|
||||
|
||||
su.LandingPage.ID = id
|
||||
err = stmt.QueryRow(
|
||||
su.LandingPage.ID,
|
||||
).Scan(
|
||||
&su.LandingPage.ID,
|
||||
&su.LandingPage.Xsamplename,
|
||||
&su.LandingPage.Email,
|
||||
&su.LandingPage.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return LandingPage{}, err
|
||||
}
|
||||
|
||||
return su.LandingPage, nil
|
||||
}
|
||||
Reference in New Issue
Block a user