Skip to content

Commit cfda110

Browse files
committed
refactor code
1 parent 3a86bfb commit cfda110

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

up/repository.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ type SqlRepository struct {
3737
}
3838

3939
func (s *SqlRepository) Load(ctx context.Context, id string) (*Upload, error) {
40-
var attachments = make([]Upload, 0)
40+
var upload = new(Upload)
4141
query := fmt.Sprintf("select %s from %s where %s= $1", s.Columns.File, s.Table, s.Columns.Id)
4242
row := s.DB.QueryRowContext(ctx, query, id)
43-
err := row.Scan(s.toArray(&attachments))
43+
err := row.Scan(&upload)
4444
if err != nil {
4545
return nil, err
4646
}
47-
if len(attachments) > 0 {
48-
return &attachments[0], nil
49-
}
50-
return nil, err
47+
return upload, err
5148
}
5249

5350
func (s *SqlRepository) Update(ctx context.Context, id string, attachments Upload) (int64, error) {

up/upload_service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@ func NewUploadService(
3636
}
3737

3838
func (u *UploadUseCase) Upload(ctx context.Context, id string, req Request) (*Upload, error) {
39-
e, err := u.repository.Load(ctx, id)
39+
_, err := u.repository.Load(ctx, id)
4040
if err != nil {
4141
return nil, err
4242
}
43-
if e == nil {
44-
return nil, errors.New("not found item")
45-
}
4643
url, err := u.uploadFileOnServer(ctx, req.Filename, req.Type, req.Size, req.Data)
4744
if err != nil {
4845
return nil, err

0 commit comments

Comments
 (0)