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

internal/mcq/sqlRepository.go   A

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mcq.NewRepository 0 2 1
A mcq.SQLRepository.GetByID 0 4 1
1
package mcq
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 (r SQLRepository) GetByID(ctx context.Context, id uint) (domain.Mcq, error) {
15
	var mcq domain.Mcq
16
	err := r.DBConn.WithContext(ctx).First(&mcq, id).Error
17
	return mcq, err
18
}
19
20
func NewRepository(dbConn *gorm.DB) IRepository {
21
	return SQLRepository{DBConn: dbConn}
22
}
23