-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#Added CRUD mechanism for post structure
- Loading branch information
1 parent
e0652fe
commit 04bc2ab
Showing
1 changed file
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |