model

package
v0.0.0-...-8c9a138 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package model provides chat-related data models and database operations. It includes message handling functionality with CRUD operations using LevelDB and Protocol Buffers.

Package model provides data models and database operations for the DM-Backend application. It includes user management functionality with CRUD operations using LevelDB and Protocol Buffers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMessageNotFound     = errors.New("message not found")
	ErrChatHistoryNotFound = errors.New("chat history not found")
	ErrInvalidMessageID    = errors.New("message ID cannot be empty")
	ErrInvalidConvID       = errors.New("conversation ID cannot be empty")
)

Common errors for chat operations

View Source
var (
	ErrUserNotFound    = errors.New("user not found")
	ErrDatabaseOpen    = errors.New("failed to open database")
	ErrSerialize       = errors.New("failed to serialize user data")
	ErrDeserialize     = errors.New("failed to deserialize user data")
	ErrDatabaseWrite   = errors.New("failed to write to database")
	ErrDatabaseRead    = errors.New("failed to read from database")
	ErrDatabaseDelete  = errors.New("failed to delete from database")
	ErrInvalidUsername = errors.New("username cannot be empty")
)

Common errors for user operations

Functions

func UserExists

func UserExists(userName string) (bool, error)

UserExists checks if a user exists in the database. Returns true if the user exists, false otherwise.

Types

type User

type User struct {
	UserName      string `protobuf:"bytes,1,opt,name=user_name,json=userName,proto3" json:"user_name,omitempty"`
	PersonId      string `protobuf:"bytes,2,opt,name=person_id,json=personId,proto3" json:"person_id,omitempty"`
	Profile       string `protobuf:"bytes,3,opt,name=profile,proto3" json:"profile,omitempty"`
	Password      string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"`
	Email         string `protobuf:"bytes,5,opt,name=email,proto3" json:"email,omitempty"`
	ProfilePicUrl string `protobuf:"bytes,6,opt,name=profile_pic_url,json=profilePicUrl,proto3" json:"profile_pic_url,omitempty"`
	AccountTime   int64  `protobuf:"varint,7,opt,name=account_time,json=accountTime,proto3" json:"account_time,omitempty"`
	BirthDate     int64  `protobuf:"varint,8,opt,name=birth_date,json=birthDate,proto3" json:"birth_date,omitempty"`
	Gender        string `protobuf:"bytes,9,opt,name=gender,proto3" json:"gender,omitempty"`
	LastEdit      int64  `protobuf:"varint,10,opt,name=last_edit,json=lastEdit,proto3" json:"last_edit,omitempty"`
	PhoneNumber   string `protobuf:"bytes,11,opt,name=phone_number,json=phoneNumber,proto3" json:"phone_number,omitempty"`
	// contains filtered or unexported fields
}

func (*User) DeleteUserData

func (d *User) DeleteUserData(userName string) error

DeleteUserData removes the user data from the database. Returns an error if the user is not found or if the delete operation fails.

func (*User) Descriptor deprecated

func (*User) Descriptor() ([]byte, []int)

Deprecated: Use User.ProtoReflect.Descriptor instead.

func (*User) GetAccountTime

func (x *User) GetAccountTime() int64

func (*User) GetBirthDate

func (x *User) GetBirthDate() int64

func (*User) GetEmail

func (x *User) GetEmail() string

func (*User) GetGender

func (x *User) GetGender() string

func (*User) GetLastEdit

func (x *User) GetLastEdit() int64

func (*User) GetPassword

func (x *User) GetPassword() string

func (*User) GetPersonId

func (x *User) GetPersonId() string

func (*User) GetPhoneNumber

func (x *User) GetPhoneNumber() string

func (*User) GetProfile

func (x *User) GetProfile() string

func (*User) GetProfilePicUrl

func (x *User) GetProfilePicUrl() string

func (*User) GetUserData

func (g *User) GetUserData(userName string) error

GetUserData retrieves user data from the database using the provided username. The retrieved data is unmarshaled into the User struct receiver. Returns an error if the user is not found or if database operations fail.

func (*User) GetUserName

func (x *User) GetUserName() string

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) ProtoReflect

func (x *User) ProtoReflect() protoreflect.Message

func (*User) Reset

func (x *User) Reset()

func (*User) SaveUserData

func (s *User) SaveUserData() error

SaveUserData persists the user data to the LevelDB database. It uses the PersonId as the key for storage. Returns an error if the database operation fails.

func (*User) String

func (x *User) String() string

func (*User) UpdateUserData

func (u *User) UpdateUserData(userName string) error

UpdateUserData updates the user data in the database. It retrieves the existing user by username, updates with new data from the receiver, and writes the updated data back to the database. Returns an error if the user is not found or if database operations fail.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL