Passed
Push — main ( 0795ea...57a23e )
by Yume
02:19 queued 01:06
created

card.SQLRepository.GetByID   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
package card
2
3
import (
4
	"context"
5
6
	"github.com/memnix/memnix-rest/domain"
7
	"gorm.io/gorm"
8
)
9
10
type SQLRepository struct {
11
	DBConn *gorm.DB
12
}
13
14
func NewRepository(dbConn *gorm.DB) IRepository {
15
	return &SQLRepository{DBConn: dbConn}
16
}
17
18
func (r SQLRepository) GetByID(ctx context.Context, id uint) (domain.Card, error) {
19
	var card domain.Card
20
	err := r.DBConn.WithContext(ctx).First(&card, id).Error
21
	return card, err
22
}
23