mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-01 15:20:29 +00:00
fix rest of linter issues
This commit is contained in:
parent
2b7a3bbec1
commit
4614586162
11 changed files with 49 additions and 51 deletions
2
backend/app/api/providers/doc.go
Normal file
2
backend/app/api/providers/doc.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package providers provides a authentication abstraction for the backend.
|
||||
package providers
|
|
@ -134,7 +134,7 @@ func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo.
|
|||
return repo.UserOut{}, err
|
||||
}
|
||||
|
||||
return svc.repos.Users.GetOneId(ctx, ID)
|
||||
return svc.repos.Users.GetOneID(ctx, ID)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -218,7 +218,7 @@ func (svc *UserService) DeleteSelf(ctx context.Context, ID uuid.UUID) error {
|
|||
}
|
||||
|
||||
func (svc *UserService) ChangePassword(ctx Context, current string, new string) (ok bool) {
|
||||
usr, err := svc.repos.Users.GetOneId(ctx, ctx.UID)
|
||||
usr, err := svc.repos.Users.GetOneID(ctx, ctx.UID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -51,10 +51,10 @@ func ToItemAttachment(attachment *ent.Attachment) ItemAttachment {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *AttachmentRepo) Create(ctx context.Context, itemID, docId uuid.UUID, typ attachment.Type) (*ent.Attachment, error) {
|
||||
func (r *AttachmentRepo) Create(ctx context.Context, itemID, docID uuid.UUID, typ attachment.Type) (*ent.Attachment, error) {
|
||||
bldr := r.db.Attachment.Create().
|
||||
SetType(typ).
|
||||
SetDocumentID(docId).
|
||||
SetDocumentID(docID).
|
||||
SetItemID(itemID)
|
||||
|
||||
// Autoset primary to true if this is the first attachment
|
||||
|
@ -87,11 +87,11 @@ func (r *AttachmentRepo) Get(ctx context.Context, id uuid.UUID) (*ent.Attachment
|
|||
Only(ctx)
|
||||
}
|
||||
|
||||
func (r *AttachmentRepo) Update(ctx context.Context, itemId uuid.UUID, data *ItemAttachmentUpdate) (*ent.Attachment, error) {
|
||||
func (r *AttachmentRepo) Update(ctx context.Context, itemID uuid.UUID, data *ItemAttachmentUpdate) (*ent.Attachment, error) {
|
||||
// TODO: execute within Tx
|
||||
typ := attachment.Type(data.Type)
|
||||
|
||||
bldr := r.db.Attachment.UpdateOneID(itemId).
|
||||
bldr := r.db.Attachment.UpdateOneID(itemID).
|
||||
SetType(typ)
|
||||
|
||||
// Primary only applies to photos
|
||||
|
@ -109,7 +109,7 @@ func (r *AttachmentRepo) Update(ctx context.Context, itemId uuid.UUID, data *Ite
|
|||
// Ensure all other attachments are not primary
|
||||
err = r.db.Attachment.Update().
|
||||
Where(
|
||||
attachment.HasItemWith(item.ID(itemId)),
|
||||
attachment.HasItemWith(item.ID(itemID)),
|
||||
attachment.IDNEQ(itm.ID),
|
||||
).
|
||||
SetPrimary(false).
|
||||
|
|
|
@ -131,5 +131,5 @@ func TestAttachmentRepo_Delete(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
_, err = tRepos.Attachments.Get(context.Background(), entity.ID)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
|
@ -99,5 +99,5 @@ func TestLabelRepository_Delete(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
_, err = tRepos.Labels.GetOne(context.Background(), loc.ID)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ type LocationPath struct {
|
|||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (lr *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUID) ([]LocationPath, error) {
|
||||
func (r *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UUID) ([]LocationPath, error) {
|
||||
query := `WITH RECURSIVE location_path AS (
|
||||
SELECT id, name, location_children
|
||||
FROM locations
|
||||
|
@ -282,7 +282,7 @@ func (lr *LocationRepository) PathForLoc(ctx context.Context, GID, locID uuid.UU
|
|||
SELECT id, name
|
||||
FROM location_path`
|
||||
|
||||
rows, err := lr.db.Sql().QueryContext(ctx, query, locID, GID)
|
||||
rows, err := r.db.Sql().QueryContext(ctx, query, locID, GID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ func TestLocationRepository_Delete(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
_, err = tRepos.Locations.Get(context.Background(), loc.ID)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestItemRepository_TreeQuery(t *testing.T) {
|
||||
|
|
|
@ -78,7 +78,7 @@ func TestMaintenanceEntryRepository_GetLog(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.InDelta(t, total, log.CostTotal, .001, "total cost should be equal to the sum of all entries")
|
||||
assert.Equal(t, total/2, log.CostAverage, "average cost should be the average of the two months")
|
||||
assert.InDelta(t, total/2, log.CostAverage, 001, "average cost should be the average of the two months")
|
||||
|
||||
for _, entry := range log.Entries {
|
||||
err := tRepos.MaintEntry.Delete(context.Background(), entry.ID)
|
||||
|
|
|
@ -11,12 +11,11 @@ import (
|
|||
)
|
||||
|
||||
func TestAuthTokenRepo_CreateToken(t *testing.T) {
|
||||
asrt := assert.New(t)
|
||||
ctx := context.Background()
|
||||
user := userFactory()
|
||||
|
||||
userOut, err := tRepos.Users.Create(ctx, user)
|
||||
asrt.NoError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
expiresAt := time.Now().Add(time.Hour)
|
||||
|
||||
|
@ -28,23 +27,22 @@ func TestAuthTokenRepo_CreateToken(t *testing.T) {
|
|||
UserID: userOut.ID,
|
||||
})
|
||||
|
||||
asrt.NoError(err)
|
||||
asrt.Equal(userOut.ID, token.UserID)
|
||||
asrt.Equal(expiresAt, token.ExpiresAt)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, userOut.ID, token.UserID)
|
||||
assert.Equal(t, expiresAt, token.ExpiresAt)
|
||||
|
||||
// Cleanup
|
||||
asrt.NoError(tRepos.Users.Delete(ctx, userOut.ID))
|
||||
require.NoError(t, tRepos.Users.Delete(ctx, userOut.ID))
|
||||
_, err = tRepos.AuthTokens.DeleteAll(ctx)
|
||||
asrt.NoError(err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAuthTokenRepo_DeleteToken(t *testing.T) {
|
||||
asrt := assert.New(t)
|
||||
ctx := context.Background()
|
||||
user := userFactory()
|
||||
|
||||
userOut, err := tRepos.Users.Create(ctx, user)
|
||||
asrt.NoError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
expiresAt := time.Now().Add(time.Hour)
|
||||
|
||||
|
@ -55,15 +53,14 @@ func TestAuthTokenRepo_DeleteToken(t *testing.T) {
|
|||
ExpiresAt: expiresAt,
|
||||
UserID: userOut.ID,
|
||||
})
|
||||
asrt.NoError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Delete token
|
||||
err = tRepos.AuthTokens.DeleteToken(ctx, []byte(generatedToken.Raw))
|
||||
asrt.NoError(err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAuthTokenRepo_GetUserByToken(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
ctx := context.Background()
|
||||
|
||||
user := userFactory()
|
||||
|
@ -84,9 +81,9 @@ func TestAuthTokenRepo_GetUserByToken(t *testing.T) {
|
|||
foundUser, err := tRepos.AuthTokens.GetUserFromToken(ctx, token.TokenHash)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(userOut.ID, foundUser.ID)
|
||||
assert.Equal(userOut.Name, foundUser.Name)
|
||||
assert.Equal(userOut.Email, foundUser.Email)
|
||||
assert.Equal(t, userOut.ID, foundUser.ID)
|
||||
assert.Equal(t, userOut.Name, foundUser.Name)
|
||||
assert.Equal(t, userOut.Email, foundUser.Email)
|
||||
|
||||
// Cleanup
|
||||
require.NoError(t, tRepos.Users.Delete(ctx, userOut.ID))
|
||||
|
@ -95,7 +92,6 @@ func TestAuthTokenRepo_GetUserByToken(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAuthTokenRepo_PurgeExpiredTokens(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
ctx := context.Background()
|
||||
|
||||
user := userFactory()
|
||||
|
@ -114,7 +110,7 @@ func TestAuthTokenRepo_PurgeExpiredTokens(t *testing.T) {
|
|||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(createdToken)
|
||||
assert.NotNil(t, createdToken)
|
||||
|
||||
createdTokens = append(createdTokens, createdToken)
|
||||
}
|
||||
|
@ -123,12 +119,12 @@ func TestAuthTokenRepo_PurgeExpiredTokens(t *testing.T) {
|
|||
tokensDeleted, err := tRepos.AuthTokens.PurgeExpiredTokens(ctx)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(5, tokensDeleted)
|
||||
assert.Equal(t, 5, tokensDeleted)
|
||||
|
||||
// Check if tokens are deleted
|
||||
for _, token := range createdTokens {
|
||||
_, err := tRepos.AuthTokens.GetUserFromToken(ctx, token.TokenHash)
|
||||
assert.Error(err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
|
|
|
@ -60,32 +60,32 @@ func mapUserOut(user *ent.User) UserOut {
|
|||
}
|
||||
}
|
||||
|
||||
func (e *UserRepository) GetOneId(ctx context.Context, ID uuid.UUID) (UserOut, error) {
|
||||
return mapUserOutErr(e.db.User.Query().
|
||||
func (r *UserRepository) GetOneID(ctx context.Context, ID uuid.UUID) (UserOut, error) {
|
||||
return mapUserOutErr(r.db.User.Query().
|
||||
Where(user.ID(ID)).
|
||||
WithGroup().
|
||||
Only(ctx))
|
||||
}
|
||||
|
||||
func (e *UserRepository) GetOneEmail(ctx context.Context, email string) (UserOut, error) {
|
||||
return mapUserOutErr(e.db.User.Query().
|
||||
func (r *UserRepository) GetOneEmail(ctx context.Context, email string) (UserOut, error) {
|
||||
return mapUserOutErr(r.db.User.Query().
|
||||
Where(user.EmailEqualFold(email)).
|
||||
WithGroup().
|
||||
Only(ctx),
|
||||
)
|
||||
}
|
||||
|
||||
func (e *UserRepository) GetAll(ctx context.Context) ([]UserOut, error) {
|
||||
return mapUsersOutErr(e.db.User.Query().WithGroup().All(ctx))
|
||||
func (r *UserRepository) GetAll(ctx context.Context) ([]UserOut, error) {
|
||||
return mapUsersOutErr(r.db.User.Query().WithGroup().All(ctx))
|
||||
}
|
||||
|
||||
func (e *UserRepository) Create(ctx context.Context, usr UserCreate) (UserOut, error) {
|
||||
func (r *UserRepository) Create(ctx context.Context, usr UserCreate) (UserOut, error) {
|
||||
role := user.RoleUser
|
||||
if usr.IsOwner {
|
||||
role = user.RoleOwner
|
||||
}
|
||||
|
||||
entUser, err := e.db.User.
|
||||
entUser, err := r.db.User.
|
||||
Create().
|
||||
SetName(usr.Name).
|
||||
SetEmail(usr.Email).
|
||||
|
@ -98,11 +98,11 @@ func (e *UserRepository) Create(ctx context.Context, usr UserCreate) (UserOut, e
|
|||
return UserOut{}, err
|
||||
}
|
||||
|
||||
return e.GetOneId(ctx, entUser.ID)
|
||||
return r.GetOneID(ctx, entUser.ID)
|
||||
}
|
||||
|
||||
func (e *UserRepository) Update(ctx context.Context, ID uuid.UUID, data UserUpdate) error {
|
||||
q := e.db.User.Update().
|
||||
func (r *UserRepository) Update(ctx context.Context, ID uuid.UUID, data UserUpdate) error {
|
||||
q := r.db.User.Update().
|
||||
Where(user.ID(ID)).
|
||||
SetName(data.Name).
|
||||
SetEmail(data.Email)
|
||||
|
@ -111,18 +111,18 @@ func (e *UserRepository) Update(ctx context.Context, ID uuid.UUID, data UserUpda
|
|||
return err
|
||||
}
|
||||
|
||||
func (e *UserRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := e.db.User.Delete().Where(user.ID(id)).Exec(ctx)
|
||||
func (r *UserRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := r.db.User.Delete().Where(user.ID(id)).Exec(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *UserRepository) DeleteAll(ctx context.Context) error {
|
||||
_, err := e.db.User.Delete().Exec(ctx)
|
||||
func (r *UserRepository) DeleteAll(ctx context.Context) error {
|
||||
_, err := r.db.User.Delete().Exec(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *UserRepository) GetSuperusers(ctx context.Context) ([]*ent.User, error) {
|
||||
users, err := e.db.User.Query().Where(user.IsSuperuser(true)).All(ctx)
|
||||
func (r *UserRepository) GetSuperusers(ctx context.Context) ([]*ent.User, error) {
|
||||
users, err := r.db.User.Query().Where(user.IsSuperuser(true)).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func TestUserRepo_GetOneId(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
userOut, _ := tRepos.Users.Create(ctx, user)
|
||||
foundUser, err := tRepos.Users.GetOneId(ctx, userOut.ID)
|
||||
foundUser, err := tRepos.Users.GetOneID(ctx, userOut.ID)
|
||||
|
||||
assert.NotNil(foundUser)
|
||||
require.NoError(t, err)
|
||||
|
@ -114,7 +114,7 @@ func TestUserRepo_Update(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Validate
|
||||
updated, err := tRepos.Users.GetOneId(context.Background(), user.ID)
|
||||
updated, err := tRepos.Users.GetOneID(context.Background(), user.ID)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, user.Name, updated.Name)
|
||||
assert.NotEqual(t, user.Email, updated.Email)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue