Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 20 additions & 23 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"fmt"
"log"
"os"

"github.com/joho/godotenv"
_ "github.com/pangolin-do-golang/thumb-processor-api/docs"
dbAdapter "github.com/pangolin-do-golang/thumb-processor-api/internal/adapters/db"
"github.com/pangolin-do-golang/thumb-processor-api/internal/adapters/rest/server"
"github.com/pangolin-do-golang/thumb-processor-api/internal/adapters/sqs"
"github.com/pangolin-do-golang/thumb-processor-api/internal/config"
"github.com/pangolin-do-golang/thumb-processor-api/internal/core/thumb"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand All @@ -20,36 +20,33 @@ import (
// @host localhost:8080
// @BasePath /
func main() {
_, err := initDb()
cfg, err := config.Load()
if err != nil {
panic(err)
log.Fatalln(err)
}

/**

_ := dbAdapter.NewPostgresThumbRepository(db)

_ := thumb.NewThumbService()
databaseAdapter, err := newDatabaseConnection(cfg)
if err != nil {
log.Fatalln(err)
}

_ := dbAdapter.NewPostgresThumbRepository(db)
queueAdapter, err := sqs.NewSQSThumbQueue(cfg)
if err != nil {
log.Fatalln(err)
}

**/
thumbRepository := dbAdapter.NewPostgresThumbRepository(databaseAdapter)
thumbService := thumb.NewThumbService(thumbRepository, queueAdapter)

restServer := server.NewRestServer(&server.RestServerOptions{})
restServer := server.NewRestServer(&server.RestServerOptions{
ThumService: thumbService,
})

restServer.Serve()
}

func initDb() (*gorm.DB, error) {
_ = godotenv.Load()
dsn := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable TimeZone=America/Sao_Paulo",
os.Getenv("DB_USERNAME"),
os.Getenv("DB_PASSWORD"),
os.Getenv("DB_HOST"),
os.Getenv("DB_PORT"),
os.Getenv("DB_NAME"),
)
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
func newDatabaseConnection(cfg *config.Config) (*gorm.DB, error) {
db, err := gorm.Open(postgres.Open(cfg.DB.GetDNS()), &gorm.Config{})
if err != nil {
log.Panic(err)
}
Expand Down
212 changes: 212 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/health": {
"get": {
"description": "Checks the health status of the application.",
"produces": [
"application/json"
],
"tags": [
"Health Check"
],
"summary": "Health Check",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"/login": {
"get": {
"description": "Authenticates a user using Basic Authentication and returns user information.",
Expand Down Expand Up @@ -49,6 +70,138 @@ const docTemplate = `{
}
}
},
"/thumbs": {
"get": {
"description": "Get a list of all thumbnail processes",
"produces": [
"application/json"
],
"tags": [
"Video Thumbs Processor"
],
"summary": "List all thumbnail processes",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/handler.ThumbProcessResponse"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.ErrorResponse"
}
}
}
},
"post": {
"description": "Start a new asynchronous thumbnail generation process from S3 video URL",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Video Thumbs Processor"
],
"summary": "Create a new thumbnail process",
"parameters": [
{
"description": "Video URL",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handler.CreateProcessRequest"
}
}
],
"responses": {
"202": {
"description": "Process started",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handler.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.ErrorResponse"
}
}
}
}
},
"/thumbs/{id}": {
"put": {
"description": "Update the status of an existing thumbnail process",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Video Thumbs Processor"
],
"summary": "Update a thumbnail process",
"parameters": [
{
"type": "string",
"description": "Process ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Process update information",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handler.UpdateProcessRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.ThumbProcessResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handler.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handler.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.ErrorResponse"
}
}
}
}
},
"/user": {
"post": {
"description": "Creates a new user with the provided nickname and password.",
Expand Down Expand Up @@ -87,6 +240,17 @@ const docTemplate = `{
}
},
"definitions": {
"handler.CreateProcessRequest": {
"type": "object",
"required": [
"url"
],
"properties": {
"url": {
"type": "string"
}
}
},
"handler.CreateUserRequest": {
"type": "object",
"required": [
Expand All @@ -101,6 +265,54 @@ const docTemplate = `{
"type": "string"
}
}
},
"handler.ErrorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
},
"handler.ThumbProcessResponse": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"error": {
"type": "string"
},
"id": {
"type": "string"
},
"status": {
"type": "string"
},
"thumbnail_path": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
},
"handler.UpdateProcessRequest": {
"type": "object",
"required": [
"status"
],
"properties": {
"error": {
"type": "string"
},
"status": {
"type": "string"
},
"thumbnail_path": {
"type": "string"
}
}
}
}
}`
Expand Down
Loading
Loading