Skip to content

Commit

Permalink
#Added CRUD mechanism for post structure
Browse files Browse the repository at this point in the history
  • Loading branch information
JonyBepary committed Oct 21, 2023
1 parent e0652fe commit 04bc2ab
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions internal/model/post.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package model

import (
"github.com/SohelAhmedJoni/Awazz-Backend/internal/durable"
)

func (p *Post) SavePost() error {
db, err := durable.CreateDatabase("./Database/", p.FragmentationKey, "post.sqlite")
if err != nil {
panic(err)
}
defer db.Close()
str := `
CREATE TABLE IF NOT EXISTS Post (
Id VARCHAR(128) PRIMARY KEY,
Community VARCHAR(128),
Content TEXT,
CreatedAt TIMESTAMP,
UpdatedAt TIMESTAMP,
DeletedAt TIMESTAMP,
Likes INT,
Shares INT,
Comments INT,
Author VARCHAR(128),
Parent INT,
Rank INT,
IsSensitive bool,
IsNsfw bool,
IsDeleted bool,
IsPinned bool,
IsEdited bool,
IsLiked bool,
IsShared bool,
IsCommented bool,
IsSubscribed bool,
IsBookmarked bool,
IsReblogged bool,
IsMentioned bool,
IsPoll bool,
IsPollVoted bool,
IsPollExpired bool,
IsPollClosed bool,
IsPollMultiple bool,
IsPollHideTotals bool,
FragmentationKey VARCHAR(128))
`
_, err = db.Exec(str)
if err != nil {
panic(err)
}
str2 := `
INSERT INTO Post (
Id,Community,Content,CreatedAt,UpdatedAt,DeletedAt,Likes,Shares,Comments,Author,Parent,Rank,IsSensitive,IsNsfw,IsDeleted,IsPinned,IsEdited,IsLiked,IsShared,IsCommented,IsSubscribed,IsBookmarked,IsReblogged,IsMentioned,IsPoll,IsPollVoted,IsPollExpired,IsPollClosed,IsPollMultiple,IsPollHideTotals,FragmentationKey) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);
`
statement, err := db.Prepare(str2)
if err != nil {
panic(err)
}
_, err = statement.Exec(p.Id,
p.Community,
p.Content,
p.CreatedAt.String(),
p.UpdatedAt.String(),
p.DeletedAt.String(),
p.Likes,
p.Shares,
p.Comments,
p.Author,
p.Parent,
p.Rank,
p.IsSensitive,
p.IsNsfw,
p.IsDeleted,
p.IsPinned,
p.IsEdited,
p.IsLiked,
p.IsShared,
p.IsCommented,
p.IsSubscribed,
p.IsBookmarked,
p.IsReblogged,
p.IsMentioned,
p.IsPoll,
p.IsPollVoted,
p.IsPollExpired,
p.IsPollClosed,
p.IsPollMultiple,
p.IsPollHideTotals,
p.IsPollHideTotals,
p.FragmentationKey,
)
if err != nil {
panic(err)
}

return nil
}
func (p *Post) GetPost(postid string) error {
db,
err := durable.CreateDatabase("Database/post")
if err != nil {
panic(err)
}
defer db.Close()
return nil
}
func (p *Post) UpdatePost(postid string) error {
db, err := durable.CreateDatabase("Database/Post")
if err != nil {
panic(err)
}
defer db.Close()
return nil
}
func (p *Post) DeletePost(postid string) error {
db, err := durable.CreateDatabase("Database/Post")
if err != nil {
panic(err)
}
defer db.Close()
return nil
}

0 comments on commit 04bc2ab

Please sign in to comment.