Skip to content

Commit

Permalink
replace "model2" with "model"
Browse files Browse the repository at this point in the history
  • Loading branch information
kucera-lukas committed Apr 3, 2022
1 parent 2ebfa01 commit b774127
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
26 changes: 13 additions & 13 deletions pkg/adapter/controller/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ package controller
import (
"context"

model2 "github.com/stegoer/server/pkg/model"
"github.com/stegoer/server/pkg/model"
)

// Image controller interface.
type Image interface {
Get(
ctx context.Context,
entUser model2.User,
id *model2.ID,
) (*model2.Image, error)
entUser model.User,
id *model.ID,
) (*model.Image, error)
List(
ctx context.Context,
entUser model2.User,
after *model2.Cursor,
entUser model.User,
after *model.Cursor,
first *int,
before *model2.Cursor,
before *model.Cursor,
last *int,
where *model2.ImageWhereInput,
orderBy *model2.ImageOrderInput,
) (*model2.ImageConnection, error)
where *model.ImageWhereInput,
orderBy *model.ImageOrderInput,
) (*model.ImageConnection, error)
Create(
ctx context.Context,
entUser model2.User,
entUser model.User,
filename string,
content string,
) (*model2.Image, error)
) (*model.Image, error)
Count(
ctx context.Context,
entUser model2.User,
entUser model.User,
) (int, error)
}
30 changes: 15 additions & 15 deletions pkg/adapter/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stegoer/server/ent/user"
"github.com/stegoer/server/graph/generated"
"github.com/stegoer/server/pkg/adapter/controller"
model2 "github.com/stegoer/server/pkg/model"
"github.com/stegoer/server/pkg/model"
"github.com/stegoer/server/pkg/util"
)

Expand All @@ -25,10 +25,10 @@ type userRepository struct {
func (r *userRepository) GetByID(
ctx context.Context,
id ulid.ID,
) (*model2.User, error) {
) (*model.User, error) {
entUser, err := r.client.User.Query().Where(user.IDEQ(id)).Only(ctx)
if err != nil {
return nil, model2.NewDBError(ctx, err.Error())
return nil, model.NewDBError(ctx, err.Error())
}

return entUser, nil
Expand All @@ -37,10 +37,10 @@ func (r *userRepository) GetByID(
func (r *userRepository) GetByEmail(
ctx context.Context,
email string,
) (*model2.User, error) {
) (*model.User, error) {
entUser, err := r.client.User.Query().Where(user.EmailEQ(email)).Only(ctx)
if err != nil {
return nil, model2.NewDBError(ctx, err.Error())
return nil, model.NewDBError(ctx, err.Error())
}

return entUser, nil
Expand All @@ -49,10 +49,10 @@ func (r *userRepository) GetByEmail(
func (r *userRepository) Create(
ctx context.Context,
input generated.NewUser,
) (*model2.User, error) {
) (*model.User, error) {
hashedPassword, err := util.HashPassword(input.Password)
if err != nil {
return nil, model2.NewValidationError(ctx, err.Error())
return nil, model.NewValidationError(ctx, err.Error())
}

entUser, err := r.client.User.
Expand All @@ -62,17 +62,17 @@ func (r *userRepository) Create(
SetPassword(hashedPassword).
Save(ctx)
if err != nil {
return nil, model2.NewDBError(ctx, err.Error())
return nil, model.NewDBError(ctx, err.Error())
}

return entUser, nil
}

func (r *userRepository) Update(
ctx context.Context,
entUser model2.User,
entUser model.User,
input generated.UpdateUser,
) (*model2.User, error) {
) (*model.User, error) {
update := entUser.Update()

if input.Username != nil {
Expand All @@ -86,27 +86,27 @@ func (r *userRepository) Update(
if input.Password != nil {
hashedPassword, err := util.HashPassword(*input.Password)
if err != nil {
return nil, model2.NewValidationError(ctx, err.Error())
return nil, model.NewValidationError(ctx, err.Error())
}

update = update.SetPassword(hashedPassword)
}

updatedEntUser, err := update.Save(ctx)
if err != nil {
return nil, model2.NewDBError(ctx, err.Error())
return nil, model.NewDBError(ctx, err.Error())
}

return updatedEntUser, nil
}

func (r *userRepository) SetLoggedIn(
ctx context.Context,
entUser model2.User,
) (*model2.User, error) {
entUser model.User,
) (*model.User, error) {
updatedEntUser, err := entUser.Update().SetLastLogin(time.Now()).Save(ctx)
if err != nil {
return nil, model2.NewDBError(ctx, err.Error())
return nil, model.NewDBError(ctx, err.Error())
}

return updatedEntUser, nil
Expand Down

0 comments on commit b774127

Please sign in to comment.