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 6 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ coverage.out
.vscode
c.out
.env
pgdata
pgdata
auth_test.go
3 changes: 3 additions & 0 deletions Makefile
reddiridabl666 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ up-all:
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

Expand Down
35 changes: 18 additions & 17 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
"log"
"net/http"

"kudago/internal/db"

"kudago/config"
_ "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 @@ -33,25 +33,25 @@ 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()

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

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

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

r.HandleFunc("/events/{id:[0-9]+}", eventHandler.GetEventByID).Methods("GET")
r.HandleFunc("/events/tags/{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 @@ -88,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
66 changes: 63 additions & 3 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,6 +61,20 @@ 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",
Expand Down Expand Up @@ -86,7 +132,7 @@ const docTemplate = `{
},
"/events/categories/{category}": {
"get": {
"description": "Возвращает события по категории",
"description": "Возвращает события по ID категории",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -459,8 +505,8 @@ const docTemplate = `{
"capacity": {
"type": "integer"
},
"category": {
"type": "string"
"category_id": {
"type": "integer"
},
"description": {
"type": "string"
Expand All @@ -474,6 +520,9 @@ const docTemplate = `{
"id": {
"type": "integer"
},
"image": {
"type": "string"
},
"location": {
"type": "string"
},
Expand Down Expand Up @@ -521,6 +570,17 @@ const docTemplate = `{
}
}
},
"models.Category": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"utils.ValidationErrResponse": {
"type": "object",
"properties": {
Expand Down
Loading