Skip to content

Commit

Permalink
List all the contacts instead of doing pagination (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peltoche authored Jun 20, 2024
1 parent 26c4ee4 commit 0a89720
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/service/contacts/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Service interface {
Create(ctx context.Context, cmd *CreateCmd) (*Contact, error)
GetByID(ctx context.Context, id uuid.UUID) (*Contact, error)
EditName(ctx context.Context, cmd *EditNameCmd) (*Contact, error)
GetAll(ctx context.Context, paginateCmd *sqlstorage.PaginateCmd) ([]Contact, error)
GetAll(ctx context.Context) ([]Contact, error)
Delete(ctx context.Context, contact *Contact) error
}

Expand Down
4 changes: 2 additions & 2 deletions internal/service/contacts/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func newService(tools tools.Tools, storage storage) *service {
}
}

func (s *service) GetAll(ctx context.Context, paginateCmd *sqlstorage.PaginateCmd) ([]Contact, error) {
res, err := s.storage.GetAll(ctx, paginateCmd)
func (s *service) GetAll(ctx context.Context) ([]Contact, error) {
res, err := s.storage.GetAll(ctx, nil)
if err != nil {
return nil, errs.Internal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/contacts/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ func Test_Contacts_Service(t *testing.T) {
*NewFakeContact(t).Build(),
}

storage.On("GetAll", ctx, &sqlstorage.PaginateCmd{}).Return(contacts, nil)
storage.On("GetAll", ctx, (*sqlstorage.PaginateCmd)(nil)).Return(contacts, nil)

// Run
res, err := service.GetAll(ctx, &sqlstorage.PaginateCmd{})
res, err := service.GetAll(ctx)

// Asserts
require.NoError(t, err)
Expand All @@ -111,10 +111,10 @@ func Test_Contacts_Service(t *testing.T) {
storage := newMockStorage(t)
service := newService(tools, storage)

storage.On("GetAll", ctx, &sqlstorage.PaginateCmd{}).Return(nil, fmt.Errorf("some-error"))
storage.On("GetAll", ctx, (*sqlstorage.PaginateCmd)(nil)).Return(nil, fmt.Errorf("some-error"))

// Run
res, err := service.GetAll(ctx, &sqlstorage.PaginateCmd{})
res, err := service.GetAll(ctx)

// Asserts
require.ErrorContains(t, err, "some-error")
Expand Down
2 changes: 1 addition & 1 deletion internal/service/vcard/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *service) ImportVCardFile(ctx context.Context, file io.Reader) error {
continue
}

if !strings.HasPrefix(card.Value("VERION"), "3.") {
if !strings.HasPrefix(card.Value("VERSION"), "3.") {
return ErrUnsupportedVCardVersion
}

Expand Down
7 changes: 1 addition & 6 deletions internal/web/contacts/page_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/Peltoche/gnocchi/internal/service/contacts"
"github.com/Peltoche/gnocchi/internal/service/vcard"
"github.com/Peltoche/gnocchi/internal/tools/router"
"github.com/Peltoche/gnocchi/internal/tools/sqlstorage"
"github.com/Peltoche/gnocchi/internal/web/html"
contactstmpl "github.com/Peltoche/gnocchi/internal/web/html/templates/contacts"
"github.com/go-chi/chi/v5"
Expand All @@ -35,7 +34,6 @@ func (h *ListPage) Register(r chi.Router, mids *router.Middlewares) {
}

r.Get("/web/contacts", h.getList)
r.Get("/web/contacts/more", h.getMoreContacts)
r.Post("/web/contacts", h.createNewContact)
r.Get("/web/contacts/imports", h.getImportsModal)
r.Post("/web/contacts/imports", h.importFile)
Expand All @@ -44,7 +42,7 @@ func (h *ListPage) Register(r chi.Router, mids *router.Middlewares) {
func (h *ListPage) getList(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

contacts, err := h.contacts.GetAll(ctx, &sqlstorage.PaginateCmd{Limit: 20})
contacts, err := h.contacts.GetAll(ctx)
if err != nil {
h.html.WriteHTMLErrorPage(w, r, fmt.Errorf("failed to get the contact list: %w", err))
return
Expand All @@ -55,9 +53,6 @@ func (h *ListPage) getList(w http.ResponseWriter, r *http.Request) {
})
}

func (h *ListPage) getMoreContacts(w http.ResponseWriter, r *http.Request) {
}

func (h *ListPage) createNewContact(w http.ResponseWriter, r *http.Request) {
contact, err := h.contacts.Create(r.Context(), &contacts.CreateCmd{})
if err != nil {
Expand Down

0 comments on commit 0a89720

Please sign in to comment.