Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookback #16

Merged
merged 11 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bookback/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ linters:
- bodyclose
- depguard
- dogsled
- dupl
# - dupl
- errcheck
- errorlint
- exportloopref
Expand Down
6 changes: 3 additions & 3 deletions bookback/cmd/bookback/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
appPkg "github.com/SShlykov/zeitment/bookback/internal/pkg/app"
pkg "github.com/SShlykov/zeitment/bookback/internal/bootstrap/app"
"os"
)

Expand All @@ -18,8 +18,8 @@ var configPath string
// @produces application/json
// @consumes application/json
func main() {
flag.StringVar(&configPath, "config", "./config/default.yml", "path to the configuration file")
app, err := appPkg.NewApp(configPath)
flag.StringVar(&configPath, "config", "./config", "path to the configuration files")
app, err := pkg.NewApp(configPath)
if err != nil {
fmt.Printf("failed to create app: %+v\n", err)
os.Exit(2)
Expand Down
12 changes: 0 additions & 12 deletions bookback/config/default.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
cors_enabled: true
shutdown_timeout: 10s
swagger:
enabled: true
http_server:
address: "0.0.0.0:7077"
timeout: 4s
iddle_timeout: 60s
request_limit: 100
min_requests: 10
error_threshold_percentage: 0.6
interval_duration: 10s
open_state_timeout: 10s
logger:
level: "debug"
12 changes: 12 additions & 0 deletions bookback/config/server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
address: "0.0.0.0:7077"
timeout: 4s
iddle_timeout: 60s

request_limit: 100
min_requests: 10
error_threshold_percentage: 0.6
interval_duration: 10s
open_state_timeout: 10s

cors_enabled: true
swagger_enabled: true
53 changes: 53 additions & 0 deletions bookback/internal/adapters/book.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package adapters

import (
"database/sql"
"github.com/SShlykov/zeitment/bookback/internal/domain/entity"
"github.com/SShlykov/zeitment/bookback/internal/models"
"github.com/SShlykov/zeitment/bookback/internal/models/types"
"time"
)

func BooksEntityToModel(books []*entity.Book) []*models.Book {
var result []*models.Book
for _, book := range books {
result = append(result, BookEntityToModel(book))
}
return result
}

func BookModelToEntity(book *models.Book) *entity.Book {
return &entity.Book{
ID: book.ID,
CreatedAt: book.CreatedAt,
UpdatedAt: book.UpdatedAt,
DeletedAt: sql.NullTime{Valid: book.DeletedAt.Valid, Time: book.DeletedAt.Value},
Owner: book.Owner,
Title: book.Title,
Author: book.Author,
Description: book.Description,
IsPublic: book.IsPublic,
Publication: sql.NullTime{Valid: book.Publication.Valid, Time: book.Publication.Value},
ImageLink: sql.NullString{Valid: book.ImageLink.Valid, String: book.ImageLink.Value},
MapLink: sql.NullString{Valid: book.MapLink.Valid, String: book.MapLink.Value},
Variables: book.Variables,
}
}

func BookEntityToModel(book *entity.Book) *models.Book {
return &models.Book{
ID: book.ID,
CreatedAt: book.CreatedAt,
UpdatedAt: book.UpdatedAt,
DeletedAt: types.Null[time.Time]{Valid: book.DeletedAt.Valid, Value: book.DeletedAt.Time},
Owner: book.Owner,
Title: book.Title,
Author: book.Author,
Description: book.Description,
IsPublic: book.IsPublic,
Publication: types.Null[time.Time]{Valid: book.Publication.Valid, Value: book.Publication.Time},
ImageLink: types.Null[string]{Valid: book.ImageLink.Valid, Value: book.ImageLink.String},
MapLink: types.Null[string]{Valid: book.MapLink.Valid, Value: book.MapLink.String},
Variables: book.Variables,
}
}
59 changes: 59 additions & 0 deletions bookback/internal/adapters/bookevent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package adapters

import (
"database/sql"
"github.com/SShlykov/zeitment/bookback/internal/domain/entity"
"github.com/SShlykov/zeitment/bookback/internal/models"
"github.com/SShlykov/zeitment/bookback/internal/models/types"
)

func BookEventsEntityToModel(bookevents []*entity.BookEvent) []*models.BookEvent {
bookEventModels := make([]*models.BookEvent, 0)
for _, bookevent := range bookevents {
bookEventModel := BookEventEntityToModel(bookevent)
bookEventModels = append(bookEventModels, bookEventModel)
}
return bookEventModels
}

func BookEventEntityToModel(bookevent *entity.BookEvent) *models.BookEvent {
return &models.BookEvent{
ID: bookevent.ID,
CreatedAt: bookevent.CreatedAt,
UpdatedAt: bookevent.UpdatedAt,
BookID: bookevent.BookID,
ChapterID: types.Null[string]{Valid: bookevent.ChapterID.Valid, Value: bookevent.ChapterID.String},
PageID: types.Null[string]{Valid: bookevent.PageID.Valid, Value: bookevent.PageID.String},
ParagraphID: types.Null[string]{Valid: bookevent.ParagraphID.Valid, Value: bookevent.ParagraphID.String},
EventType: types.Null[string]{Valid: bookevent.EventType.Valid, Value: bookevent.EventType.String},
IsPublic: bookevent.IsPublic,
Key: bookevent.Key,
Value: bookevent.Value,
Link: types.Null[string]{Valid: bookevent.Link.Valid, Value: bookevent.Link.String},
LinkText: types.Null[string]{Valid: bookevent.LinkText.Valid, Value: bookevent.LinkText.String},
LinkType: types.Null[string]{Valid: bookevent.LinkType.Valid, Value: bookevent.LinkType.String},
LinkImage: types.Null[string]{Valid: bookevent.LinkImage.Valid, Value: bookevent.LinkImage.String},
Description: types.Null[string]{Valid: bookevent.Description.Valid, Value: bookevent.Description.String},
}
}

func BookEventModelToEntity(bookeventModel *models.BookEvent) *entity.BookEvent {
return &entity.BookEvent{
ID: bookeventModel.ID,
CreatedAt: bookeventModel.CreatedAt,
UpdatedAt: bookeventModel.UpdatedAt,
BookID: bookeventModel.BookID,
ChapterID: sql.NullString{Valid: bookeventModel.ChapterID.Valid, String: bookeventModel.ChapterID.Value},
PageID: sql.NullString{Valid: bookeventModel.PageID.Valid, String: bookeventModel.PageID.Value},
ParagraphID: sql.NullString{Valid: bookeventModel.ParagraphID.Valid, String: bookeventModel.ParagraphID.Value},
EventType: sql.NullString{Valid: bookeventModel.EventType.Valid, String: bookeventModel.EventType.Value},
IsPublic: bookeventModel.IsPublic,
Key: bookeventModel.Key,
Value: bookeventModel.Value,
Link: sql.NullString{Valid: bookeventModel.Link.Valid, String: bookeventModel.Link.Value},
LinkText: sql.NullString{Valid: bookeventModel.LinkText.Valid, String: bookeventModel.LinkText.Value},
LinkType: sql.NullString{Valid: bookeventModel.LinkType.Valid, String: bookeventModel.LinkType.Value},
LinkImage: sql.NullString{Valid: bookeventModel.LinkImage.Valid, String: bookeventModel.LinkImage.Value},
Description: sql.NullString{Valid: bookeventModel.Description.Valid, String: bookeventModel.Description.Value},
}
}
49 changes: 49 additions & 0 deletions bookback/internal/adapters/chapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package adapters

import (
"database/sql"
"github.com/SShlykov/zeitment/bookback/internal/domain/entity"
"github.com/SShlykov/zeitment/bookback/internal/models"
"github.com/SShlykov/zeitment/bookback/internal/models/types"
"time"
)

func ChaptersEntityToModel(chapters []*entity.Chapter) []*models.Chapter {
var result []*models.Chapter
for _, chapter := range chapters {
result = append(result, ChapterEntityToModel(chapter))
}
return result
}

func ChapterEntityToModel(chapter *entity.Chapter) *models.Chapter {
return &models.Chapter{
ID: chapter.ID,
CreatedAt: chapter.CreatedAt,
UpdatedAt: chapter.UpdatedAt,
DeletedAt: types.Null[time.Time]{Valid: chapter.DeletedAt.Valid, Value: chapter.DeletedAt.Time},
Title: chapter.Title,
Number: chapter.Number,
Text: chapter.Text,
BookID: chapter.BookID,
IsPublic: chapter.IsPublic,
MapLink: types.Null[string]{Valid: chapter.MapLink.Valid, Value: chapter.MapLink.String},
MapParamsID: types.Null[string]{Valid: chapter.MapLink.Valid, Value: chapter.MapLink.String},
}
}

func ChapterModelToEntity(chapter *models.Chapter) *entity.Chapter {
return &entity.Chapter{
ID: chapter.ID,
CreatedAt: chapter.CreatedAt,
UpdatedAt: chapter.UpdatedAt,
DeletedAt: sql.NullTime{Valid: chapter.DeletedAt.Valid, Time: chapter.DeletedAt.Value},
Title: chapter.Title,
Number: chapter.Number,
Text: chapter.Text,
BookID: chapter.BookID,
IsPublic: chapter.IsPublic,
MapLink: sql.NullString{Valid: chapter.MapLink.Valid, String: chapter.MapLink.Value},
MapParamsID: sql.NullString{Valid: chapter.MapLink.Valid, String: chapter.MapLink.Value},
}
}
62 changes: 62 additions & 0 deletions bookback/internal/adapters/mapvariables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package adapters

import (
"database/sql"
"github.com/SShlykov/zeitment/bookback/internal/domain/entity"
"github.com/SShlykov/zeitment/bookback/internal/models"
"github.com/SShlykov/zeitment/bookback/internal/models/types"
)

func MapVariablesEntityToModel(variables []*entity.MapVariable) []*models.MapVariable {
var result []*models.MapVariable
for _, variable := range variables {
result = append(result, MapVariableEntityToModel(variable))
}
return result
}

func MapVariableModelToEntity(variable *models.MapVariable) *entity.MapVariable {
return &entity.MapVariable{
ID: variable.ID,
CreatedAt: variable.CreatedAt,
UpdatedAt: variable.UpdatedAt,
BookID: variable.BookID,
ChapterID: sql.NullString{Valid: variable.ChapterID.Valid, String: variable.ChapterID.Value},
PageID: sql.NullString{Valid: variable.PageID.Valid, String: variable.PageID.Value},
ParagraphID: sql.NullString{Valid: variable.ParagraphID.Valid, String: variable.ParagraphID.Value},
MapLink: variable.MapLink,
Lat: variable.Lat,
Lng: variable.Lng,
Zoom: sql.NullInt64{Valid: variable.Zoom.Valid, Int64: variable.Zoom.Value},
Date: sql.NullString{Valid: variable.Date.Valid, String: variable.Date.Value},
Description: sql.NullString{Valid: variable.Description.Valid, String: variable.Description.Value},
Link: sql.NullString{Valid: variable.Link.Valid, String: variable.Link.Value},
LinkText: sql.NullString{Valid: variable.LinkText.Valid, String: variable.LinkText.Value},
LinkType: sql.NullString{Valid: variable.LinkType.Valid, String: variable.LinkType.Value},
LinkImage: sql.NullString{Valid: variable.LinkImage.Valid, String: variable.LinkImage.Value},
Image: sql.NullString{Valid: variable.Image.Valid, String: variable.Image.Value},
}
}

func MapVariableEntityToModel(variable *entity.MapVariable) *models.MapVariable {
return &models.MapVariable{
ID: variable.ID,
CreatedAt: variable.CreatedAt,
UpdatedAt: variable.UpdatedAt,
BookID: variable.BookID,
ChapterID: types.Null[string]{Valid: variable.ChapterID.Valid, Value: variable.ChapterID.String},
PageID: types.Null[string]{Valid: variable.PageID.Valid, Value: variable.PageID.String},
ParagraphID: types.Null[string]{Valid: variable.ParagraphID.Valid, Value: variable.ParagraphID.String},
MapLink: variable.MapLink,
Lat: variable.Lat,
Lng: variable.Lng,
Zoom: types.Null[int64]{Valid: variable.Zoom.Valid, Value: variable.Zoom.Int64},
Date: types.Null[string]{Valid: variable.Date.Valid, Value: variable.Date.String},
Description: types.Null[string]{Valid: variable.Description.Valid, Value: variable.Description.String},
Link: types.Null[string]{Valid: variable.Link.Valid, Value: variable.Link.String},
LinkText: types.Null[string]{Valid: variable.LinkText.Valid, Value: variable.LinkText.String},
LinkType: types.Null[string]{Valid: variable.LinkType.Valid, Value: variable.LinkType.String},
LinkImage: types.Null[string]{Valid: variable.LinkImage.Valid, Value: variable.LinkImage.String},
Image: types.Null[string]{Valid: variable.Image.Valid, Value: variable.Image.String},
}
}
45 changes: 45 additions & 0 deletions bookback/internal/adapters/page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package adapters

import (
"database/sql"
"github.com/SShlykov/zeitment/bookback/internal/domain/entity"
"github.com/SShlykov/zeitment/bookback/internal/models"
"github.com/SShlykov/zeitment/bookback/internal/models/types"
"time"
)

func PagesEntityToModel(pages []*entity.Page) []*models.Page {
var result []*models.Page
for _, page := range pages {
result = append(result, PageEntityToModel(page))
}
return result
}

func PageModelToEntity(m *models.Page) *entity.Page {
return &entity.Page{
ID: m.ID,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: sql.NullTime{Valid: m.DeletedAt.Valid, Time: m.DeletedAt.Value},
Title: m.Title,
Text: m.Text,
ChapterID: m.ChapterID,
IsPublic: m.IsPublic,
MapParamsID: sql.NullString{Valid: m.MapParamsID.Valid, String: m.MapParamsID.Value},
}
}

func PageEntityToModel(e *entity.Page) *models.Page {
return &models.Page{
ID: e.ID,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
DeletedAt: types.Null[time.Time]{Valid: e.DeletedAt.Valid, Value: e.DeletedAt.Time},
Title: e.Title,
Text: e.Text,
ChapterID: e.ChapterID,
IsPublic: e.IsPublic,
MapParamsID: types.Null[string]{Valid: e.MapParamsID.Valid, Value: e.MapParamsID.String},
}
}
45 changes: 45 additions & 0 deletions bookback/internal/adapters/paragraph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package adapters

import (
"database/sql"
"github.com/SShlykov/zeitment/bookback/internal/domain/entity"
"github.com/SShlykov/zeitment/bookback/internal/models"
"github.com/SShlykov/zeitment/bookback/internal/models/types"
"time"
)

func ParagraphsEntityToModel(paragraphs []*entity.Paragraph) []*models.Paragraph {
var result []*models.Paragraph
for _, paragraph := range paragraphs {
result = append(result, ParagraphEntityToModel(paragraph))
}
return result
}

func ParagraphEntityToModel(paragraph *entity.Paragraph) *models.Paragraph {
return &models.Paragraph{
ID: paragraph.ID,
CreatedAt: paragraph.CreatedAt,
UpdatedAt: paragraph.UpdatedAt,
DeletedAt: types.Null[time.Time]{Valid: paragraph.DeletedAt.Valid, Value: paragraph.DeletedAt.Time},
Title: paragraph.Title,
Text: paragraph.Text,
Type: paragraph.Type,
IsPublic: paragraph.IsPublic,
PageID: paragraph.PageID,
}
}

func ParagraphModelToEntity(paragraph *models.Paragraph) *entity.Paragraph {
return &entity.Paragraph{
ID: paragraph.ID,
CreatedAt: paragraph.CreatedAt,
UpdatedAt: paragraph.UpdatedAt,
DeletedAt: sql.NullTime{Valid: paragraph.DeletedAt.Valid, Time: paragraph.DeletedAt.Value},
Title: paragraph.Title,
Text: paragraph.Text,
Type: paragraph.Type,
IsPublic: paragraph.IsPublic,
PageID: paragraph.PageID,
}
}
Empty file.
Loading
Loading