feat: add simple docker compose file, change pipline, add docker build command to makefile, update db path logic in storage packages, minor fixes in handlers

This commit is contained in:
d3m0k1d
2026-02-14 14:40:42 +03:00
parent c2d5178b33
commit 3bf3e2a233
8 changed files with 71 additions and 12 deletions

View File

@@ -1,10 +1,6 @@
name: Backend ci name: Backend ci
on: on:
push:
branches:
- master
- develop
pull_request: pull_request:
branches: branches:
- master - master

View File

@@ -1,4 +1,4 @@
.PHONY: test build clean lint dev run-docker docs-upd .PHONY: test build clean lint dev run-docker docs-upd docker
test: test:
@@ -25,6 +25,9 @@ docs-upd:
swag init -g ./cmd/main.go --parseDependency --parseInternal swag init -g ./cmd/main.go --parseDependency --parseInternal
docker:
docker build -t backend .
run-docker: run-docker:
docker build -t backend . docker build -t backend .
docker run --rm -p 8080:8080 --env-file .env backend:latest docker run --rm -p 8080:8080 --env-file .env backend:latest

View File

@@ -0,0 +1,12 @@
services:
backend:
image: backend:latest
env_file:
- .env
ports:
- 8080:8080
volumes:
- db-data:/var/lib/backend/data
volumes:
db-data:

View File

@@ -179,6 +179,15 @@ const docTemplate = `{
} }
} }
}, },
"404": {
"description": "Post not found",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": { "500": {
"description": "Internal server error", "description": "Internal server error",
"schema": { "schema": {
@@ -241,6 +250,15 @@ const docTemplate = `{
"posts" "posts"
], ],
"summary": "Delete post", "summary": "Delete post",
"parameters": [
{
"type": "integer",
"description": "Post ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",

View File

@@ -168,6 +168,15 @@
} }
} }
}, },
"404": {
"description": "Post not found",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": { "500": {
"description": "Internal server error", "description": "Internal server error",
"schema": { "schema": {
@@ -230,6 +239,15 @@
"posts" "posts"
], ],
"summary": "Delete post", "summary": "Delete post",
"parameters": [
{
"type": "integer",
"description": "Post ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",

View File

@@ -120,6 +120,12 @@ paths:
consumes: consumes:
- application/json - application/json
description: Delete post description: Delete post
parameters:
- description: Post ID
in: path
name: id
required: true
type: integer
produces: produces:
- application/json - application/json
responses: responses:
@@ -153,6 +159,12 @@ paths:
additionalProperties: additionalProperties:
type: string type: string
type: object type: object
"404":
description: Post not found
schema:
additionalProperties:
type: string
type: object
"500": "500":
description: Internal server error description: Internal server error
schema: schema:

View File

@@ -20,8 +20,8 @@ func Register(router *gin.Engine, db *sql.DB) {
posts.GET("/", handler_posts.GetPosts) posts.GET("/", handler_posts.GetPosts)
posts.GET("/:id", handler_posts.GetPost) posts.GET("/:id", handler_posts.GetPost)
posts.POST("/", handler_posts.CreatePost) posts.POST("/", auth.JWTMiddleware(), handler_posts.CreatePost)
posts.PUT("/:id", handler_posts.UpdatePost) posts.PUT("/:id", auth.JWTMiddleware(), handler_posts.UpdatePost)
posts.DELETE("/:id", handler_posts.DeletePost).Use(auth.JWTMiddleware()) posts.DELETE("/:id", auth.JWTMiddleware(), handler_posts.DeletePost)
} }
} }

View File

@@ -8,9 +8,9 @@ import (
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
) )
var db_path = os.Getenv( var path = os.Getenv("DB_PATH")
"DB_PATH",
) + "?_journal_mode=WAL&_busy_timeout=5000&_synchronous=NORMAL&_cache_size=2000&_foreign_keys=ON" var params = "?_journal_mode=WAL&_busy_timeout=5000&_synchronous=NORMAL&_cache_size=2000&_foreign_keys=ON"
func CreateTables(db *sql.DB) error { func CreateTables(db *sql.DB) error {
logger := logger.New(false) logger := logger.New(false)
@@ -24,7 +24,7 @@ func CreateTables(db *sql.DB) error {
} }
func OpenSession() (*sql.DB, error) { func OpenSession() (*sql.DB, error) {
db, err := sql.Open("sqlite", db_path) db, err := sql.Open("sqlite", path+params)
if err != nil { if err != nil {
return nil, err return nil, err
} }