Skip to content

Commit

Permalink
#fix Variable naming bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JonyBepary committed Oct 21, 2023
1 parent 0f349a0 commit e93a4f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions internal/model/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Comments is the database model for comments.
func (cm *Comments) Get() error {
func (cm *Comment) Get() error {
//leveldb get
db, err := leveldb.OpenFile("Database/comments", nil)
if err != nil {
Expand All @@ -26,7 +26,7 @@ func (cm *Comments) Get() error {
return nil
}

func (cm *Comments) Save() error {
func (cm *Comment) Save() error {
//leveldb put
db, err := leveldb.OpenFile("Database/comments", nil)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func (cm *Comments) Save() error {
return nil
}

func GetNComments(postId string, N int) ([]*Comments, error) {
func GetNComments(postId string, N int) ([]*Comment, error) {
//leveldb get
db, err := leveldb.OpenFile("Database/comments", nil)
if err != nil {
Expand All @@ -53,9 +53,9 @@ func GetNComments(postId string, N int) ([]*Comments, error) {
defer db.Close()
iterator := db.NewIterator(nil, nil)
defer iterator.Release()
var comments []*Comments
var comments []*Comment
for iterator.Next() && len(comments) < N+1 {
var cm Comments
var cm Comment
err = proto.Unmarshal(iterator.Value(), &cm)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions internal/model/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestComments_Save_Get(t *testing.T) {
// Create a new Comments object with some data
cm := &Comments{
cm := &Comment{

PostId: "1",
Id: "2",
Expand All @@ -33,7 +33,7 @@ func TestComments_Save_Get(t *testing.T) {
}

// Unmarshal the data and check that it matches the original Comments object
var savedCm Comments
var savedCm Comment
err = proto.Unmarshal(data, &savedCm)
if err != nil {
panic(err)
Expand All @@ -45,9 +45,9 @@ func TestComments_Save_Get(t *testing.T) {

func TestGetNComments(t *testing.T) {
// Create 10 Comments objects with different post IDs
var comments []*Comments
var comments []*Comment
for i := 1; i <= 10; i++ {
cm := &Comments{
cm := &Comment{
PostId: "1",
Id: fmt.Sprint(i),
Text: fmt.Sprintf("This is comment %d", i),
Expand Down
6 changes: 3 additions & 3 deletions internal/model/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (msg *Messages) SaveMessages() error {
LastEdit TEXT,
DeleteTime TEXT,
Status BOOL,
Attachment BLOB,
Attachment BLOB,
Type TEXT,
Reaction TEXT)
`
Expand All @@ -40,7 +40,7 @@ func (msg *Messages) SaveMessages() error {
panic(err)
}

_, err = statement.Exec(msg.MsgId, msg.SenderId, msg.ReceiverId, msg.Content, msg.SentTime.String(), msg.LastEdit.String(), msg.DeleteTime.String(), msg.Status, msg.Type, msg.Reaction)
_, err = statement.Exec(msg.MsgId, msg.SenderId, msg.ReceiverId, msg.Content, msg.SentTime.String(), msg.LastEdit.String(), msg.DeleteTime.String(), msg.Status, msg.Types, msg.Reaction)
if err != nil {
panic(err)
}
Expand All @@ -64,7 +64,7 @@ func (m *Messages) GetMessages(msgId string) error {
SentTime := ""
LastEdit := ""
DeleteTime := ""
err = rows.Scan(&m.MsgId, &m.SenderId, &m.ReceiverId, &m.Content, &SentTime, &LastEdit, &DeleteTime, &m.Status, &m.Attachment, &m.Type, &m.Reaction)
err = rows.Scan(&m.MsgId, &m.SenderId, &m.ReceiverId, &m.Content, &SentTime, &LastEdit, &DeleteTime, &m.Status, &m.Attachment, &m.Types, &m.Reaction)

if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit e93a4f4

Please sign in to comment.