-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
68 lines (56 loc) · 1.54 KB
/
app.go
File metadata and controls
68 lines (56 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"encoding/json"
"errors"
"github.com/fauzancodes/github-wrapped-app/app/dto"
"github.com/fauzancodes/github-wrapped-app/app/models"
"github.com/fauzancodes/github-wrapped-app/app/repository"
"github.com/fauzancodes/github-wrapped-app/app/service"
"github.com/google/uuid"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) GenerateData(request dto.Request) (result models.GWAResult, err error) {
if err = request.Validate(); err != nil {
err = errors.New("failed to validate request: " + err.Error())
return
}
result, err = service.GenerateData(request.PersonalAccessToken, request.StartDate, request.EndDate)
if err != nil {
err = errors.New("failed to generate data: " + err.Error())
return
}
return
}
func (a *App) GetData(id string) (result models.GWAResult, err error) {
parsedUUID, err := uuid.Parse(id)
if err != nil {
err = errors.New("failed to parse uuid: " + err.Error())
return
}
result, err = repository.GetDataByID(parsedUUID)
if err != nil {
err = errors.New("failed to get data: " + err.Error())
return
}
if result.Data != "" {
err = json.Unmarshal([]byte(result.Data), &result.DataResponse)
if err != nil {
err = errors.New("failed to convert data to json: " + err.Error())
return
}
}
return
}