Compare commits

..

3 Commits

Author SHA1 Message Date
d3m0k1d
9094f5e278 feat: update dockerfiles and add .dockerignore 2026-02-28 23:05:29 +03:00
d3m0k1d
bb987b1f8b feat: add logic for repository 2026-02-18 13:43:00 +03:00
d3m0k1d
3fcaefba1b feat: 2026-02-18 13:42:42 +03:00
5 changed files with 67 additions and 10 deletions

6
backend/.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.git
docker-compose.yml
data/
Makefile
.env
docs/

View File

@@ -3,18 +3,21 @@ FROM golang:1.25.6 AS builder
WORKDIR /app
COPY . .
ENV CGO_ENABLED=0
ENV GIN_MODE=release
RUN go mod tidy
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -ldflags "-s -w" -o backend ./cmd/main.go
FROM alpine:3.23.0
RUN adduser -D appuser && apk add --no-cache curl
COPY --from=builder /app/backend .
RUN chown appuser:appuser ./backend
USER appuser
EXPOSE 8080
RUN apk add --no-cache curl
HEALTHCHECK CMD curl --fail http://localhost:8080/health || exit 1
CMD ["./backend"]

View File

@@ -21,15 +21,55 @@ func NewCommentsRepository(db *sql.DB) CommentRepository {
}
}
func (c *commentsRepository) CreateComment(ctx context.Context, comment *storage.Comment) error {
func (c *commentsRepository) CreateComment(
ctx context.Context,
comment *storage.CommentCreate,
) error {
_, err := c.db.Exec(
"INSERT INTO comments(content, post_id) VALUES(?, ?, ?)",
comment.Content,
comment.PostID,
comment.UserID,
)
if err != nil {
c.logger.Error("error insert: " + err.Error())
return err
}
return nil
}
func (c *commentsRepository) GetAllComments(ctx context.Context) ([]storage.Comment, error) {
return nil, nil
var result []storage.Comment
rows, err := c.db.Query("SELECT id, content, post_id, user_id, created_at FROM comments")
if err != nil {
c.logger.Error("error scan " + err.Error())
return nil, err
}
for rows.Next() {
var id int
var content string
var postID int
var userID int
var createdAt string
err := rows.Scan(&id, &content, &postID, &userID, &createdAt)
if err != nil {
c.logger.Error("error scan: " + err.Error())
}
result = append(result, storage.Comment{
ID: id,
Content: content,
PostID: postID,
UserID: userID,
CreatedAt: createdAt,
})
}
return result, nil
}
func (c *commentsRepository) GetCommentsOfPost(ctx context.Context, id int) ([]storage.Comment, error) {
func (c *commentsRepository) GetCommentsOfPost(
ctx context.Context,
id int,
) ([]storage.Comment, error) {
return nil, nil
}
@@ -37,6 +77,10 @@ func (c *commentsRepository) DeleteComment(ctx context.Context, id int) error {
return nil
}
func (c *commentsRepository) UpdateComment(ctx context.Context, id int, comment *storage.Comment) error {
func (c *commentsRepository) UpdateComment(
ctx context.Context,
id int,
comment *storage.Comment,
) error {
return nil
}

View File

@@ -24,7 +24,7 @@ type AuthRepository interface {
}
type CommentRepository interface {
CreateComment(ctx context.Context, comment *storage.Comment) error
CreateComment(ctx context.Context, comment *storage.CommentCreate) error
GetAllComments(ctx context.Context) ([]storage.Comment, error)
GetCommentsOfPost(ctx context.Context, id int) ([]storage.Comment, error)
DeleteComment(ctx context.Context, id int) error

4
frontend/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
Makefile
dist
node_modules