feat: add service and model
This commit is contained in:
@@ -2,22 +2,22 @@ package handlers
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (hc *handlersContext) getAllCages(c *gin.Context){
|
||||
func (hc *handlersContext) getAllCages(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) getACage(c *gin.Context){
|
||||
func (hc *handlersContext) getACage(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) createACage(c *gin.Context){
|
||||
func (hc *handlersContext) createACage(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) updateACage(c *gin.Context){
|
||||
func (hc *handlersContext) updateACage(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) deleteACage(c *gin.Context){
|
||||
func (hc *handlersContext) deleteACage(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,26 +2,26 @@ package handlers
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (hc *handlersContext) getAllGames(c *gin.Context){
|
||||
func (hc *handlersContext) getAllGames(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) getAGame(c *gin.Context){
|
||||
func (hc *handlersContext) getAGame(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) createAGame(c *gin.Context){
|
||||
func (hc *handlersContext) createAGame(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) updateAGame(c *gin.Context){
|
||||
func (hc *handlersContext) updateAGame(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) deleteAGame(c *gin.Context){
|
||||
func (hc *handlersContext) deleteAGame(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) getHamstersOfGame(c *gin.Context){
|
||||
func (hc *handlersContext) getHamstersOfGame(c *gin.Context) {
|
||||
|
||||
}
|
||||
@@ -2,22 +2,22 @@ package handlers
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (hc *handlersContext) getAllHamsters(c *gin.Context){
|
||||
func (hc *handlersContext) getAllHamsters(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) getAHamster(c *gin.Context){
|
||||
func (hc *handlersContext) getAHamster(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) createAHamster(c *gin.Context){
|
||||
func (hc *handlersContext) createAHamster(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) updateAHamster(c *gin.Context){
|
||||
func (hc *handlersContext) updateAHamster(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (hc *handlersContext) deleteAHamster(c *gin.Context){
|
||||
func (hc *handlersContext) deleteAHamster(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
@@ -77,19 +77,19 @@ func NewRouter(config *Config) *gin.Engine {
|
||||
gameRoute.Handle(http.MethodGet, "", hc.getAllGames)
|
||||
gameRoute.Handle(http.MethodGet, "/:gameId", hc.getAGame)
|
||||
gameRoute.Handle(http.MethodPost, "/:gameId", hc.createAGame)
|
||||
gameRoute.Handle(http.MethodPut, "/:gameId",hc.updateAGame)
|
||||
gameRoute.Handle(http.MethodGet, "/:gameId/hamsters",hc.getHamstersOfGame)
|
||||
gameRoute.Handle(http.MethodDelete, "/:gameId",hc.deleteAGame)
|
||||
gameRoute.Handle(http.MethodPut, "/:gameId", hc.updateAGame)
|
||||
gameRoute.Handle(http.MethodGet, "/:gameId/hamsters", hc.getHamstersOfGame)
|
||||
gameRoute.Handle(http.MethodDelete, "/:gameId", hc.deleteAGame)
|
||||
|
||||
cageRoute := gameRoute.Group("/:gameId/cages")
|
||||
cageRoute.Handle(http.MethodGet, "",hc.getAllCages)
|
||||
cageRoute.Handle(http.MethodGet, "", hc.getAllCages)
|
||||
cageRoute.Handle(http.MethodGet, "/:cageId", hc.getACage)
|
||||
cageRoute.Handle(http.MethodPost, "/:cageId", hc.createACage)
|
||||
cageRoute.Handle(http.MethodPut, "/:cageId", hc.updateACage)
|
||||
cageRoute.Handle(http.MethodDelete, "/:cageId",hc.deleteACage)
|
||||
cageRoute.Handle(http.MethodDelete, "/:cageId", hc.deleteACage)
|
||||
|
||||
hamsterRoute := cageRoute.Group("/:cageId/hamsters")
|
||||
hamsterRoute.Handle(http.MethodGet, "",hc.getAllHamsters)
|
||||
hamsterRoute.Handle(http.MethodGet, "", hc.getAllHamsters)
|
||||
hamsterRoute.Handle(http.MethodGet, "/:hamsterId", hc.getAHamster)
|
||||
hamsterRoute.Handle(http.MethodPost, "/:hamsterId", hc.createAHamster)
|
||||
hamsterRoute.Handle(http.MethodPut, "/:hamsterId", hc.updateAHamster)
|
||||
|
||||
11
service/cage_service.go
Normal file
11
service/cage_service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package service
|
||||
|
||||
import "hamster-tycoon/storage/dao"
|
||||
|
||||
type CageService struct {
|
||||
serviceContext
|
||||
}
|
||||
|
||||
func NewCageService(database dao.Database) *CageService {
|
||||
return &CageService{serviceContext{db: database}}
|
||||
}
|
||||
11
service/game_service.go
Normal file
11
service/game_service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package service
|
||||
|
||||
import "Game-tycoon/storage/dao"
|
||||
|
||||
type GameService struct {
|
||||
serviceContext
|
||||
}
|
||||
|
||||
func NewGameService(database dao.Database) *GameService {
|
||||
return &GameService{serviceContext{db: database}}
|
||||
}
|
||||
11
service/hamster_service.go
Normal file
11
service/hamster_service.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package service
|
||||
|
||||
import "hamster-tycoon/storage/dao"
|
||||
|
||||
type HamsterService struct {
|
||||
serviceContext
|
||||
}
|
||||
|
||||
func NewHamsterService(database dao.Database) *HamsterService {
|
||||
return &HamsterService{serviceContext{db: database}}
|
||||
}
|
||||
@@ -15,4 +15,12 @@ type Database interface {
|
||||
UpdateUser(*model.User) error
|
||||
// end: user dao funcs
|
||||
|
||||
// start: cage games funcs
|
||||
GetAllGames() ([]*model.Game, error)
|
||||
GetGameById(string) (*model.Game, error)
|
||||
CreateGame(*model.Game) error
|
||||
DeleteGame(string) error
|
||||
UpdateGame(*model.Game) error
|
||||
// end: games dao funcs
|
||||
|
||||
}
|
||||
|
||||
1
storage/dao/fake/database_postgresql_cages.go
Executable file
1
storage/dao/fake/database_postgresql_cages.go
Executable file
@@ -0,0 +1 @@
|
||||
package fake
|
||||
1
storage/dao/fake/database_postgresql_games.go
Executable file
1
storage/dao/fake/database_postgresql_games.go
Executable file
@@ -0,0 +1 @@
|
||||
package fake
|
||||
1
storage/dao/fake/database_postgresql_hamsters.go
Executable file
1
storage/dao/fake/database_postgresql_hamsters.go
Executable file
@@ -0,0 +1 @@
|
||||
package fake
|
||||
1
storage/dao/postgresql/database_postgresql_cages.go
Executable file
1
storage/dao/postgresql/database_postgresql_cages.go
Executable file
@@ -0,0 +1 @@
|
||||
package postgresql
|
||||
1
storage/dao/postgresql/database_postgresql_games.go
Executable file
1
storage/dao/postgresql/database_postgresql_games.go
Executable file
@@ -0,0 +1 @@
|
||||
package postgresql
|
||||
1
storage/dao/postgresql/database_postgresql_hamsters.go
Executable file
1
storage/dao/postgresql/database_postgresql_hamsters.go
Executable file
@@ -0,0 +1 @@
|
||||
package postgresql
|
||||
@@ -1,4 +1,4 @@
|
||||
package hamster_tycoon
|
||||
package model
|
||||
|
||||
type Cage struct {
|
||||
Hamsters []*Hamster
|
||||
@@ -1,6 +1,8 @@
|
||||
package hamster_tycoon
|
||||
package model
|
||||
|
||||
type Game struct {
|
||||
ID string
|
||||
server Server
|
||||
Cages []*Cage
|
||||
SelledHamster []*Hamster
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package hamster_tycoon
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"hamster-tycoon/randomizer"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,7 @@ const (
|
||||
var GlobalHamsterNumber = 1
|
||||
|
||||
type Hamster struct {
|
||||
ID string
|
||||
Name string
|
||||
Number int
|
||||
Sexe string
|
||||
@@ -113,6 +115,7 @@ func Born(father *Hamster, mother *Hamster) ([]*Hamster, error) {
|
||||
child := make([]*Hamster, numberOfChild)
|
||||
for i := 0; i < numberOfChild; i++ {
|
||||
child[i] = &Hamster{
|
||||
ID: uuid.NewV4().String(),
|
||||
Name: fmt.Sprintf("Hamster %d", GlobalHamsterNumber),
|
||||
Number: GlobalHamsterNumber,
|
||||
Age: 1,
|
||||
@@ -1,4 +1,4 @@
|
||||
package hamster_tycoon
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
5
storage/model/server.go
Normal file
5
storage/model/server.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
type Server struct {
|
||||
ID string
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
UserEditable
|
||||
@@ -8,6 +10,7 @@ type User struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt *time.Time `json:"updatedAt"`
|
||||
GoogleId string `json:"-"`
|
||||
Games []Game
|
||||
}
|
||||
|
||||
type UserEditable struct {
|
||||
|
||||
Reference in New Issue
Block a user