Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2 #4

Open
wants to merge 37 commits into
base: dev2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c4f2aeb
added docker compose and init.sql
source-Alexander-Rudenko Oct 21, 2024
a9c82a1
connection to pg + new libs
source-Alexander-Rudenko Oct 21, 2024
4b77c74
repository users update
source-Alexander-Rudenko Oct 21, 2024
d1859de
event db
Achpochmak Oct 23, 2024
34d4853
migrations
Achpochmak Oct 24, 2024
c1e601e
sql query
Achpochmak Oct 24, 2024
cf96309
session
Achpochmak Oct 25, 2024
4ded7ee
dz1 markdown added
source-Alexander-Rudenko Oct 27, 2024
e342e1d
mermaid added
source-Alexander-Rudenko Oct 27, 2024
c6d629b
categories
Achpochmak Oct 27, 2024
0ba3a1d
Merge branch 'db2' of https://github.com/go-park-mail-ru/2024_2_Team7…
Achpochmak Oct 27, 2024
d4f3728
categories
Achpochmak Oct 27, 2024
8570160
get by tags
Achpochmak Oct 30, 2024
e98ce75
images
Achpochmak Oct 31, 2024
a3cbddc
update user
Achpochmak Nov 1, 2024
a139340
error logger
Achpochmak Nov 2, 2024
58d44a6
docker-compose & makefile update
source-Alexander-Rudenko Nov 3, 2024
ce17e2b
pagination
Achpochmak Nov 4, 2024
7425b76
migrations in db init
source-Alexander-Rudenko Nov 4, 2024
b679c5f
handler test
Achpochmak Nov 5, 2024
4205616
handler test
Achpochmak Nov 5, 2024
13a9e32
Merge branch 'db2' of https://github.com/go-park-mail-ru/2024_2_Team7…
Achpochmak Nov 5, 2024
85edfdf
merge
Achpochmak Nov 5, 2024
069635a
swagger
Achpochmak Nov 5, 2024
ccd3725
events repo tests
Achpochmak Nov 7, 2024
3078d5d
search
Achpochmak Nov 8, 2024
201b16b
search
Achpochmak Nov 8, 2024
d56c16c
compose for vm
source-Alexander-Rudenko Nov 8, 2024
25ecddb
Update cors.go
Achpochmak Nov 8, 2024
e8acac4
Update add_event.go
Achpochmak Nov 8, 2024
eaf74c6
Update update_event.go
Achpochmak Nov 8, 2024
176ed09
event_db fill
source-Alexander-Rudenko Nov 8, 2024
37df7f2
another compose
source-Alexander-Rudenko Nov 9, 2024
cf78e06
favorites
Achpochmak Nov 14, 2024
450d815
subscription
Achpochmak Nov 15, 2024
a7008d2
get subscriptions
Achpochmak Nov 16, 2024
19530af
vm compose
source-Alexander-Rudenko Nov 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
pkg
coverage.out
.vscode
c.out
c.out
.env
pgdata
auth_test.go
31 changes: 31 additions & 0 deletions Makefile
reddiridabl666 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
MIGRATION_FOLDER=$(INTERNAL_REPO_PATH)migrations

build:
docker compose build

up-all:
docker compose up -d

down:
docker compose down

test:
go test -coverprofile=c.out ./... -coverpkg="./..." && go tool cover -func c.out | grep total

up-db:
docker compose up -d postgres

stop-db:
docker compose stop postgres

start-db:
docker compose start postgres

down-db:
docker compose down postgres

migration-up-oms:
goose -dir "$(MIGRATION_FOLDER)" postgres "$(POSTGRES_OMS_SETUP)" up

migration-down-oms:
goose -dir "$(MIGRATION_FOLDER)" postgres "$(POSTGRES_OMS_SETUP)" down
38 changes: 26 additions & 12 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
_ "kudago/docs"
"kudago/internal/http/auth"
"kudago/internal/http/events"
"kudago/internal/logger"
"kudago/internal/middleware"
eventRepository "kudago/internal/repository/events"
"kudago/internal/repository/postgres"
eventRepository "kudago/internal/repository/postgres/events"
userRepository "kudago/internal/repository/postgres/users"
sessionRepository "kudago/internal/repository/session"
userRepository "kudago/internal/repository/users"

authService "kudago/internal/service/auth"
eventService "kudago/internal/service/events"

httpSwagger "github.com/swaggo/http-swagger"

"github.com/gorilla/mux"
"go.uber.org/zap"
)

// swag init
Expand All @@ -31,16 +33,26 @@ import (
func main() {
port := config.LoadConfig()

logger, err := zap.NewProduction()
appLogger, err := logger.NewLogger()
if err != nil {
log.Fatalf("Server failed to start logger: %v", err)
}
defer logger.Sync()
sugar := logger.Sugar()
defer appLogger.Logger.Sync()

redisConfig, err := sessionRepository.GetRedisConfig()
reddiridabl666 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Fatalf("Failed to connect to the redis database")
}
postgresConfig, err := postgres.GetPostgresConfig()
pool, err := postgres.InitPostgres(postgresConfig, appLogger)
if err != nil {
log.Fatalf("Failed to connect to the postgres database")
}
defer pool.Close()

userDB := userRepository.NewDB()
sessionDB := sessionRepository.NewDB()
eventDB := eventRepository.NewDB()
userDB := userRepository.NewDB(pool)
sessionDB := sessionRepository.NewDB(redisConfig)
eventDB := eventRepository.NewDB(pool)

authService := authService.NewService(userDB, sessionDB)
eventService := eventService.NewService(eventDB)
Expand All @@ -62,8 +74,10 @@ func main() {
r.HandleFunc("/profile", authHandler.Profile).Methods("GET")

r.HandleFunc("/events/{id:[0-9]+}", eventHandler.GetEventByID).Methods("GET")
r.HandleFunc("/events/{tag}", eventHandler.GetEventsByTag).Methods("GET")
r.HandleFunc("/events/tags", eventHandler.GetEventsByTags).Methods("GET")
r.HandleFunc("/events/categories/{category}", eventHandler.GetEventsByCategory).Methods("GET")
r.HandleFunc("/events", eventHandler.GetAllEvents).Methods("GET")
r.HandleFunc("/categories", eventHandler.GetCategories).Methods("GET")
r.HandleFunc("/events/{id:[0-9]+}", eventHandler.UpdateEvent).Methods("PUT")
r.HandleFunc("/events/{id:[0-9]+}", eventHandler.DeleteEvent).Methods("DELETE")
r.HandleFunc("/events", eventHandler.AddEvent).Methods("POST")
Expand All @@ -75,13 +89,13 @@ func main() {
"/static",
"/session",
"/logout",
"/swagger",
"/docs",
"/categories",
}

handlerWithAuth := middleware.AuthMiddleware(whitelist, authHandler, r)
handlerWithCORS := middleware.CORSMiddleware(handlerWithAuth)
handlerWithLogging := middleware.LoggingMiddleware(handlerWithCORS, sugar)
handlerWithLogging := middleware.LoggingMiddleware(handlerWithCORS, appLogger.Logger)
handler := middleware.PanicMiddleware(handlerWithLogging)

err = http.ListenAndServe(":"+port, handler)
Expand Down
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.8'
services:
api:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- postgres
environment:
POSTGRES_DB: kudago_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
env_file:
- .env
volumes:
- .:/app

postgres:
image: postgres:latest
container_name: my_postgres_container
restart: unless-stopped
env_file:
- .env
ports:
- "5432:5432"
reddiridabl666 marked this conversation as resolved.
Show resolved Hide resolved
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:latest
ports:
- "6379:6379"

volumes:
postgres_data:
driver: local
159 changes: 130 additions & 29 deletions docs/docs.go
reddiridabl666 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/categories": {
"get": {
"description": "Получить список всех доступных категорий событий",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"categories"
],
"summary": "Получить все категории",
"responses": {
"200": {
"description": "Список категорий",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Category"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httpErrors.HttpError"
}
}
}
}
},
"/events": {
"get": {
"description": "Получить все существующие события",
Expand All @@ -29,12 +61,32 @@ const docTemplate = `{
"events"
],
"summary": "Получить все события",
"parameters": [
{
"type": "integer",
"description": "Номер страницы (по умолчанию 1)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "Количество событий на странице (по умолчанию 30)",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/events.GetEventsResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httpErrors.HttpError"
}
}
}
},
Expand Down Expand Up @@ -78,6 +130,58 @@ const docTemplate = `{
}
}
},
"/events/categories/{category}": {
"get": {
"description": "Возвращает события по ID категории",
"produces": [
"application/json"
],
"tags": [
"events"
],
"summary": "Получение событий по категори",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/events.GetEventsResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httpErrors.HttpError"
}
}
}
}
},
"/events/tags/{tag}": {
"get": {
"description": "Возвращает события по тегу",
"produces": [
"application/json"
],
"tags": [
"events"
],
"summary": "Получение событий по тегу",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/events.GetEventsResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httpErrors.HttpError"
}
}
}
}
},
"/events/{id}": {
"get": {
"description": "Возвращает информацию о событии по его идентификатору",
Expand Down Expand Up @@ -200,32 +304,6 @@ const docTemplate = `{
}
}
},
"/events/{tag}": {
"get": {
"description": "Возвращает события по тегу",
"produces": [
"application/json"
],
"tags": [
"events"
],
"summary": "Получение событий по тегу",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/events.GetEventsResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/httpErrors.HttpError"
}
}
}
}
},
"/login": {
"post": {
"description": "Авторизует пользователя",
Expand Down Expand Up @@ -424,18 +502,30 @@ const docTemplate = `{
"author": {
"type": "integer"
},
"date_end": {
"capacity": {
"type": "integer"
},
"category_id": {
"type": "integer"
},
"description": {
"type": "string"
},
"date_start": {
"event_end": {
"type": "string"
},
"description": {
"event_start": {
"type": "string"
},
"id": {
"type": "integer"
},
"image": {
"type": "string"
},
"location": {
"type": "string"
},
"tag": {
"type": "array",
"items": {
Expand Down Expand Up @@ -480,6 +570,17 @@ const docTemplate = `{
}
}
},
"models.Category": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"utils.ValidationErrResponse": {
"type": "object",
"properties": {
Expand Down
Loading