Skip to content

Commit

Permalink
Merge pull request #23 from titouanfreville/issue-6-APIimpl
Browse files Browse the repository at this point in the history
More precise errors
  • Loading branch information
titouanfreville authored Mar 6, 2017
2 parents c04dd27 + ba6fc93 commit f4d10e3
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 95 deletions.
4 changes: 2 additions & 2 deletions api/api_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* The inner API of Popcube aim to define every methods need to manage communication organisation inside PopCube chat project
*
* Schemes : http, https
* Host: api.popcube
* BasePath: /alpha
* Host: api-alpha.popcube.xyz
* BasePath: /
* Version: alpha
* Contact: Titouan Freville <[email protected]>
*
Expand Down
12 changes: 6 additions & 6 deletions api/avatar_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func initAvatarRoute(router chi.Router) {
// This will create an avatar for organisation avatars library.
//
// Responses:
// 200: avatarObjectSuccess
// 201: avatarObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -61,7 +61,7 @@ func initAvatarRoute(router chi.Router) {
// This will create an avatar for organisation avatars library.
//
// Responses:
// 200: avatarObjectSuccess
// 201: avatarObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -86,7 +86,7 @@ func initAvatarRoute(router chi.Router) {
r.Route("/:avatarName", func(r chi.Router) {
r.Use(avatarContext)
// swagger:route GET /avatar/name/{avatarName} Avatars getAvatarFromName
//y
//
// Get avatar from name
//
// This will return the avatar object corresponding to provided name
Expand Down Expand Up @@ -192,13 +192,13 @@ func newAvatar(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Avatar == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Avatar().Save(data.Avatar, db)
if err == nil {
render.JSON(w, 200, data.Avatar)
render.JSON(w, 201, data.Avatar)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -219,7 +219,7 @@ func updateAvatar(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
avatar := r.Context().Value(oldAvatarKey).(models.Avatar)
if err != nil {
if err != nil || data.Avatar == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
10 changes: 5 additions & 5 deletions api/channel_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func initChannelRoute(router chi.Router) {
// This will create an channel for organisation channels library.
//
// Responses:
// 200: channelObjectSuccess
// 201: channelObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -61,7 +61,7 @@ func initChannelRoute(router chi.Router) {
// This will create an channel for organisation channels library.
//
// Responses:
// 200: channelObjectSuccess
// 201: channelObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -229,13 +229,13 @@ func newChannel(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Channel == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Channel().Save(data.Channel, db)
if err == nil {
render.JSON(w, 200, data.Channel)
render.JSON(w, 201, data.Channel)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -256,7 +256,7 @@ func updateChannel(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
channel := r.Context().Value(oldChannelKey).(models.Channel)
if err != nil {
if err != nil || data.Channel == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
10 changes: 5 additions & 5 deletions api/emojis_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func initEmojiRoute(router chi.Router) {
// This will create an emoji for organisation emojis library.
//
// Responses:
// 200: emojiObjectSuccess
// 201: emojiObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -62,7 +62,7 @@ func initEmojiRoute(router chi.Router) {
// This will create an emoji for organisation emojis library.
//
// Responses:
// 200: emojiObjectSuccess
// 201: emojiObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -211,13 +211,13 @@ func newEmoji(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Emoji == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Emoji().Save(data.Emoji, db)
if err == nil {
render.JSON(w, 200, data.Emoji)
render.JSON(w, 201, data.Emoji)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -238,7 +238,7 @@ func updateEmoji(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
emoji := r.Context().Value(oldEmojiKey).(models.Emoji)
if err != nil {
if err != nil || data.Emoji == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
10 changes: 5 additions & 5 deletions api/folder_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func initFolderRoute(router chi.Router) {
// This will create an folder for organisation folders library.
//
// Responses:
// 200: folderObjectSuccess
// 201: folderObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -62,7 +62,7 @@ func initFolderRoute(router chi.Router) {
// This will create an folder for organisation folders library.
//
// Responses:
// 200: folderObjectSuccess
// 201: folderObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -245,13 +245,13 @@ func newFolder(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Folder == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Folder().Save(data.Folder, db)
if err == nil {
render.JSON(w, 200, data.Folder)
render.JSON(w, 201, data.Folder)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -272,7 +272,7 @@ func updateFolder(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
folder := r.Context().Value(oldFolderKey).(models.Folder)
if err != nil {
if err != nil || data.Folder == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
16 changes: 8 additions & 8 deletions api/member_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func initMemberRoute(router chi.Router) {
// This will create an member for organisation members library.
//
// Responses:
// 200: memberObjectSuccess
// 201: memberObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -95,7 +95,7 @@ func initMemberRoute(router chi.Router) {
// This will create an member for organisation members library.
//
// Responses:
// 200: memberObjectSuccess
// 201: memberObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -164,7 +164,7 @@ func getMemberFromUser(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.User == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand All @@ -186,7 +186,7 @@ func getMemberFromChannel(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Channel == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand All @@ -208,7 +208,7 @@ func getMemberFromRole(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Role == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand All @@ -230,13 +230,13 @@ func newMember(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Member == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Member().Save(data.Member, db)
if err == nil {
render.JSON(w, 200, data.Member)
render.JSON(w, 201, data.Member)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -257,7 +257,7 @@ func updateMember(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
member := r.Context().Value(oldMemberKey).(models.Member)
if err != nil {
if err != nil || data.Member == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
14 changes: 7 additions & 7 deletions api/message_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func initMessageRoute(router chi.Router) {
// This will create an message for organisation messages library.
//
// Responses:
// 200: messageObjectSuccess
// 201: messageObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -60,7 +60,7 @@ func initMessageRoute(router chi.Router) {
// This will create an message for organisation messages library.
//
// Responses:
// 200: messageObjectSuccess
// 201: messageObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -180,7 +180,7 @@ func getMessageFromUser(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.User == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand All @@ -202,7 +202,7 @@ func getMessageFromChannel(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Channel == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand All @@ -224,13 +224,13 @@ func newMessage(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Message == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Message().Save(data.Message, db)
if err == nil {
render.JSON(w, 200, data.Message)
render.JSON(w, 201, data.Message)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -251,7 +251,7 @@ func updateMessage(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
message := r.Context().Value(oldMessageKey).(models.Message)
if err != nil {
if err != nil || data.Message == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
10 changes: 5 additions & 5 deletions api/organisation_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func initOrganisationRoute(router chi.Router) {
// This will create an organisation for organisation organisations library.
//
// Responses:
// 200: organisationObjectSuccess
// 201: organisationObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand All @@ -59,7 +59,7 @@ func initOrganisationRoute(router chi.Router) {
// This will create an organisation for organisation organisations library.
//
// Responses:
// 200: organisationObjectSuccess
// 201: organisationObjectSuccess
// 422: wrongEntity
// 503: databaseError
// default: genericError
Expand Down Expand Up @@ -115,13 +115,13 @@ func newOrganisation(w http.ResponseWriter, r *http.Request) {
db := dbStore.db
request := r.Body
err := chiRender.Bind(request, &data)
if err != nil {
if err != nil || data.Organisation == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
err := store.Organisation().Save(data.Organisation, db)
if err == nil {
render.JSON(w, 200, data.Organisation)
render.JSON(w, 201, data.Organisation)
} else {
render.JSON(w, err.StatusCode, err)
}
Expand All @@ -142,7 +142,7 @@ func updateOrganisation(w http.ResponseWriter, r *http.Request) {
request := r.Body
err := chiRender.Bind(request, &data)
organisation := r.Context().Value(oldOrganisationKey).(models.Organisation)
if err != nil {
if err != nil || data.Organisation == nil {
render.JSON(w, error422.StatusCode, error422)
} else {
if err := db.DB().Ping(); err == nil {
Expand Down
Loading

0 comments on commit f4d10e3

Please sign in to comment.