forked from bootdotdev/learn-cicd-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
51 lines (44 loc) · 1.08 KB
/
models.go
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
package main
import (
"time"
"github.com/bootdotdev/learn-cicd-starter/internal/database"
)
type User struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
ApiKey string `json:"api_key"`
}
func databaseUserToUser(user database.User) User {
return User{
ID: user.ID,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
Name: user.Name,
ApiKey: user.ApiKey,
}
}
type Note struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Note string `json:"note"`
UserID string `json:"user_id"`
}
func databaseNoteToNote(post database.Note) Note {
return Note{
ID: post.ID,
CreatedAt: post.CreatedAt,
UpdatedAt: post.UpdatedAt,
Note: post.Note,
UserID: post.UserID,
}
}
func databasePostsToPosts(notes []database.Note) []Note {
result := make([]Note, len(notes))
for i, note := range notes {
result[i] = databaseNoteToNote(note)
}
return result
}