-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71660cc
commit 0a796ee
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package auth | ||
|
||
import "database/sql" | ||
|
||
type Repo interface { | ||
getPlaces() ([]Place, error) | ||
} | ||
|
||
type Repository struct{} | ||
|
||
func NewRepository() *Repository { | ||
return &Repository{} | ||
} | ||
|
||
func (r *Repository) getPlaces() ([]Place, error) { | ||
connStr := "user=postgres password=mypassword host=localhost port=5432 dbname=landmarks sslmode=disable" | ||
db, err := sql.Open("postgres", connStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer db.Close() | ||
rows, err := db.Query("SELECT * FROM places") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer rows.Close() | ||
places := []Place{} | ||
for rows.Next() { | ||
var place Place | ||
err := rows.Scan(&place.ID, &place.Name, &place.Image) | ||
if err != nil { | ||
return nil, err | ||
} | ||
places = append(places, place) | ||
} | ||
return places, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package auth | ||
|
||
type Place struct { | ||
ID int | ||
Name string | ||
Image string | ||
} | ||
|
||
type PlaceUsecase interface { | ||
getPlace() ([]Place, error) | ||
} | ||
|
||
type RepoUsecase struct { | ||
repos Repository | ||
} | ||
|
||
func NewRepoUsecase(repos *Repository) *RepoUsecase { | ||
return &RepoUsecase{repos: *repos} | ||
} | ||
|
||
func (i *RepoUsecase) getPlace() ([]Place, error) { | ||
places, err := i.repos.getPlaces() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return places, nil | ||
} |