-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_repository.go
37 lines (31 loc) · 1014 Bytes
/
user_repository.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
package repositories
import (
"fmt"
"github.com/nor-ko-hi-jp/gorilla-tutorial/internals/entities"
"github.com/nor-ko-hi-jp/gorilla-tutorial/internals/interfaces"
"github.com/nor-ko-hi-jp/gorilla-tutorial/internals/mappers"
)
type UserRepository struct {
}
func (repository UserRepository) Find(id string) *interfaces.Result {
client, context := NewFirestoreClient()
defer client.Close()
ref := client.Collection("users").Doc(id)
snapshot, err := ref.Get(context)
if err != nil {
fmt.Println(err)
return &interfaces.Result{Value: err}
}
var user entities.User
if mappedError := snapshot.DataTo(&user); mappedError != nil {
fmt.Println(mappedError)
return &interfaces.Result{Value: mappedError}
}
return &interfaces.Result{Value: &user, Mapper: mappers.User{}}
}
func (repository UserRepository) FindAll() *interfaces.Result {
return &interfaces.Result{Value: ""}
}
func (repository UserRepository) QueryBy(queries interfaces.Queries) *interfaces.Result {
return &interfaces.Result{}
}