chore: add code for 2 handlers with GET
Some checks failed
Backend ci / build (push) Failing after 36m27s
Some checks failed
Backend ci / build (push) Failing after 36m27s
This commit is contained in:
@@ -19,13 +19,42 @@ func NewPostRepository(db *sql.DB) PostRepository {
|
||||
logger: logger.New(false),
|
||||
}
|
||||
}
|
||||
func (p *postRepository) GetAll(ctx context.Context) ([]storage.Post, error) {
|
||||
return nil, nil
|
||||
func (p *postRepository) GetAll(ctx context.Context) ([]storage.PostReq, error) {
|
||||
var result []storage.PostReq
|
||||
rows, err := p.db.Query("SELECT title content FROM posts")
|
||||
if err != nil {
|
||||
p.logger.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
for rows.Next() {
|
||||
var title string
|
||||
var content string
|
||||
err := rows.Scan(&title, &content)
|
||||
if err != nil {
|
||||
p.logger.Error("error scan: " + err.Error())
|
||||
}
|
||||
result = append(result, storage.PostReq{
|
||||
Title: title,
|
||||
Content: content,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *postRepository) GetByID(ctx context.Context, id int) (storage.Post, error) {
|
||||
|
||||
return storage.Post{}, nil
|
||||
func (p *postRepository) GetByID(ctx context.Context, id int) (storage.PostReq, error) {
|
||||
var result storage.PostReq
|
||||
row := p.db.QueryRow("SELECT title content FROM posts WHERE id = ?", id)
|
||||
var title string
|
||||
var content string
|
||||
err := row.Scan(&title, &content)
|
||||
if err != nil {
|
||||
p.logger.Error("error scan: " + err.Error())
|
||||
}
|
||||
result = storage.PostReq{
|
||||
Title: title,
|
||||
Content: content,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *postRepository) Create(ctx context.Context, post storage.Post) error {
|
||||
|
||||
Reference in New Issue
Block a user