Add Support to consume/redeem points

Support Creating task/chore via api
Add initial Description for tasks
This commit is contained in:
Mo Tarbin 2025-01-14 10:43:05 -05:00
parent 50b1357dfa
commit ac733343da
11 changed files with 368 additions and 66 deletions

21
internal/points/model.go Normal file
View file

@ -0,0 +1,21 @@
package model
import "time"
type PointsHistory struct {
ID int `json:"id" gorm:"primary_key"` // Unique identifier
Action PointsHistoryAction `json:"action" gorm:"column:action"` // Action
Points int `json:"points" gorm:"column:points"` // Points
CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` // Created at
CreatedBy int `json:"created_by" gorm:"column:created_by"` // Created by
UserID int `json:"user_id" gorm:"column:user_id;index"` // User ID
CircleID int `json:"circle_id" gorm:"column:circle_id;index"` // Circle ID with index
}
type PointsHistoryAction int8
const (
PointsHistoryActionAdd PointsHistoryAction = iota
PointsHistoryActionRemove
PointsHistoryActionRedeem
)

View file

@ -0,0 +1,24 @@
package points
import (
"context"
pModel "donetick.com/core/internal/points"
"gorm.io/gorm"
)
type PointsRepository struct {
db *gorm.DB
}
func NewPointsRepository(db *gorm.DB) *PointsRepository {
return &PointsRepository{db}
}
func (r *PointsRepository) CreatePointsHistory(c context.Context, tx *gorm.DB, pointsHistory *pModel.PointsHistory) error {
if tx != nil {
return tx.Model(&pModel.PointsHistory{}).Save(pointsHistory).Error
}
return r.db.WithContext(c).Save(pointsHistory).Error
}