mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
partial repository layer added
This commit is contained in:
53
pkg/repository/api.go
Normal file
53
pkg/repository/api.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"wallet-api/pkg/migrate"
|
||||
"wallet-api/pkg/model"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
|
||||
type ApiRepository struct {
|
||||
db *pg.DB
|
||||
}
|
||||
|
||||
func NewApiRepository(db *pg.DB) *ApiRepository {
|
||||
return &ApiRepository{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
GetFirst
|
||||
|
||||
Gets first row from API table.
|
||||
|
||||
Args:
|
||||
context.Context: Application context
|
||||
Returns:
|
||||
model.ApiModel: Api object from database.
|
||||
*/
|
||||
func (as ApiRepository) GetFirst(ctx context.Context) model.ApiModel {
|
||||
db := as.db.WithContext(ctx)
|
||||
apiModel := model.ApiModel{Api: "Works"}
|
||||
db.Model(&apiModel).First()
|
||||
return apiModel
|
||||
}
|
||||
|
||||
/*
|
||||
PostMigrate
|
||||
|
||||
Starts database migration.
|
||||
|
||||
Args:
|
||||
context.Context: Application context
|
||||
string: Migration version
|
||||
Returns:
|
||||
*model.MessageResponse: Message response object.
|
||||
*model.Exception: Exception response object.
|
||||
*/
|
||||
func (as ApiRepository) PostMigrate(ctx context.Context, version string) []error {
|
||||
db := as.db.WithContext(ctx)
|
||||
return migrate.Start(db, version)
|
||||
}
|
||||
Reference in New Issue
Block a user