// @Title retrieveFile // @Description Retrieve a file. // @Accept json // @Param id path int true "File ID" // @Success 200 {object} model.File "OK" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /upload/files // @Router /upload/{id} [get] func retrieveFile(c *gin.Context) { file, status, err := uploadService.RetrieveFile(c) if err == nil { c.JSON(status, gin.H{"file": file}) } else { messageTypes := &response.MessageTypes{NotFound: "upload.file.error.notFound"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title createLocation // @Description Create an location. // @Accept json // @Param title form string true "Location title." // @Param url form string true "Location url" // @Param latitude form int true "Location latitude" // @Param longitude form int true "Location longitude" // @Param content form string false "Location content" // @Success 201 {object} model.Location "Created" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 500 {object} response.BasicResponse "Location is not created" // @Resource /locations // @Router /locations [post] func createLocation(c *gin.Context) { location, status, err := locationService.CreateLocation(c) if err == nil { c.JSON(status, gin.H{"location": location}) } else { messageTypes := &response.MessageTypes{InternalServerError: "location.error.notCreated"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveRole // @Description Retrieve a role. // @Accept json // @Param id path int true "Role ID" // @Success 200 {object} model.Role "OK" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /roles // @Router /roles/{id} [get] func retrieveRole(c *gin.Context) { role, status, err := roleService.RetrieveRole(c) if err == nil { c.JSON(status, gin.H{"role": role}) } else { messageTypes := &response.MessageTypes{NotFound: "role.error.notFound"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title createArticle // @Description Create an article. // @Accept json // @Param title form string true "Article title." // @Param url form string true "Article url." // @Param content form string false "Article content." // @Success 201 {object} model.Article "Created" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 500 {object} response.BasicResponse "Article is not created" // @Resource /articles // @Router /articles [post] func createArticle(c *gin.Context) { article, status, err := articleService.CreateArticle(c) if err == nil { c.JSON(status, gin.H{"article": article}) } else { messageTypes := &response.MessageTypes{InternalServerError: "article.error.notCreated"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveArticles // @Description Retrieve article array. // @Accept json // @Success 200 {array} model.Article "OK" // @Resource /articles // @Router /articles [get] func retrieveArticles(c *gin.Context) { articles, canWrite, category, currentPage, hasPrev, hasNext, status, err := articleService.RetrieveArticles(c) if err == nil { c.JSON(status, gin.H{"articles": articles, "canWrite": canWrite, "category": category, "currentPage": currentPage, "hasPrev": hasPrev, "hasNext": hasNext}) } else { messageTypes := &response.MessageTypes{} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveCommentsOnLocation // @Description Retrieve comments on an location. // @Accept json // @Param locationId path int true "Location Id" // @Success 200 {object} model.Comment "Comment updated successfully" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 403 {object} response.BasicResponse "FormUser's Id is not identical with currentUser's Id" // @Failure 404 {object} response.BasicResponse "Not found" // @Failure 500 {object} response.BasicResponse "Comment is not updated" // @Resource /locations // @Router /locations/{id}/comments [get] func retrieveCommentsOnLocation(c *gin.Context) { comments, currentPage, hasPrev, hasNext, count, status, err := locationService.RetrieveCommentsOnLocation(c) if err == nil { c.JSON(status, gin.H{"comments": comments, "currentPage": currentPage, "hasPrev": hasPrev, "hasNext": hasNext, "count": count}) } else { messageTypes := &response.MessageTypes{ NotFound: "comment.error.notFound"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveLocations // @Description Retrieve location array. // @Accept json // @Success 200 {array} model.Location "OK" // @Resource /locations // @Router /locations [get] func retrieveLocations(c *gin.Context) { locations, canWrite, currentPage, hasPrev, hasNext, status, err := locationService.RetrieveLocations(c) if err == nil { c.JSON(status, gin.H{"locations": locations, "canWrite": canWrite, "currentPage": currentPage, "hasPrev": hasPrev, "hasNext": hasNext}) } else { messageTypes := &response.MessageTypes{} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveOauthStatus // @Description Retrieve oauth connections. // @Accept json // @Success 200 {array} oauthService.oauthStatusMap "OK" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Resource /oauth // @Router /oauth [get] func retrieveOauthStatus(c *gin.Context) { oauthStatus, status, err := oauthService.RetrieveOauthStatus(c) if err == nil { c.JSON(status, gin.H{"oauthStatus": oauthStatus}) } else { messageTypes := &response.MessageTypes{ Unauthorized: "oauth.error.unauthorized", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title createRole // @Description Create a role. // @Accept json // @Param name form string true "Name of Role." // @Param description form string true "Description of Role." // @Success 201 {object} model.Role "Created" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 500 {object} response.BasicResponse "Role is not created" // @Resource /roles // @Router /roles [post] func createRole(c *gin.Context) { role, status, err := roleService.CreateRole(c) if err == nil { c.JSON(status, gin.H{"role": role}) } else { messageTypes := &response.MessageTypes{Unauthorized: "role.error.unauthorized", InternalServerError: "admin.role.create.fail"} response.ErrorJSON(c, status, messageTypes, err) // c.JSON(400, gin.H{"role": nil}) } }
// @Title retrieveLocation // @Description Retrieve an location. // @Accept json // @Param id path int true "Location Id" // @Success 200 {object} model.Location "OK" // @Failure 404 {object} response.BasicResponse "Location is not found" // @Resource /locations // @Router /locations/{id} [get] func retrieveLocation(c *gin.Context) { location, isAuthor, currentUserId, status, err := locationService.RetrieveLocation(c) if err == nil { c.JSON(status, gin.H{"location": location, "isAuthor": isAuthor, "currentUserId": currentUserId}) } else { messageTypes := &response.MessageTypes{ NotFound: "location.error.notFound", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveArticle // @Description Retrieve an article. // @Accept json // @Param id path int true "Article Id" // @Success 200 {object} model.Article "OK" // @Failure 404 {object} response.BasicResponse "Article is not found" // @Resource /articles // @Router /articles/{id} [get] func retrieveArticle(c *gin.Context) { article, isAuthor, currentUserId, status, err := articleService.RetrieveArticle(c) if err == nil { c.JSON(status, gin.H{"article": article, "isAuthor": isAuthor, "currentUserId": currentUserId}) } else { messageTypes := &response.MessageTypes{ NotFound: "article.error.notFound", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveLikingsOnArticles // @Description Retrieve likings on an article. // @Accept json // @Param articleId path int true "Article Id" // @Success 200 {array} model.PublicUser "OK" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /articles // @Router /articles/{id}/likings [get] func retrieveLikingsOnArticles(c *gin.Context) { likings, currentPage, hasPrev, hasNext, count, status, err := articleService.RetrieveLikingsOnArticles(c) if err == nil { c.JSON(status, gin.H{"likings": likings, "currentPage": currentPage, "hasPrev": hasPrev, "hasNext": hasNext, "count": count}) } else { messageTypes := &response.MessageTypes{ NotFound: "liking.error.notFound"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title updateFile // @Description Update a file. // @Accept json // @Param id path int true "File ID" // @Success 200 {object} model.File "OK" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Not found" // @Failure 500 {object} response.BasicResponse "File is not updated" // @Resource /upload/files // @Router /upload/{id} [put] func updateFile(c *gin.Context) { file, status, err := uploadService.UpdateFile(c) if err == nil { c.JSON(status, gin.H{"file": file}) } else { messageTypes := &response.MessageTypes{Unauthorized: "upload.file.error.unauthorized", NotFound: "upload.file.error.notFound", InternalServerError: "upload.file.update.fail"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title updateArticle // @Description Update an article. // @Accept json // @Param id path int true "Article Id" // @Success 200 {object} model.Article "OK" // @Failure 400 {object} response.BasicResponse "Article is not updated" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Article is not found" // @Resource /articles // @Router /articles/{id} [put] func updateArticle(c *gin.Context) { article, status, err := articleService.UpdateArticle(c) if err == nil { c.JSON(status, gin.H{"article": article}) } else { messageTypes := &response.MessageTypes{ BadRequest: "article.view.updated.fail", Unauthorized: "article.error.isNotAuthor", NotFound: "article.error.notFound"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title updateLocation // @Description Update an location. // @Accept json // @Param id path int true "Location Id" // @Success 200 {object} model.Location "OK" // @Failure 400 {object} response.BasicResponse "Location is not updated" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Location is not found" // @Resource /locations // @Router /locations/{id} [put] func updateLocation(c *gin.Context) { location, status, err := locationService.UpdateLocation(c) if err == nil { c.JSON(status, gin.H{"location": location}) } else { messageTypes := &response.MessageTypes{ BadRequest: "location.view.updated.fail", Unauthorized: "location.error.isNotAuthor", NotFound: "location.error.notFound"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title googleRevoke // @Description Get google oauth url. // @Accept json // @Success 200 {object} gin.H "Revoked" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Connection is not found" // @Failure 500 {object} response.BasicResponse "Connection not revoked from user" // @Resource /oauth // @Router /oauth/google [delete] func googleRevoke(c *gin.Context) { oauthStatus, status, err := oauthService.RevokeGoogle(c) if err == nil { c.JSON(status, gin.H{"oauthStatus": oauthStatus}) } else { messageTypes := &response.MessageTypes{ Unauthorized: "oauth.error.unauthorized", NotFound: "oauth.error.notFound", InternalServerError: "oauth.error.internalServerError"} response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveUser // @Description Retrieve a user. // @Accept json // @Param id path int true "User ID" // @Success 200 {object} model.PublicUser "OK" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /users // @Router /users/{id} [get] func retrieveUser(c *gin.Context) { user, isAuthor, currentUserId, status, err := userService.RetrieveUser(c) if err == nil { c.JSON(status, gin.H{"user": user, "isAuthor": isAuthor, "currentUserId": currentUserId}) } else { messageTypes := &response.MessageTypes{ NotFound: "user.error.notFound", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveLikedOnUsers // @Description Retrieve likings on a user. // @Accept json // @Param userId path int true "User ID" // @Success 200 {array} model.PublicUser "OK" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /users // @Router /users/{id}/liked [get] func retrieveLikedOnUsers(c *gin.Context) { liked, currentPage, hasPrev, hasNext, status, err := userLiking.RetrieveLikedOnUser(c) if err == nil { c.JSON(status, gin.H{"liked": liked, "currentPage": currentPage, "hasPrev": hasPrev, "hasNext": hasNext}) } else { messageTypes := &response.MessageTypes{ Unauthorized: "liking.error.unauthorized", NotFound: "liking.error.notFound", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title retrieveCurrentUser // @Description Retrieve a user for admin. It contains more information than normal query. // @Accept json // @Param id path int true "User ID" // @Success 200 {object} model.User "OK" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /user // @Router /user/admin/{id} [get] func retrieveUserForAdmin(c *gin.Context) { user, status, err := userService.RetrieveUserForAdmin(c) if err == nil { c.JSON(status, gin.H{"user": user}) } else { messageTypes := &response.MessageTypes{ Unauthorized: "user.error.unauthorized", NotFound: "user.error.notFound", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title activateUser // @Description Activate/Deactivate a user. // @Accept json // @Param id path int true "User ID" // @Success 200 {object} model.User "OK" // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Not found" // @Resource /user // @Router /users/{id} [put] func activateUser(c *gin.Context) { user, status, err := userService.ActivateUser(c) if err == nil { c.JSON(status, gin.H{"user": user}) } else { messageTypes := &response.MessageTypes{ Unauthorized: "user.error.unauthorized", NotFound: "user.error.notFound", InternalServerError: "admin.user.toggleActivate.fail", } response.ErrorJSON(c, status, messageTypes, err) } }
// @Title deleteUser // @Description Delete a user. // @Accept json // @Param id path int true "User ID" // @Success 200 {object} response.BasicResponse // @Failure 401 {object} response.BasicResponse "Authentication required" // @Failure 404 {object} response.BasicResponse "Not found" // @Failure 500 {object} response.BasicResponse "User is not deleted." // @Resource /users // @Router /users/{id} [delete] func deleteUser(c *gin.Context) { status, err := userService.DeleteUser(c) if err == nil { c.JSON(status, response.BasicResponse{}) } else { messageTypes := &response.MessageTypes{ Unauthorized: "user.error.unauthorized", NotFound: "user.error.notFound", InternalServerError: "setting.leaveOurService.fail", } response.ErrorJSON(c, status, messageTypes, err) } }