Skip to content

Commit

Permalink
Removed useless listpanel
Browse files Browse the repository at this point in the history
Renamed database model
  • Loading branch information
grrlopes committed Aug 7, 2023
1 parent fd45874 commit acf4c24
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions entity/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/charmbracelet/bubbles/viewport"
)

type Command struct {
type CmdModel struct {
Content string
Cursor int
Ready bool
Expand All @@ -26,5 +26,5 @@ type Command struct {
ProgressSync progress.Model
Finder textinput.Model
FinderFilter string
Store []SqliteCommand
Store []Commands
}
5 changes: 0 additions & 5 deletions entity/listpanel.go

This file was deleted.

2 changes: 1 addition & 1 deletion entity/sqlitecommand.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package entity

type SqliteCommand struct {
type Commands struct {
ID int64
EnTitle string
Desc string
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m model) View() string {
func main() {
m := model{
home: ui.NewHome(
&entity.Command{},
&entity.CmdModel{},
),
}

Expand Down
4 changes: 2 additions & 2 deletions repositories/isqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package repositories

import "github.com/grrlopes/storydb/entity"

type SqliteCmd entity.SqliteCommand
type SqliteCmd entity.Commands

type ISqliteRepository interface {
Migrate() error
All(int) ([]SqliteCmd, int, error)
Pagination(int, int) ([]SqliteCmd, error)
Count() (int, error)
InsertParsed(string) (int64, error)
Search(string, int, int) ([]entity.SqliteCommand, int, error)
Search(string, int, int) ([]entity.Commands, int, error)
SearchCount(string) (int, error)
}
12 changes: 6 additions & 6 deletions repositories/sqlite/sqliterepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,33 @@ func (sql SQLiteRepository) InsertParsed(data string) (int64, error) {
return id, err
}

func (sql *SQLiteRepository) Search(filter string, limit int, skip int) ([]entity.SqliteCommand, int, error) {
func (sql *SQLiteRepository) Search(filter string, limit int, skip int) ([]entity.Commands, int, error) {
var count int

stmt, err := sql.db.Prepare("SELECT * FROM command WHERE title LIKE ? limit ? offset ?")
if err != nil {
return []entity.SqliteCommand{}, count, err
return []entity.Commands{}, count, err
}

result, err := stmt.Query("%"+filter+"%", limit, skip)
if err != nil {
return []entity.SqliteCommand{}, count, err
return []entity.Commands{}, count, err
}

defer result.Close()

err = sql.db.QueryRow("SELECT COUNT(*) FROM command WHERE Title LIKE ?", "%"+filter+"%").Scan(&count)

var data []entity.SqliteCommand
var data []entity.Commands

for result.Next() {
var command entity.SqliteCommand
var command entity.Commands
if err := result.Scan(
&command.ID,
&command.EnTitle,
&command.Desc,
); err != nil {
return []entity.SqliteCommand{}, count, err
return []entity.Commands{}, count, err
}

data = append(data, command)
Expand Down
2 changes: 1 addition & 1 deletion ui/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/grrlopes/storydb/entity"
)

func finderCmd(filter string, limit int, offset int) ([]entity.SqliteCommand, int) {
func finderCmd(filter string, limit int, offset int) ([]entity.Commands, int) {
data, total, _ := usecaseFinder.Execute(filter, limit, offset)
return data, total
}
Expand Down
6 changes: 3 additions & 3 deletions ui/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ var (
)

type ModelHome struct {
home entity.Command
home entity.CmdModel
}

func NewHome(m *entity.Command) *ModelHome {
func NewHome(m *entity.CmdModel) *ModelHome {
count := usecaseCount.Execute()
ftotal := usecaseHistoryTotal.Execute()
p := paginator.New()
Expand All @@ -50,7 +50,7 @@ func NewHome(m *entity.Command) *ModelHome {
txt.Prompt = "Finder: "

home := ModelHome{
home: entity.Command{
home: entity.CmdModel{
Content: m.Content,
Ready: false,
Viewport: viewport.Model{},
Expand Down
4 changes: 2 additions & 2 deletions usecase/finder/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type InputBoundary interface {
Execute(string, int, int) ([]entity.SqliteCommand, int, error)
Execute(string, int, int) ([]entity.Commands, int, error)
}

type execute struct {
Expand All @@ -21,7 +21,7 @@ func NewFinder(repo repositories.ISqliteRepository) InputBoundary {
}
}

func (e execute) Execute(filter string, limit int, skip int) ([]entity.SqliteCommand, int, error) {
func (e execute) Execute(filter string, limit int, skip int) ([]entity.Commands, int, error) {
result, count, err := e.repository.Search(filter, limit, skip)
if err != nil {
log.Fatal("Search:", err)
Expand Down
8 changes: 4 additions & 4 deletions usecase/pager/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type InputBoundary interface {
// It gets integer paramaters limit and offset
Execute(int, int) ([]entity.SqliteCommand, error)
Execute(int, int) ([]entity.Commands, error)
}

type execute struct {
Expand All @@ -22,9 +22,9 @@ func NewPager(repo repositories.ISqliteRepository) InputBoundary {
}
}

func (e execute) Execute(limit int, offset int) ([]entity.SqliteCommand, error) {
func (e execute) Execute(limit int, offset int) ([]entity.Commands, error) {
result, err := e.repository.Pagination(limit, offset)
items := []entity.SqliteCommand{}
items := []entity.Commands{}

if err != nil {
log.Fatal("Pager:", err)
Expand All @@ -33,7 +33,7 @@ func (e execute) Execute(limit int, offset int) ([]entity.SqliteCommand, error)
for _, value := range result {
items = append(
items,
entity.SqliteCommand(value),
entity.Commands(value),
)
}

Expand Down

0 comments on commit acf4c24

Please sign in to comment.