feat: item-attachments CRUD (#22)

* change /content/ -> /homebox/

* add cache to code generators

* update env variables to set data storage

* update env variables

* set env variables in prod container

* implement attachment post route (WIP)

* get attachment endpoint

* attachment download

* implement string utilities lib

* implement generic drop zone

* use explicit truncate

* remove clean dir

* drop strings composable for lib

* update item types and add attachments

* add attachment API

* implement service context

* consolidate API code

* implement editing attachments

* implement upload limit configuration

* improve error handling

* add docs for max upload size

* fix test cases
This commit is contained in:
Hayden 2022-09-24 11:33:38 -08:00 committed by GitHub
parent 852d312ba7
commit 31b34241e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
165 changed files with 2509 additions and 664 deletions

View file

@ -8,8 +8,8 @@ import (
"testing"
"time"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/pkgs/faker"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/pkgs/faker"
_ "github.com/mattn/go-sqlite3"
)

View file

@ -4,10 +4,10 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/document"
"github.com/hay-kot/content/backend/ent/group"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/document"
"github.com/hay-kot/homebox/backend/ent/group"
"github.com/hay-kot/homebox/backend/internal/types"
)
// DocumentRepository is a repository for Document entity

View file

@ -5,8 +5,8 @@ import (
"testing"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/stretchr/testify/assert"
)

View file

@ -5,9 +5,9 @@ import (
"time"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/documenttoken"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/documenttoken"
"github.com/hay-kot/homebox/backend/internal/types"
)
// DocumentTokensRepository is a repository for Document entity

View file

@ -6,9 +6,9 @@ import (
"time"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/documenttoken"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/documenttoken"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/stretchr/testify/assert"
)

View file

@ -4,7 +4,7 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/homebox/backend/ent"
)
type GroupRepository struct {

View file

@ -4,8 +4,8 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/attachment"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/attachment"
)
// AttachmentRepo is a repository for Attachments table that links Items to Documents
@ -34,9 +34,15 @@ func (r *AttachmentRepo) Get(ctx context.Context, id uuid.UUID) (*ent.Attachment
}
func (r *AttachmentRepo) Update(ctx context.Context, itemId uuid.UUID, typ attachment.Type) (*ent.Attachment, error) {
return r.db.Attachment.UpdateOneID(itemId).
itm, err := r.db.Attachment.UpdateOneID(itemId).
SetType(typ).
Save(ctx)
if err != nil {
return nil, err
}
return r.Get(ctx, itm.ID)
}
func (r *AttachmentRepo) Delete(ctx context.Context, id uuid.UUID) error {

View file

@ -5,8 +5,8 @@ import (
"testing"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/attachment"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/attachment"
"github.com/stretchr/testify/assert"
)

View file

@ -4,10 +4,10 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/group"
"github.com/hay-kot/content/backend/ent/item"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/group"
"github.com/hay-kot/homebox/backend/ent/item"
"github.com/hay-kot/homebox/backend/internal/types"
)
type ItemsRepository struct {

View file

@ -6,8 +6,8 @@ import (
"time"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/stretchr/testify/assert"
)

View file

@ -4,10 +4,10 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/group"
"github.com/hay-kot/content/backend/ent/label"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/group"
"github.com/hay-kot/homebox/backend/ent/label"
"github.com/hay-kot/homebox/backend/internal/types"
)
type LabelRepository struct {

View file

@ -4,8 +4,8 @@ import (
"context"
"testing"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/stretchr/testify/assert"
)

View file

@ -4,9 +4,9 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/location"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/location"
"github.com/hay-kot/homebox/backend/internal/types"
)
type LocationRepository struct {

View file

@ -4,7 +4,7 @@ import (
"context"
"testing"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/stretchr/testify/assert"
)

View file

@ -4,9 +4,9 @@ import (
"context"
"time"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/authtokens"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/authtokens"
"github.com/hay-kot/homebox/backend/internal/types"
)
type TokenRepository struct {

View file

@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/content/backend/pkgs/hasher"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/hay-kot/homebox/backend/pkgs/hasher"
"github.com/stretchr/testify/assert"
)

View file

@ -4,9 +4,9 @@ import (
"context"
"github.com/google/uuid"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/ent/user"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/ent/user"
"github.com/hay-kot/homebox/backend/internal/types"
)
type UserRepository struct {

View file

@ -5,8 +5,8 @@ import (
"fmt"
"testing"
"github.com/hay-kot/content/backend/ent"
"github.com/hay-kot/content/backend/internal/types"
"github.com/hay-kot/homebox/backend/ent"
"github.com/hay-kot/homebox/backend/internal/types"
"github.com/stretchr/testify/assert"
)

View file

@ -1,6 +1,6 @@
package repo
import "github.com/hay-kot/content/backend/ent"
import "github.com/hay-kot/homebox/backend/ent"
// AllRepos is a container for all the repository interfaces
type AllRepos struct {