Esempio n. 1
0
// @Title createUserAuthentication
// @Description Create a user session.
// @Accept  json
// @Param   loginEmail        form   string     true        "User email."
// @Param   loginPassword        form   string  true        "User password."
// @Success 201 {object} response.BasicResponse "User authentication created"
// @Failure 401 {object} response.BasicResponse "Password incorrect"
// @Failure 404 {object} response.BasicResponse "User is not found"
// @Resource /authentications
// @Router /authentications [post]
func createUserAuthentication(c *gin.Context) {
	status, err := userService.CreateUserAuthentication(c)
	messageTypes := &response.MessageTypes{OK: "login.done",
		Unauthorized: "login.error.passwordIncorrect",
		NotFound:     "login.error.userNotFound"}
	messages := &response.Messages{OK: "User logged in successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 2
0
// @Title createCommentOnArticle
// @Description Create a comment on an article.
// @Accept  json
// @Param   articleId        form   int     true        "Article Id."
// @Param   content        form   string     true        "Comment content."
// @Param   imageName        form   string     true        "Article image name."
// @Param   description        form   string  false        "Article description."
// @Success 201 {object} response.BasicResponse "Comment created"
// @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 "Article is not found"
// @Resource /articles
// @Router /articles/comments [post]
func createCommentOnArticle(c *gin.Context) {
	status, err := articleService.CreateCommentOnArticle(c)
	messageTypes := &response.MessageTypes{
		Created:      "comment.created.done",
		Unauthorized: "comment.error.unauthorized",
		Forbidden:    "comment.error.forbidden",
		NotFound:     "comment.error.notFound"}
	messages := &response.Messages{OK: "Comment is created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 3
0
// @Title deleteArticle
// @Description Delete an article.
// @Accept  json
// @Param   id        path    int     true        "Article Id"
// @Success 200 {object} response.BasicResponse "Article deleted"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /articles
// @Router /articles/{id} [delete]
func deleteArticle(c *gin.Context) {
	status, err := articleService.DeleteArticle(c)
	messageTypes := &response.MessageTypes{
		OK:           "article.view.deleted.done",
		BadRequest:   "article.view.deleted.fail",
		Unauthorized: "article.error.isNotAuthor",
		NotFound:     "article.error.notFound"}
	messages := &response.Messages{OK: "Article is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 4
0
// @Title uploadAndSyncArticles
// @Description upload images to storage. And sync article data. Request should contain multipart form data.
// @Accept  json
// @Success 201 {object} gin.H "Uploaded"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Upload failed"
// @Resource /upload/articles
// @Router /upload [post]
func uploadAndSyncArticles(c *gin.Context) {
	status, err := uploadService.UploadAndSyncArticles(c)
	messageTypes := &response.MessageTypes{
		OK:                  "upload.done",
		Unauthorized:        "upload.error.unauthorized",
		InternalServerError: "upload.error.internalServerError",
	}
	messages := &response.Messages{OK: "Files uploaded successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 5
0
// @Title createLikingOnArticle
// @Description Create a liking on an article.
// @Accept  json
// @Param   articleId        form   int     true        "Article Id."
// @Param   content        form   string     true        "Liking content."
// @Param   imageName        form   string     true        "Article image name."
// @Param   description        form   string  false        "Article description."
// @Success 201 {object} response.BasicResponse "Liking created"
// @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 "Article is not found"
// @Resource /articles
// @Router /articles/likings [post]
func createLikingOnArticle(c *gin.Context) {
	status, err := articleService.CreateLikingOnArticle(c)
	messageTypes := &response.MessageTypes{
		OK:           "liking.like.done",
		BadRequest:   "liking.like.fail",
		Unauthorized: "liking.error.unauthorized",
		NotFound:     "liking.error.notFound"}
	messages := &response.Messages{OK: "Article liking is created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 6
0
// @Title updateCommentOnLocation
// @Description Update a comment on location.
// @Accept  json
// @Param   locationId        path    int     true        "Location Id"
// @Param   id                path    int     true        "Comment 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/{commentId} [put]
func updateCommentOnLocation(c *gin.Context) {
	status, err := locationService.UpdateCommentOnLocation(c)
	messageTypes := &response.MessageTypes{
		OK:                  "comment.updated.done",
		Unauthorized:        "comment.error.unauthorized",
		Forbidden:           "comment.error.forbidden",
		NotFound:            "comment.error.notFound",
		InternalServerError: "comment.updated.fail"}
	messages := &response.Messages{OK: "Comment is created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 7
0
// @Title deleteLocation
// @Description Delete an location.
// @Accept  json
// @Param   id        path    int     true        "Location Id"
// @Success 200 {object} response.BasicResponse "Location deleted"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /locations
// @Router /locations/{id} [delete]
func deleteLocation(c *gin.Context) {
	status, err := locationService.DeleteLocation(c)
	messageTypes := &response.MessageTypes{
		OK:           "location.view.deleted.done",
		BadRequest:   "location.view.deleted.fail",
		Unauthorized: "location.error.isNotAuthor",
		NotFound:     "location.error.notFound"}
	messages := &response.Messages{OK: "Location is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)

}
Esempio n. 8
0
// @Title verifyEmail
// @Description Create a user session.
// @Accept  json
// @Param   token        form   string     true        "User email validation token"
// @Success 200 {object} response.BasicResponse "User email verified."
// @Failure 400 {object} response.BasicResponse "User email not verified."
// @Resource /user
// @Router /user/verify/email [put]
func verifyEmail(c *gin.Context) {
	status, err := userService.EmailVerification(c)
	messageTypes := &response.MessageTypes{
		OK:                  "emailVerification.done",
		Forbidden:           "emailVerification.error.tokenExpired",
		NotFound:            "error.notFound",
		InternalServerError: "emailVerification.fail",
	}
	messages := &response.Messages{OK: "Email verified successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 9
0
// @Title sendEmailVerificationToken
// @Description Create a user session.
// @Accept  json
// @Success 201 {object} response.BasicResponse "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Email verification token not sent"
// @Resource /user
// @Router /user/send/email/verification/token [post]
func sendEmailVerificationToken(c *gin.Context) {
	status, err := userService.SendVerification(c)
	messageTypes := &response.MessageTypes{
		OK:                  "emailVerification.send.sent.done",
		Unauthorized:        "error.unauthorized",
		NotFound:            "error.notFound",
		InternalServerError: "emailVerification.send.sent.fail",
	}
	messages := &response.Messages{OK: "Email verification token sent successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 10
0
// @Title resetPassword
// @Description Create a user session.
// @Accept  json
// @Param   token        form   string     true        "User password reset token"
// @Param   newPassword        form   string     true        "New password"
// @Success 200 {object} response.BasicResponse "User password updated"
// @Failure 400 {object} response.BasicResponse "User password is not updated."
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Password reset token not sent"
// @Resource /user
// @Router /user/reset/password [put]
func resetPassword(c *gin.Context) {
	status, err := userService.ResetPassword(c)
	messageTypes := &response.MessageTypes{
		OK:                  "passwordReset.reset.updated.done",
		Forbidden:           "passwordReset.error.tokenExpired",
		NotFound:            "error.notFound",
		InternalServerError: "passwordReset.reset.updated.fail",
	}
	messages := &response.Messages{OK: "Password reset successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 11
0
// @Title sendPasswordResetToken
// @Description Create a user session.
// @Accept  json
// @Param   email        form   string     true        "User email."
// @Success 200 {object} response.BasicResponse "Sent"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Password reset token not sent"
// @Resource /user
// @Router /user/send/password/reset/token [post]
func sendPasswordResetToken(c *gin.Context) {
	status, err := userService.SendPasswordResetToken(c)
	messageTypes := &response.MessageTypes{
		OK:                  "passwordReset.send.sent.done",
		Unauthorized:        "error.unauthorized",
		NotFound:            "error.notFound",
		InternalServerError: "passwordReset.send.sent.fail",
	}
	messages := &response.Messages{OK: "Password reset token sent successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 12
0
// @Title deleteLikingOnUser
// @Description Delete a liking on user.
// @Accept  json
// @Param   userId        path    int     true        "User ID"
// @Param   id                path    int     true        "Liking 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 "Liking is not deleted"
// @Resource /users
// @Router /users/{id}/likings/{likingId} [delete]
func deleteLikingOnUser(c *gin.Context) {
	status, err := userLiking.DeleteLikingOnUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "liking.unlike.done",
		Unauthorized:        "liking.error.unauthorized",
		NotFound:            "liking.error.notFound",
		InternalServerError: "liking.unlike.fail",
	}
	messages := &response.Messages{OK: "Liking is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 13
0
// @Title removeRoleFromUser
// @Description Remove a role from user.
// @Accept  json
// @Param   id        path   int  true        "User ID."
// @Param   roleId        form   int  true        "Role ID."
// @Success 200 {object} response.BasicResponse "OK"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "Role is not deleted from a user"
// @Resource /users
// @Router /users/{id}/roles/{roleId} [delete]
func removeRoleFromUser(c *gin.Context) {
	status, err := userService.RemoveRoleFromUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "admin.user.role.delete.done",
		Unauthorized:        "user.error.unauthorized",
		NotFound:            "user.error.notFound",
		InternalServerError: "admin.user.role.delete.fail",
	}
	messages := &response.Messages{OK: "Role is deleted from a user successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 14
0
// @Title addRoleToUser
// @Description Add a role to user.
// @Accept  json
// @Param   userId        form   int  true        "User ID."
// @Param   roleId        form   int  true        "Role ID."
// @Success 201 {object} response.BasicResponse "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "User or role is not found"
// @Failure 500 {object} response.BasicResponse "Role is not added to a user"
// @Resource /users
// @Router /users/roles [post]
func addRoleToUser(c *gin.Context) {
	status, err := userService.AddRoleToUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "admin.user.role.add.done",
		Unauthorized:        "user.error.unauthorized",
		NotFound:            "user.error.notFound",
		InternalServerError: "admin.user.role.add.fail",
	}
	messages := &response.Messages{OK: "Role is added to a user successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 15
0
// @Title deleteCommentOnArticle
// @Description Delete a comment on article.
// @Accept  json
// @Param   articleId        path    int     true        "Article Id"
// @Param   id                path    int     true        "Comment Id"
// @Success 200 {object} response.BasicResponse "Comment is deleted 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 deleted"
// @Resource /articles
// @Router /articles/{id}/comments/{commentId} [delete]
func deleteCommentOnArticle(c *gin.Context) {
	status, err := articleService.DeleteCommentOnArticle(c)
	messageTypes := &response.MessageTypes{
		OK:                  "comment.deleted.done",
		Unauthorized:        "comment.error.unauthorized",
		Forbidden:           "comment.error.forbidden",
		NotFound:            "comment.error.notFound",
		InternalServerError: "comment.deleted.fail"}
	messages := &response.Messages{OK: "Comment is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 16
0
// @Title createUser
// @Description Create a user.
// @Accept  json
// @Param   registrationEmail        form   string     true        "User Email."
// @Param   registrationPassword        form   string  true        "User Password."
// @Success 201 {object} response.BasicResponse "User is registered successfully"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "User not logged in."
// @Failure 500 {object} response.BasicResponse "User is not created."
// @Resource /users
// @Router /users [post]
func createUser(c *gin.Context) {
	status, err := userService.CreateUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "registration.done",
		Unauthorized:        "login.error.fail",
		NotFound:            "registration.error.fail",
		InternalServerError: "registration.error.fail",
	}
	messages := &response.Messages{OK: "User is registered successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 17
0
// @Title deleteFile
// @Description Delete a file.
// @Accept  json
// @Param   id        path    int     true        "File ID"
// @Success 200 {object} response.BasicResponse
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /upload/files
// @Router /upload/{id} [delete]
func deleteFile(c *gin.Context) {
	log.Debug("deleteFile performed")
	status, err := uploadService.DeleteFile(c)
	messageTypes := &response.MessageTypes{
		OK:           "destroy.done",
		BadRequest:   "destroy.fail",
		Unauthorized: "upload.file.error.unauthorized",
		NotFound:     "upload.file.error.notFound"}
	messages := &response.Messages{OK: "File is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 18
0
// @Title createArticles
// @Description Create a file.
// @Accept  json
// @Param   title        form   string     true        "Article title."
// @Param   url        form   string     true        "Article url."
// @Param   imageName        form   string     true        "Article imagename."
// @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 /upload/files
// @Router /upload [post]
func createArticles(c *gin.Context) {
	status, err := articleService.CreateArticles(c)

	messageTypes := &response.MessageTypes{
		OK:                  "article.create.done",
		Unauthorized:        "article.error.unauthorized",
		InternalServerError: "article.error.notCreated",
	}
	messages := &response.Messages{OK: "Metadata of articles are created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 19
0
// @Title deleteLikingOnArticle
// @Description Delete a liking on article.
// @Accept  json
// @Param   articleId        path    int     true        "Article Id"
// @Param   id                path    int     true        "Liking Id"
// @Success 200 {object} response.BasicResponse "Liking is deleted 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 "Liking is not deleted"
// @Resource /articles
// @Router /articles/{id}/likings/{likingId} [delete]
func deleteLikingOnArticle(c *gin.Context) {
	status, err := articleService.DeleteLikingOnArticle(c)
	messageTypes := &response.MessageTypes{
		OK:                  "liking.unlike.done",
		Unauthorized:        "liking.error.unauthorized",
		Forbidden:           "liking.error.forbidden",
		NotFound:            "liking.error.notFound",
		InternalServerError: "liking.unlike.fail"}
	messages := &response.Messages{OK: "Article liked successfully."}

	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 20
0
// @Title uploadAndSyncArticles
// @Description upload images to storage. And sync article data. Request should contain multipart form data.
// @Accept  json
// @Success 201 {object} gin.H "Uploaded"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Upload failed"
// @Resource /articles/sync
// @Router /articles [post]
func uploadAndSyncArticles(c *gin.Context) {
	status, err := articleService.UploadAndSyncArticles(c)
	messageTypes := &response.MessageTypes{
		OK:                  "article.upload.done",
		BadRequest:          "article.upload.error.badRequest",
		Unauthorized:        "article.upload.error.unauthorized",
		Forbidden:           "article.upload.error.forbidden",
		NotFound:            "article.upload.error.notFound",
		InternalServerError: "article.upload.error.internalServerError",
	}
	messages := &response.Messages{OK: "Files uploaded successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
Esempio n. 21
0
// @Title deleteRole
// @Description Delete a role.
// @Accept  json
// @Param   id        path    int     true        "Role ID"
// @Success 200 {object} response.BasicResponse
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /roles
// @Router /roles/{id} [delete]
func deleteRole(c *gin.Context) {
	log.Debug("deleteRole performed")
	status, err := roleService.DeleteRole(c)
	messageTypes := &response.MessageTypes{
		OK:           "destroy.done",
		BadRequest:   "destroy.fail",
		Unauthorized: "role.error.unauthorized",
		NotFound:     "role.error.notFound"}
	messages := &response.Messages{OK: "Role is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
	//
	// if err == nil {
	// 	c.JSON(status, response.BasicResponse{})
	// } else {
	// 	c.JSON(400, response.BasicResponse{})
	// }
}
Esempio n. 22
0
// @Title createFile
// @Description Create a file.
// @Accept  json
// @Param   name        form   string     true        "Name of File."
// @Param   size        form   int  true        "Description of File."
// @Success 201 {object} model.File "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "File is not created"
// @Resource /upload/files
// @Router /upload [post]
func createFile(c *gin.Context) {
	status, err := uploadService.CreateFile(c)
	messageTypes := &response.MessageTypes{
		OK:                  "upload.file.create.done",
		Unauthorized:        "upload.file.error.unauthorized",
		InternalServerError: "upload.file.create.fail",
	}
	messages := &response.Messages{OK: "File model created successfully."}
	response.JSON(c, status, messageTypes, messages, err)

	// if err == nil {
	// 	c.JSON(status, gin.H{"file": file})
	// } else {
	// 	messageTypes := &response.MessageTypes{Unauthorized: "upload.file.error.unauthorized",
	// 		InternalServerError: "upload.file.create.fail"}
	// 	response.ErrorJSON(c, status, messageTypes, err)
	// }
}
Esempio n. 23
0
// @Title deleteUserAuthentication
// @Description Delete a user session.
// @Accept  json
// @Success 200 {object}  response.BasicResponse "User logged out successfully"
// @Resource /authentications
// @Router /authentications [delete]
func deleteUserAuthentication(c *gin.Context) {
	status, err := userService.ClearCookie(c)
	messageTypes := &response.MessageTypes{OK: "logout.done"}
	messages := &response.Messages{OK: "User logged out successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}