Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegsuus committed Jun 19, 2024
1 parent de51d28 commit 13fed01
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
5 changes: 1 addition & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import (
"news-api/internal/app"
"news-api/internal/config"
"news-api/internal/database"
"news-api/internal/migrations"
)

func main() {
cfg := config.GetConfig()
db := database.NewDB(cfg)
defer db.Close()

migrations.MigrateUp(db.DB)
migrations.Migrations(cfg, db.DB)

app := &app.App{
Config: cfg,
Expand Down
60 changes: 48 additions & 12 deletions internal/models/models.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
package models

import (
"time"
)

// News представляет структуру новости.
type News struct {
ID int64 `reform:"id,pk" json:"id"`
Title string `reform:"title" json:"title"`
Content string `reform:"content" json:"content"`
CreatedAt time.Time `reform:"created_at" json:"created_at"`
UpdatedAt time.Time `reform:"updated_at" json:"updated_at"`
ID int64 `reform:"id,pk" json:"id"`
Title string `reform:"title" json:"title"`
Content string `reform:"content" json:"content"`
}

// Implementing reform.View interface
func (*News) Schema() string {
return "public"
}

func (*News) String() string {
return "News"
}

// NewsTable is the reform table identifier for News.
const NewsTable = "news"
// Implementing reform.Record interface
func (n *News) String() string {
return "News"
}

func (n *News) Values() []interface{} {
return []interface{}{n.ID, n.Title, n.Content}
}

func (n *News) PKPointer() interface{} {
return &n.ID
}

// NewsCategory represents the relationship between news and categories.
// NewsCategory представляет связь между новостью и категорией.
type NewsCategory struct {
NewsID int64 `reform:"news_id,pk" json:"news_id"`
CategoryID int64 `reform:"category_id,pk" json:"category_id"`
}

// Implementing reform.View interface
func (*NewsCategory) Schema() string {
return "public"
}

func (*NewsCategory) String() string {
return "NewsCategory"
}

// Implementing reform.Record interface
func (nc *NewsCategory) String() string {
return "NewsCategory"
}

func (nc *NewsCategory) Values() []interface{} {
return []interface{}{nc.NewsID, nc.CategoryID}
}

func (nc *NewsCategory) PKPointer() interface{} {
return &nc.NewsID
}

0 comments on commit 13fed01

Please sign in to comment.