Compare commits
3 Commits
5a375d67c7
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9094f5e278 | ||
|
|
bb987b1f8b | ||
|
|
3fcaefba1b |
6
backend/.dockerignore
Normal file
6
backend/.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
||||
.git
|
||||
docker-compose.yml
|
||||
data/
|
||||
Makefile
|
||||
.env
|
||||
docs/
|
||||
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
4
frontend/.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
||||
Makefile
|
||||
dist
|
||||
node_modules
|
||||
|
||||
Reference in New Issue
Block a user