Skip to content

Commit

Permalink
chore(io): migrate deps to third party io package
Browse files Browse the repository at this point in the history
  • Loading branch information
thuongtruong109 committed Jul 12, 2024
1 parent ffdc0c4 commit a20cb9f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 90 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/thuongtruong109/soundlib/ci.yml)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/thuongtruong109/soundlib)

## Preview

| ![Main Menu](/public/1.png) | ![Read data](/public/2.png) |
![Main Menu](/public/1.png)
![Read data](/public/2.png)

## Description

Expand Down
2 changes: 1 addition & 1 deletion database/artists.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"1687605265053017500","name":"222"},{"id":"1687605373968689300","name":"333"},{"id":"1687606184929398800","name":"kokoh"},{"id":"1687662384549952900","name":"qqq"},{"id":"1687681372018956400","name":"fuel222"},{"id":"1720710413102935900","name":"test"},{"id":"1720803919206864100","name":"Single"}]
[{"id":"1687605265053017500","name":"222"},{"id":"1687605373968689300","name":"333"},{"id":"1687606184929398800","name":"kokoh"},{"id":"1687662384549952900","name":"qqq"},{"id":"1687681372018956400","name":"fuel222"},{"id":"1720710413102935900","name":"test"},{"id":"1720803919206864100","name":"Single"},{"id":"1720805964595336600","name":"frofjer2"}]
56 changes: 0 additions & 56 deletions database/db.go

This file was deleted.

10 changes: 5 additions & 5 deletions internal/artists/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package artists

import (
"fmt"
"github.com/thuongtruong109/soundlib/database"
"github.com/thuongtruong109/gouse/io"
"github.com/thuongtruong109/soundlib/pkg/constants"
"github.com/thuongtruong109/soundlib/internal/models"
"github.com/thuongtruong109/soundlib/pkg/helpers"
Expand All @@ -19,7 +19,7 @@ func NewArtistRepository(helper helpers.Helper) *ArtistRepository {
}

func (a *ArtistRepository) GetArtists() ([]*models.Artist, error) {
allArtist, err := database.ReadDB[*models.Artist](constants.ARTIST_PATH)
allArtist, err := io.ReadFileObj[*models.Artist](constants.ARTIST_PATH)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func (a *ArtistRepository) CreateArtist(newArtist *models.Artist) (*models.Artis

artistInit = append(artistInit, newArtist)

err2 := database.SaveDB[[]*models.Artist](constants.ARTIST_PATH, artistInit)
err2 := io.WriteFileObj[[]*models.Artist](constants.ARTIST_PATH, artistInit)
if err2 != nil {
return nil, fmt.Errorf(constants.CREATE_FAILED)
}
Expand All @@ -89,7 +89,7 @@ func (a *ArtistRepository) UpdateArtist(artlistUpdate *models.Artist) (*models.A

artistInit = append(artistInit, allArtist[len(artistInit):]...)

err2 := database.SaveDB[[]*models.Artist](constants.ARTIST_PATH, allArtist)
err2 := io.WriteFileObj[[]*models.Artist](constants.ARTIST_PATH, allArtist)
if err2 != nil {
return nil, fmt.Errorf(constants.UPDATE_FAILED)
}
Expand All @@ -110,7 +110,7 @@ func (a *ArtistRepository) DeleteArtist(artlistID string) error {
}
}

err2 := database.SaveDB[[]*models.Artist](constants.ARTIST_PATH, allArtist)
err2 := io.WriteFileObj[[]*models.Artist](constants.ARTIST_PATH, allArtist)
if err2 != nil {
return fmt.Errorf(constants.DELETE_FAILED)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/genres/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package genres

import (
"fmt"
"github.com/thuongtruong109/soundlib/database"
"github.com/thuongtruong109/gouse/io"
"github.com/thuongtruong109/soundlib/pkg/constants"
"github.com/thuongtruong109/soundlib/pkg/helpers"
"github.com/thuongtruong109/soundlib/internal/models"
Expand All @@ -19,7 +19,7 @@ func NewGenreRepository(helper helpers.Helper) *GenreRepository {
}

func (g *GenreRepository) GetGenres() ([]*models.Genre, error) {
genres, err := database.ReadDB[*models.Genre](constants.GENRE_PATH)
genres, err := io.ReadFileObj[*models.Genre](constants.GENRE_PATH)

if err != nil {
return nil, err
Expand Down Expand Up @@ -65,7 +65,7 @@ func (g *GenreRepository) CreateGenre(newGenre *models.Genre) (*models.Genre, er

genresInit = append(genresInit, newGenre)

err2 := database.SaveDB[[]*models.Genre](constants.GENRE_PATH, genresInit)
err2 := io.WriteFileObj[[]*models.Genre](constants.GENRE_PATH, genresInit)
if err2 != nil {
return nil, fmt.Errorf(constants.CREATE_FAILED)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func (g *GenreRepository) UpdateGenre(updateGenre *models.Genre) (*models.Genre,

genresInit = append(genresInit, allGenres[len(genresInit):]...)

err2 := database.SaveDB[[]*models.Genre](constants.GENRE_PATH, genresInit)
err2 := io.WriteFileObj[[]*models.Genre](constants.GENRE_PATH, genresInit)
if err2 != nil {
return nil, fmt.Errorf(constants.UPDATE_FAILED)
}
Expand All @@ -119,7 +119,7 @@ func (g *GenreRepository) DeleteGenre(genreID string) error {
}
}

err2 := database.SaveDB[[]*models.Genre](constants.GENRE_PATH, genresInit)
err2 := io.WriteFileObj[[]*models.Genre](constants.GENRE_PATH, genresInit)
if err2 != nil {
return fmt.Errorf(constants.DELETE_FAILED)
}
Expand Down
9 changes: 0 additions & 9 deletions pkg/constants/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ const (
)

const (
Reset string = "\033[0m"
Red string = "\033[31m"
Green string = "\033[32m"
Yellow string = "\033[33m"
Purple string = "\033[34m"
Pink string = "\033[35m"
Cyan string = "\033[36m"
Gray string = "\033[37m"
White string = "\033[97m"
Orange string = "\033[38;5;208m"
)
27 changes: 14 additions & 13 deletions pkg/helpers/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@ package helpers

import (
"github.com/thuongtruong109/soundlib/pkg/constants"
"github.com/thuongtruong109/gouse/shared"
)

func (h *Helper) OutputColor(level int8) string {
switch level {
case constants.DEBUG:
return constants.Gray
case constants.INFO:
return constants.Green
return shared.GREEN_FG
case constants.WARNING:
return constants.Orange
return shared.ORANGE_FG
case constants.ERROR:
return constants.Red
return shared.RED_FG
case constants.FATAL:
return constants.Purple
return shared.PURPLE_FG
case constants.LABEL:
return constants.Cyan
return shared.CYAN_FG
case constants.DESC:
return constants.Yellow
return shared.YELLOW_FG
case constants.INPUT:
return constants.Cyan
return shared.CYAN_FG
case constants.QUERY:
return constants.Pink
return shared.PINK_FG
default:
return constants.White
return shared.WHITE_FG
}
}

func (h *Helper) OutputSuccess(statusMsg string) {
println(constants.Green + "\n::: Status: " + statusMsg + constants.Reset)
println(shared.GREEN_FG + "\n::: Status: " + statusMsg + shared.DEFAULT_FG)
}

func (h *Helper) OutputError(statusMsg string, err string) {
println(constants.Red + "\n::: Status: " + statusMsg + "\n::: Message: " + err + constants.Reset)
println(shared.RED_FG + "\n::: Status: " + statusMsg + "\n::: Message: " + err + shared.DEFAULT_FG)
}

func (h *Helper) OutputNomal(label int8, msg string) {
println(h.OutputColor(label) + msg + constants.Reset)
println(h.OutputColor(label) + msg + shared.DEFAULT_FG)
}

func OutputTime(time string) {
println(constants.Purple + "\n::: Query time: " + time + constants.Reset)
println(shared.PURPLE_FG + "\n::: Query time: " + time + shared.DEFAULT_FG)
}

0 comments on commit a20cb9f

Please sign in to comment.