Skip to content

Commit

Permalink
Merge pull request #17 from titouanfreville/issue-6-APIimpl
Browse files Browse the repository at this point in the history
Issue 6 ap impl
  • Loading branch information
titouanfreville authored Mar 5, 2017
2 parents f6ad816 + a837575 commit 058e33d
Show file tree
Hide file tree
Showing 68 changed files with 1,481 additions and 17,641 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,5 @@ vendor/*
.env*
!.env.dist
!.env.test
docker_resources/*
!docker_resources/README.md
23 changes: 21 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"github.com/pressly/chi"
"github.com/pressly/chi/docgen"
"github.com/pressly/chi/middleware"
"github.com/titouanfreville/popcubeapi/configs"
"github.com/titouanfreville/popcubeapi/datastores"
"github.com/titouanfreville/popcubeapi/utils"
)

type testDb struct {
type saveDb struct {
db *gorm.DB
}

Expand All @@ -21,9 +23,9 @@ type key string

var (
routes = flag.Bool("routes", false, "Generate router documentation")
dbStore = testDb{}
error422 = newEntityError(422, "parse.request.body", "Request json object not correct.")
error503 = newDatabaseError(503, "database.maintenance", "Database is currently in maintenance state. We are doing our best to get it back online ASAP.")
dbStore = saveDb{}
error422 = utils.NewAPIError(422, "parse.request.body", "Request json object not correct.")
error503 = utils.NewAPIError(503, "database.maintenance", "Database is currently in maintenance state. We are doing our best to get it back online ASAP.")
)

// newRouter initialise api serveur.
Expand All @@ -39,7 +41,7 @@ func initMiddleware(router *chi.Mux) {
router.Use(middleware.Recoverer)
router.Use(middleware.StripSlashes)
router.Use(middleware.Timeout(5 * 1000))
router.Use(middleware.Heartbeat("/ping"))
// router.Use(middleware.Heartbeat("/heartbeat"))
router.Use(middleware.CloseNotify)
}

Expand Down Expand Up @@ -82,9 +84,16 @@ func basicRoutes(router *chi.Mux) {
}

// StartAPI initialise the api with provided host and port.
func StartAPI(hostname string, port string) {
func StartAPI(hostname string, port string, DbConnectionInfo *configs.DbConnection) {
router := newRouter()
dbStore.db = datastores.Store().InitConnection("root", "popcube_test", "popcube_dev", "database", "3306")
// Init DB connection
user := DbConnectionInfo.User
db := DbConnectionInfo.Database
pass := DbConnectionInfo.Password
host := DbConnectionInfo.Host
dbport := DbConnectionInfo.Port
dbStore.db = datastores.Store().InitConnection(user, db, pass, host, dbport)

initMiddleware(router)
basicRoutes(router)
initAvatarRoute(router)
Expand Down
94 changes: 0 additions & 94 deletions api/api_default_response.go

This file was deleted.

104 changes: 104 additions & 0 deletions api/api_parameters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package api

import "github.com/titouanfreville/popcubeapi/models"

// <><><><><> AVATAR PARAMETERS <><><><><> //

// swagger:parameters getAvatarFromLink
type avatarLinkParam struct {
//Link of the avatar in server.
// in:path
AvatarLink string `json:"avatarLink"`
}

// swagger:parameters getAvatarFromName
type avatarNameParam struct {
//Link of the avatar in server.
// in:path
AvatarName string `json:"avatarName"`
}

// swagger:parameters updateAvatar deleteAvatar
type avatarIDParam struct {
//Link of the avatar in server.
// in:path
AvatarID int `json:"avatarID"`
}

// swagger:parameters newAvatar updateAvatar
type avatarObjectParam struct {
//Link of the avatar in server.
// in:body
Avatar models.Avatar `json:"avatar"`
}

// <><><><><> <><><><><> <><><><><> <><><><><> //
// <><><><><> CHANNEL PARAMETERS <><><><><> //

// swagger:parameters getChannelFromType
type channelTypeParam struct {
//Link of the channel in server.
// in:path
ChannelType string `json:"channelType"`
}

// swagger:parameters getChannelFromName
type channelNameParam struct {
//Link of the channel in server.
// in:path
ChannelName string `json:"channelName"`
}

// swagger:parameters updateChannel deleteChannel
type channelIDParam struct {
//Link of the channel in server.
// in:path
ChannelID int `json:"channelID"`
}

// swagger:parameters newChannel updateChannel
type channelObjectParam struct {
//Link of the channel in server.
// in:body
Channel models.Channel `json:"channel"`
}

// <><><><><> <><><><><> <><><><><> <><><><><> //
// <><><><><> EMOJI PARAMETERS <><><><><> //

// swagger:parameters getEmojiFromLink
type emojiLinkParam struct {
//Link of the emoji in server.
// in:path
EmojiLink string `json:"emojiLink"`
}

// swagger:parameters getEmojiFromName
type emojiNameParam struct {
//Link of the emoji in server.
// in:path
EmojiName string `json:"emojiName"`
}

// swagger:parameters getEmojiFromShortcut
type emojiShortcutParam struct {
//Link of the emoji in server.
// in:path
EmojiShortcut string `json:"emojiShortcut"`
}

// swagger:parameters updateEmoji deleteEmoji
type emojiIDParam struct {
//Link of the emoji in server.
// in:path
EmojiID int `json:"emojiID"`
}

// swagger:parameters newEmoji updateEmoji
type emojiObjectParam struct {
//Link of the emoji in server.
// in:body
Emoji models.Emoji `json:"emoji"`
}

// <><><><><> <><><><><> <><><><><> <><><><><> //
Loading

0 comments on commit 058e33d

Please sign in to comment.