database changes

This commit is contained in:
2026-02-12 15:09:06 +03:00
parent c5448b14f6
commit 022cf4ba06
18 changed files with 202 additions and 223 deletions

View File

@@ -12,19 +12,19 @@ type AiRepository struct {
client *redis.Client
}
func NewAiRepository(db *laniakea.DatabaseContext) *AiRepository {
return &AiRepository{client: db.Redis}
func NewAiRepository(db *laniakea.DatabaseContext) AiRepository {
return AiRepository{client: db.Redis}
}
func (rep *AiRepository) SetChatId(userId int, chatId string) error {
func (rep AiRepository) SetChatId(userId int, chatId string) error {
key := fmt.Sprintf("ai.chats.gpt.%d", userId)
return rep.client.Set(ctx, key, chatId, 0).Err()
}
func (rep *AiRepository) GetChatId(userId int) (string, error) {
func (rep AiRepository) GetChatId(userId int) (string, error) {
key := fmt.Sprintf("ai.chats.gpt.%d", userId)
return rep.client.Get(ctx, key).Result()
}
func (rep *AiRepository) GetOrCreateChatId(userId int) (string, error) {
func (rep AiRepository) GetOrCreateChatId(userId int) (string, error) {
key := fmt.Sprintf("ai.chats.gpt.%d", userId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {