Skip to content

Commit c5798b8

Browse files
Merge pull request #3 from pangolin-do-golang/feature/thumb-process-api
Feature: thumb process api
2 parents a562082 + ce51f06 commit c5798b8

27 files changed

+2423
-96
lines changed

cmd/http/main.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package main
22

33
import (
4-
"fmt"
54
"log"
6-
"os"
75

8-
"github.com/joho/godotenv"
96
_ "github.com/pangolin-do-golang/thumb-processor-api/docs"
107
dbAdapter "github.com/pangolin-do-golang/thumb-processor-api/internal/adapters/db"
118
"github.com/pangolin-do-golang/thumb-processor-api/internal/adapters/rest/server"
9+
"github.com/pangolin-do-golang/thumb-processor-api/internal/adapters/sqs"
10+
"github.com/pangolin-do-golang/thumb-processor-api/internal/config"
11+
"github.com/pangolin-do-golang/thumb-processor-api/internal/core/thumb"
1212
"gorm.io/driver/postgres"
1313
"gorm.io/gorm"
1414
)
@@ -20,36 +20,33 @@ import (
2020
// @host localhost:8080
2121
// @BasePath /
2222
func main() {
23-
_, err := initDb()
23+
cfg, err := config.Load()
2424
if err != nil {
25-
panic(err)
25+
log.Fatalln(err)
2626
}
2727

28-
/**
29-
30-
_ := dbAdapter.NewPostgresThumbRepository(db)
31-
32-
_ := thumb.NewThumbService()
28+
databaseAdapter, err := newDatabaseConnection(cfg)
29+
if err != nil {
30+
log.Fatalln(err)
31+
}
3332

34-
_ := dbAdapter.NewPostgresThumbRepository(db)
33+
queueAdapter, err := sqs.NewSQSThumbQueue(cfg)
34+
if err != nil {
35+
log.Fatalln(err)
36+
}
3537

36-
**/
38+
thumbRepository := dbAdapter.NewPostgresThumbRepository(databaseAdapter)
39+
thumbService := thumb.NewThumbService(thumbRepository, queueAdapter)
3740

38-
restServer := server.NewRestServer(&server.RestServerOptions{})
41+
restServer := server.NewRestServer(&server.RestServerOptions{
42+
ThumService: thumbService,
43+
})
3944

4045
restServer.Serve()
4146
}
4247

43-
func initDb() (*gorm.DB, error) {
44-
_ = godotenv.Load()
45-
dsn := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable TimeZone=America/Sao_Paulo",
46-
os.Getenv("DB_USERNAME"),
47-
os.Getenv("DB_PASSWORD"),
48-
os.Getenv("DB_HOST"),
49-
os.Getenv("DB_PORT"),
50-
os.Getenv("DB_NAME"),
51-
)
52-
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
48+
func newDatabaseConnection(cfg *config.Config) (*gorm.DB, error) {
49+
db, err := gorm.Open(postgres.Open(cfg.DB.GetDNS()), &gorm.Config{})
5350
if err != nil {
5451
log.Panic(err)
5552
}

docs/docs.go

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ const docTemplate = `{
1515
"host": "{{.Host}}",
1616
"basePath": "{{.BasePath}}",
1717
"paths": {
18+
"/health": {
19+
"get": {
20+
"description": "Checks the health status of the application.",
21+
"produces": [
22+
"application/json"
23+
],
24+
"tags": [
25+
"Health Check"
26+
],
27+
"summary": "Health Check",
28+
"responses": {
29+
"200": {
30+
"description": "OK",
31+
"schema": {
32+
"type": "object",
33+
"additionalProperties": true
34+
}
35+
}
36+
}
37+
}
38+
},
1839
"/login": {
1940
"get": {
2041
"description": "Authenticates a user using Basic Authentication and returns user information.",
@@ -49,6 +70,138 @@ const docTemplate = `{
4970
}
5071
}
5172
},
73+
"/thumbs": {
74+
"get": {
75+
"description": "Get a list of all thumbnail processes",
76+
"produces": [
77+
"application/json"
78+
],
79+
"tags": [
80+
"Video Thumbs Processor"
81+
],
82+
"summary": "List all thumbnail processes",
83+
"responses": {
84+
"200": {
85+
"description": "OK",
86+
"schema": {
87+
"type": "array",
88+
"items": {
89+
"$ref": "#/definitions/handler.ThumbProcessResponse"
90+
}
91+
}
92+
},
93+
"500": {
94+
"description": "Internal Server Error",
95+
"schema": {
96+
"$ref": "#/definitions/handler.ErrorResponse"
97+
}
98+
}
99+
}
100+
},
101+
"post": {
102+
"description": "Start a new asynchronous thumbnail generation process from S3 video URL",
103+
"consumes": [
104+
"application/json"
105+
],
106+
"produces": [
107+
"application/json"
108+
],
109+
"tags": [
110+
"Video Thumbs Processor"
111+
],
112+
"summary": "Create a new thumbnail process",
113+
"parameters": [
114+
{
115+
"description": "Video URL",
116+
"name": "request",
117+
"in": "body",
118+
"required": true,
119+
"schema": {
120+
"$ref": "#/definitions/handler.CreateProcessRequest"
121+
}
122+
}
123+
],
124+
"responses": {
125+
"202": {
126+
"description": "Process started",
127+
"schema": {
128+
"type": "string"
129+
}
130+
},
131+
"400": {
132+
"description": "Bad Request",
133+
"schema": {
134+
"$ref": "#/definitions/handler.ErrorResponse"
135+
}
136+
},
137+
"500": {
138+
"description": "Internal Server Error",
139+
"schema": {
140+
"$ref": "#/definitions/handler.ErrorResponse"
141+
}
142+
}
143+
}
144+
}
145+
},
146+
"/thumbs/{id}": {
147+
"put": {
148+
"description": "Update the status of an existing thumbnail process",
149+
"consumes": [
150+
"application/json"
151+
],
152+
"produces": [
153+
"application/json"
154+
],
155+
"tags": [
156+
"Video Thumbs Processor"
157+
],
158+
"summary": "Update a thumbnail process",
159+
"parameters": [
160+
{
161+
"type": "string",
162+
"description": "Process ID",
163+
"name": "id",
164+
"in": "path",
165+
"required": true
166+
},
167+
{
168+
"description": "Process update information",
169+
"name": "request",
170+
"in": "body",
171+
"required": true,
172+
"schema": {
173+
"$ref": "#/definitions/handler.UpdateProcessRequest"
174+
}
175+
}
176+
],
177+
"responses": {
178+
"200": {
179+
"description": "OK",
180+
"schema": {
181+
"$ref": "#/definitions/handler.ThumbProcessResponse"
182+
}
183+
},
184+
"400": {
185+
"description": "Bad Request",
186+
"schema": {
187+
"$ref": "#/definitions/handler.ErrorResponse"
188+
}
189+
},
190+
"404": {
191+
"description": "Not Found",
192+
"schema": {
193+
"$ref": "#/definitions/handler.ErrorResponse"
194+
}
195+
},
196+
"500": {
197+
"description": "Internal Server Error",
198+
"schema": {
199+
"$ref": "#/definitions/handler.ErrorResponse"
200+
}
201+
}
202+
}
203+
}
204+
},
52205
"/user": {
53206
"post": {
54207
"description": "Creates a new user with the provided nickname and password.",
@@ -87,6 +240,17 @@ const docTemplate = `{
87240
}
88241
},
89242
"definitions": {
243+
"handler.CreateProcessRequest": {
244+
"type": "object",
245+
"required": [
246+
"url"
247+
],
248+
"properties": {
249+
"url": {
250+
"type": "string"
251+
}
252+
}
253+
},
90254
"handler.CreateUserRequest": {
91255
"type": "object",
92256
"required": [
@@ -101,6 +265,54 @@ const docTemplate = `{
101265
"type": "string"
102266
}
103267
}
268+
},
269+
"handler.ErrorResponse": {
270+
"type": "object",
271+
"properties": {
272+
"error": {
273+
"type": "string"
274+
}
275+
}
276+
},
277+
"handler.ThumbProcessResponse": {
278+
"type": "object",
279+
"properties": {
280+
"created_at": {
281+
"type": "string"
282+
},
283+
"error": {
284+
"type": "string"
285+
},
286+
"id": {
287+
"type": "string"
288+
},
289+
"status": {
290+
"type": "string"
291+
},
292+
"thumbnail_path": {
293+
"type": "string"
294+
},
295+
"updated_at": {
296+
"type": "string"
297+
}
298+
}
299+
},
300+
"handler.UpdateProcessRequest": {
301+
"type": "object",
302+
"required": [
303+
"status"
304+
],
305+
"properties": {
306+
"error": {
307+
"type": "string"
308+
},
309+
"status": {
310+
"type": "string"
311+
},
312+
"thumbnail_path": {
313+
"type": "string"
314+
}
315+
}
104316
}
105317
}
106318
}`

0 commit comments

Comments
 (0)