Compare commits
2 Commits
4f89f59232
...
fix/sravni
| Author | SHA1 | Date | |
|---|---|---|---|
| e63b254395 | |||
| 5c529ef060 |
@ -85,19 +85,6 @@ type Filters struct {
|
|||||||
IsCourseProfeccion Flagged `json:"isCourseProfession"`
|
IsCourseProfeccion Flagged `json:"isCourseProfession"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataSourceType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
DataSourceTypeDictionaryConfig DataSourceType = "dictionaryConfig"
|
|
||||||
DataSourceTypeDictionary DataSourceType = "dictionary"
|
|
||||||
DataSourceTypeOrganization DataSourceType = "organization"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ReduxDataSource struct {
|
|
||||||
Type DataSourceType `json:"type"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReduxConfigDictionaryBaseUnit struct {
|
type ReduxConfigDictionaryBaseUnit struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
@ -124,25 +111,18 @@ type ReduxConfigFilterUnit struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ReduxConfigSorting struct {
|
type ReduxConfigSorting struct {
|
||||||
Property string `json:"property"`
|
Name string `json:"name"`
|
||||||
// 3 more fields
|
Property string `json:"property"`
|
||||||
|
Direction string `json:"direction"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReduxConfig struct {
|
type ReduxConfig struct {
|
||||||
Default struct {
|
Default struct {
|
||||||
SortingParameters []ReduxConfigSorting `json:"sortingParameters"`
|
SortingParameters []ReduxConfigSorting `json:"sortingParameters"`
|
||||||
} `json:"default"`
|
} `json:"default"`
|
||||||
DataSources map[string]ReduxDataSource `json:"dataSources"`
|
DataSources map[string]string `json:"dataSources"`
|
||||||
Dictionaries struct {
|
Filters []ReduxConfigFilterUnit `json:"filters"`
|
||||||
PriceFilter []ReduxConfigDictionaryRangeUnit `json:"dictionaryPriceFilter"`
|
Sorting []ReduxConfigSorting `json:"sorting"`
|
||||||
GraphicFilter []ReduxConfigDictionaryBaseUnit `json:"dictionaryGraphicFilterNew"`
|
|
||||||
FormatFilter []ReduxConfigDictionaryBaseUnit `json:"dictionaryFormatFilterNew"`
|
|
||||||
LevelFilter []ReduxConfigDictionaryBaseUnit `json:"dictionaryLevelFilterNew"`
|
|
||||||
TimeFilter []ReduxConfigDictionaryRangeUnit `json:"dictionaryTimeFilter"`
|
|
||||||
InstallmentFilter []ReduxConfigDictionaryRangeUnit `json:"dictionaryInstallmentFilter"`
|
|
||||||
}
|
|
||||||
Filters []ReduxConfigFilterUnit `json:"filters"`
|
|
||||||
Sorting []ReduxConfigSorting `json:"sorting"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type InitialReduxState struct {
|
type InitialReduxState struct {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/domain/mocks"
|
mockrepo "git.loyso.art/frx/kurious/internal/kurious/adapters/mocks"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|||||||
42
internal/kurious/adapters/not_implemented.go
Normal file
42
internal/kurious/adapters/not_implemented.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package adapters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
|
||||||
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NotImplementedOrganizationRepository struct{}
|
||||||
|
|
||||||
|
func (NotImplementedOrganizationRepository) ListStats(
|
||||||
|
context.Context,
|
||||||
|
domain.ListOrganizationsParams,
|
||||||
|
) ([]domain.OrganizationStat, error) {
|
||||||
|
return nil, cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
func (NotImplementedOrganizationRepository) List(context.Context, domain.ListOrganizationsParams) ([]domain.Organization, error) {
|
||||||
|
return nil, cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
func (NotImplementedOrganizationRepository) Get(context.Context, domain.GetOrganizationParams) (domain.Organization, error) {
|
||||||
|
return domain.Organization{}, cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
func (NotImplementedOrganizationRepository) Create(context.Context, domain.CreateOrganizationParams) (domain.Organization, error) {
|
||||||
|
return domain.Organization{}, cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
func (NotImplementedOrganizationRepository) Delete(ctx context.Context, id string) error {
|
||||||
|
return cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotImplementedLearningCategory struct{}
|
||||||
|
|
||||||
|
func (NotImplementedLearningCategory) Upsert(context.Context, domain.LearningCategory) error {
|
||||||
|
return cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
func (NotImplementedLearningCategory) List(context.Context) ([]domain.LearningCategory, error) {
|
||||||
|
return nil, cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
|
func (NotImplementedLearningCategory) Get(context.Context, string) (domain.LearningCategory, error) {
|
||||||
|
return domain.LearningCategory{}, cerrors.ErrNotImplemented
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
|
||||||
"git.loyso.art/frx/kurious/internal/common/xslices"
|
"git.loyso.art/frx/kurious/internal/common/xslices"
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ func (r *sqliteLearingCategoryRepository) Get(ctx context.Context, id string) (c
|
|||||||
err = r.db.GetContext(ctx, &cdb, query, id)
|
err = r.db.GetContext(ctx, &cdb, query, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return domain.LearningCategory{}, domain.ErrNotFound
|
return domain.LearningCategory{}, cerrors.ErrNotFound
|
||||||
}
|
}
|
||||||
return domain.LearningCategory{}, fmt.Errorf("executing query: %w", err)
|
return domain.LearningCategory{}, fmt.Errorf("executing query: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package adapters
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.loyso.art/frx/kurious/internal/common/errors"
|
||||||
"git.loyso.art/frx/kurious/internal/common/nullable"
|
"git.loyso.art/frx/kurious/internal/common/nullable"
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ func (s *sqliteLearningCategoriesRepositorySuite) TestUpsert() {
|
|||||||
const categoryID = "test-id-1"
|
const categoryID = "test-id-1"
|
||||||
repo := s.connection.LearningCategory()
|
repo := s.connection.LearningCategory()
|
||||||
gotCategory, err := repo.Get(s.ctx, categoryID)
|
gotCategory, err := repo.Get(s.ctx, categoryID)
|
||||||
s.ErrorIs(err, domain.ErrNotFound)
|
s.ErrorIs(err, errors.ErrNotFound)
|
||||||
s.Empty(gotCategory)
|
s.Empty(gotCategory)
|
||||||
|
|
||||||
createdCategory := domain.LearningCategory{
|
createdCategory := domain.LearningCategory{
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
|
||||||
"git.loyso.art/frx/kurious/internal/common/xslices"
|
"git.loyso.art/frx/kurious/internal/common/xslices"
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
@ -228,7 +229,7 @@ func (r *sqliteOrganizationRepository) Get(ctx context.Context, params domain.Ge
|
|||||||
err = r.db.GetContext(ctx, &orgdb, query, args...)
|
err = r.db.GetContext(ctx, &orgdb, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return out, domain.ErrNotFound
|
return out, cerrors.ErrNotFound
|
||||||
}
|
}
|
||||||
return out, fmt.Errorf("executing query: %w", err)
|
return out, fmt.Errorf("executing query: %w", err)
|
||||||
}
|
}
|
||||||
@ -306,14 +307,14 @@ func (r *sqliteOrganizationRepository) Delete(ctx context.Context, id string) (e
|
|||||||
result, err := r.db.ExecContext(ctx, query, id)
|
result, err := r.db.ExecContext(ctx, query, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return domain.ErrNotFound
|
return cerrors.ErrNotFound
|
||||||
}
|
}
|
||||||
return fmt.Errorf("executing query: %w", err)
|
return fmt.Errorf("executing query: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
affected, _ := result.RowsAffected()
|
affected, _ := result.RowsAffected()
|
||||||
if affected == 0 {
|
if affected == 0 {
|
||||||
return domain.ErrNotFound
|
return cerrors.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -110,11 +110,11 @@ func (conn *YDBConnection) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conn *YDBConnection) Organization() domain.OrganizationRepository {
|
func (conn *YDBConnection) Organization() domain.OrganizationRepository {
|
||||||
return domain.NotImplementedOrganizationRepository{}
|
return NotImplementedOrganizationRepository{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *YDBConnection) LearningCategory() domain.LearningCategoryRepository {
|
func (conn *YDBConnection) LearningCategory() domain.LearningCategoryRepository {
|
||||||
return domain.NotImplementedLearningCategory{}
|
return NotImplementedLearningCategory{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *YDBConnection) CourseRepository() *ydbCourseRepository {
|
func (conn *YDBConnection) CourseRepository() *ydbCourseRepository {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"git.loyso.art/frx/kurious/internal/common/nullable"
|
"git.loyso.art/frx/kurious/internal/common/nullable"
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/domain/mocks"
|
mockrepo "git.loyso.art/frx/kurious/internal/kurious/adapters/mocks"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||||
mockrepo "git.loyso.art/frx/kurious/internal/kurious/domain/mocks"
|
mockrepo "git.loyso.art/frx/kurious/internal/kurious/adapters/mocks"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
package domain
|
|
||||||
|
|
||||||
const (
|
|
||||||
ErrNotFound PlainError = "not found"
|
|
||||||
ErrNotImplemented PlainError = "not implemented"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PlainError string
|
|
||||||
|
|
||||||
func (err PlainError) Error() string {
|
|
||||||
return string(err)
|
|
||||||
}
|
|
||||||
@ -80,7 +80,7 @@ type ListStatisticsResult struct {
|
|||||||
LearningTypeStatistics []StatisticUnit
|
LearningTypeStatistics []StatisticUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate mockery --name CourseRepository
|
//go:generate mockery --name CourseRepository --output ../adapters/mocks
|
||||||
type CourseRepository interface {
|
type CourseRepository interface {
|
||||||
// List courses by specifid parameters.
|
// List courses by specifid parameters.
|
||||||
List(context.Context, ListCoursesParams) (ListCoursesResult, error)
|
List(context.Context, ListCoursesParams) (ListCoursesResult, error)
|
||||||
@ -126,7 +126,7 @@ type ListOrganizationsParams struct {
|
|||||||
IDs []string
|
IDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate mockery --name OrganizationRepository
|
//go:generate mockery --name OrganizationRepository --output ../adapters/mocks
|
||||||
type OrganizationRepository interface {
|
type OrganizationRepository interface {
|
||||||
ListStats(context.Context, ListOrganizationsParams) ([]OrganizationStat, error)
|
ListStats(context.Context, ListOrganizationsParams) ([]OrganizationStat, error)
|
||||||
List(context.Context, ListOrganizationsParams) ([]Organization, error)
|
List(context.Context, ListOrganizationsParams) ([]Organization, error)
|
||||||
@ -135,44 +135,10 @@ type OrganizationRepository interface {
|
|||||||
Delete(ctx context.Context, id string) error
|
Delete(ctx context.Context, id string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotImplementedOrganizationRepository struct{}
|
//go:generate mockery --name LearningCategoryRepository --output ../adapters/mocks
|
||||||
|
|
||||||
func (NotImplementedOrganizationRepository) ListStats(
|
|
||||||
context.Context,
|
|
||||||
ListOrganizationsParams,
|
|
||||||
) ([]OrganizationStat, error) {
|
|
||||||
return nil, ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
func (NotImplementedOrganizationRepository) List(context.Context, ListOrganizationsParams) ([]Organization, error) {
|
|
||||||
return nil, ErrNotImplemented
|
|
||||||
}
|
|
||||||
func (NotImplementedOrganizationRepository) Get(context.Context, GetOrganizationParams) (Organization, error) {
|
|
||||||
return Organization{}, ErrNotImplemented
|
|
||||||
}
|
|
||||||
func (NotImplementedOrganizationRepository) Create(context.Context, CreateOrganizationParams) (Organization, error) {
|
|
||||||
return Organization{}, ErrNotImplemented
|
|
||||||
}
|
|
||||||
func (NotImplementedOrganizationRepository) Delete(ctx context.Context, id string) error {
|
|
||||||
return ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:generate mockery --name LearningCategoryRepository
|
|
||||||
type LearningCategoryRepository interface {
|
type LearningCategoryRepository interface {
|
||||||
Upsert(context.Context, LearningCategory) error
|
Upsert(context.Context, LearningCategory) error
|
||||||
|
|
||||||
List(context.Context) ([]LearningCategory, error)
|
List(context.Context) ([]LearningCategory, error)
|
||||||
Get(context.Context, string) (LearningCategory, error)
|
Get(context.Context, string) (LearningCategory, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotImplementedLearningCategory struct{}
|
|
||||||
|
|
||||||
func (NotImplementedLearningCategory) Upsert(context.Context, LearningCategory) error {
|
|
||||||
return ErrNotImplemented
|
|
||||||
}
|
|
||||||
func (NotImplementedLearningCategory) List(context.Context) ([]LearningCategory, error) {
|
|
||||||
return nil, ErrNotImplemented
|
|
||||||
}
|
|
||||||
func (NotImplementedLearningCategory) Get(context.Context, string) (LearningCategory, error) {
|
|
||||||
return LearningCategory{}, ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"git.loyso.art/frx/kurious/internal/common/errors"
|
"git.loyso.art/frx/kurious/internal/common/errors"
|
||||||
"git.loyso.art/frx/kurious/internal/common/xcontext"
|
"git.loyso.art/frx/kurious/internal/common/xcontext"
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
|
||||||
"git.loyso.art/frx/kurious/internal/kurious/service"
|
"git.loyso.art/frx/kurious/internal/kurious/service"
|
||||||
"git.loyso.art/frx/kurious/pkg/xdefault"
|
"git.loyso.art/frx/kurious/pkg/xdefault"
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ func handleError(ctx context.Context, err error, w http.ResponseWriter, log *slo
|
|||||||
case stderrors.As(err, &valErr):
|
case stderrors.As(err, &valErr):
|
||||||
errorString = valErr.Error()
|
errorString = valErr.Error()
|
||||||
code = http.StatusBadRequest
|
code = http.StatusBadRequest
|
||||||
case stderrors.Is(err, errors.ErrNotFound), stderrors.Is(err, domain.ErrNotFound):
|
case stderrors.Is(err, errors.ErrNotFound):
|
||||||
errorString = err.Error()
|
errorString = err.Error()
|
||||||
code = http.StatusNotFound
|
code = http.StatusNotFound
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user