feat: initialized all controllers for release 1;
feat: authentication added to swagger
This commit is contained in:
@@ -23,7 +23,19 @@ func main() {
|
|||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r = routes.SetupRoutes(r)
|
r = routes.SetupRoutes(r)
|
||||||
|
|
||||||
docs.SwaggerInfo.BasePath = "/api/"
|
// @title Easywish client API
|
||||||
|
// @version 1.0
|
||||||
|
// @description Easy and feature-rich wishlist.
|
||||||
|
// @license.name GPL 3.0
|
||||||
|
|
||||||
|
// @BasePath /api/
|
||||||
|
// @Schemes http
|
||||||
|
|
||||||
|
// @securityDefinitions.apikey JWT
|
||||||
|
// @in header
|
||||||
|
// @name Authorization
|
||||||
|
|
||||||
|
docs.SwaggerInfo.Schemes = []string{"http"}
|
||||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
|
||||||
|
|
||||||
r.Run(":8080")
|
r.Run(":8080")
|
||||||
|
|||||||
@@ -10,11 +10,34 @@ const docTemplate = `{
|
|||||||
"description": "{{escape .Description}}",
|
"description": "{{escape .Description}}",
|
||||||
"title": "{{.Title}}",
|
"title": "{{.Title}}",
|
||||||
"contact": {},
|
"contact": {},
|
||||||
|
"license": {
|
||||||
|
"name": "GPL 3.0"
|
||||||
|
},
|
||||||
"version": "{{.Version}}"
|
"version": "{{.Version}}"
|
||||||
},
|
},
|
||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/account/changePassword": {
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Account"
|
||||||
|
],
|
||||||
|
"summary": "Change account password",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/auth/login": {
|
"/auth/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"consumes": [
|
"consumes": [
|
||||||
@@ -105,6 +128,93 @@ const docTemplate = `{
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/profile/me": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Get own profile when authorized",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/profile/privacy": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Get profile privacy settings",
|
||||||
|
"responses": {}
|
||||||
|
},
|
||||||
|
"patch": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Update profile privacy settings",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/profile/{username}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Get someone's profile details",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Username",
|
||||||
|
"name": "username",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/service/health": {
|
"/service/health": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Used internally for checking service health",
|
"description": "Used internally for checking service health",
|
||||||
@@ -138,17 +248,24 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"securityDefinitions": {
|
||||||
|
"JWT": {
|
||||||
|
"type": "apiKey",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||||
var SwaggerInfo = &swag.Spec{
|
var SwaggerInfo = &swag.Spec{
|
||||||
Version: "",
|
Version: "1.0",
|
||||||
Host: "",
|
Host: "",
|
||||||
BasePath: "",
|
BasePath: "/api/",
|
||||||
Schemes: []string{},
|
Schemes: []string{"http"},
|
||||||
Title: "",
|
Title: "Easywish client API",
|
||||||
Description: "",
|
Description: "Easy and feature-rich wishlist.",
|
||||||
InfoInstanceName: "swagger",
|
InfoInstanceName: "swagger",
|
||||||
SwaggerTemplate: docTemplate,
|
SwaggerTemplate: docTemplate,
|
||||||
LeftDelim: "{{",
|
LeftDelim: "{{",
|
||||||
|
|||||||
@@ -1,9 +1,39 @@
|
|||||||
{
|
{
|
||||||
|
"schemes": [
|
||||||
|
"http"
|
||||||
|
],
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"contact": {}
|
"description": "Easy and feature-rich wishlist.",
|
||||||
|
"title": "Easywish client API",
|
||||||
|
"contact": {},
|
||||||
|
"license": {
|
||||||
|
"name": "GPL 3.0"
|
||||||
},
|
},
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"basePath": "/api/",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/account/changePassword": {
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Account"
|
||||||
|
],
|
||||||
|
"summary": "Change account password",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/auth/login": {
|
"/auth/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"consumes": [
|
"consumes": [
|
||||||
@@ -94,6 +124,93 @@
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/profile/me": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Get own profile when authorized",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/profile/privacy": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Get profile privacy settings",
|
||||||
|
"responses": {}
|
||||||
|
},
|
||||||
|
"patch": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Update profile privacy settings",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/profile/{username}": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Get someone's profile details",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Username",
|
||||||
|
"name": "username",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/service/health": {
|
"/service/health": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Used internally for checking service health",
|
"description": "Used internally for checking service health",
|
||||||
@@ -127,5 +244,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"securityDefinitions": {
|
||||||
|
"JWT": {
|
||||||
|
"type": "apiKey",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
basePath: /api/
|
||||||
definitions:
|
definitions:
|
||||||
controllers.HealthStatus:
|
controllers.HealthStatus:
|
||||||
properties:
|
properties:
|
||||||
@@ -6,7 +7,24 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
|
description: Easy and feature-rich wishlist.
|
||||||
|
license:
|
||||||
|
name: GPL 3.0
|
||||||
|
title: Easywish client API
|
||||||
|
version: "1.0"
|
||||||
paths:
|
paths:
|
||||||
|
/account/changePassword:
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses: {}
|
||||||
|
security:
|
||||||
|
- JWT: []
|
||||||
|
summary: Change account password
|
||||||
|
tags:
|
||||||
|
- Account
|
||||||
/auth/login:
|
/auth/login:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -68,6 +86,59 @@ paths:
|
|||||||
summary: Confirm with code, finish creating the account
|
summary: Confirm with code, finish creating the account
|
||||||
tags:
|
tags:
|
||||||
- Auth
|
- Auth
|
||||||
|
/profile/{username}:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- description: Username
|
||||||
|
in: path
|
||||||
|
name: username
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses: {}
|
||||||
|
security:
|
||||||
|
- JWT: []
|
||||||
|
summary: Get someone's profile details
|
||||||
|
tags:
|
||||||
|
- Profile
|
||||||
|
/profile/me:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses: {}
|
||||||
|
security:
|
||||||
|
- JWT: []
|
||||||
|
summary: Get own profile when authorized
|
||||||
|
tags:
|
||||||
|
- Profile
|
||||||
|
/profile/privacy:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses: {}
|
||||||
|
security:
|
||||||
|
- JWT: []
|
||||||
|
summary: Get profile privacy settings
|
||||||
|
tags:
|
||||||
|
- Profile
|
||||||
|
patch:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses: {}
|
||||||
|
security:
|
||||||
|
- JWT: []
|
||||||
|
summary: Update profile privacy settings
|
||||||
|
tags:
|
||||||
|
- Profile
|
||||||
/service/health:
|
/service/health:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -83,4 +154,11 @@ paths:
|
|||||||
summary: Get health status
|
summary: Get health status
|
||||||
tags:
|
tags:
|
||||||
- Service
|
- Service
|
||||||
|
schemes:
|
||||||
|
- http
|
||||||
|
securityDefinitions:
|
||||||
|
JWT:
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
type: apiKey
|
||||||
swagger: "2.0"
|
swagger: "2.0"
|
||||||
|
|||||||
18
backend/internal/controllers/account.go
Normal file
18
backend/internal/controllers/account.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// @Summary Change account password
|
||||||
|
// @Tags Account
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security JWT
|
||||||
|
// @Router /account/changePassword [put]
|
||||||
|
func ChangePassword(c *gin.Context) {
|
||||||
|
c.Status(http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
||||||
65
backend/internal/controllers/profile.go
Normal file
65
backend/internal/controllers/profile.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// @Summary Get someone's profile details
|
||||||
|
// @Tags Profile
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param username path string true "Username"
|
||||||
|
// @Security JWT
|
||||||
|
// @Router /profile/{username} [get]
|
||||||
|
func GetProfile(c *gin.Context) {
|
||||||
|
|
||||||
|
username := c.Param("username")
|
||||||
|
|
||||||
|
if username == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
|
"error": "Username cannot be empty",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusNotImplemented, gin.H{
|
||||||
|
"username": username,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Summary Get own profile when authorized
|
||||||
|
// @Tags Profile
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security JWT
|
||||||
|
// @Router /profile/me [get]
|
||||||
|
func GetOwnProfile(c *gin.Context) {
|
||||||
|
|
||||||
|
username := "Gregory House"
|
||||||
|
|
||||||
|
c.JSON(http.StatusNotImplemented, gin.H{
|
||||||
|
"username": username,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Summary Get profile privacy settings
|
||||||
|
// @Tags Profile
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security JWT
|
||||||
|
// @Router /profile/privacy [get]
|
||||||
|
func GetPrivacySettings(c *gin.Context) {
|
||||||
|
c.Status(http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Summary Update profile privacy settings
|
||||||
|
// @Tags Profile
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security JWT
|
||||||
|
// @Router /profile/privacy [patch]
|
||||||
|
func UpdatePrivacySettings(c *gin.Context) {
|
||||||
|
c.Status(http.StatusNotImplemented)
|
||||||
|
}
|
||||||
@@ -23,6 +23,19 @@ func SetupRoutes(r *gin.Engine) *gin.Engine {
|
|||||||
authGroup.POST("/passwordResetBegin", controllers.PasswordResetBegin)
|
authGroup.POST("/passwordResetBegin", controllers.PasswordResetBegin)
|
||||||
authGroup.POST("/passwordResetComplete", controllers.PasswordResetComplete)
|
authGroup.POST("/passwordResetComplete", controllers.PasswordResetComplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accountGroup := apiGroup.Group("/account")
|
||||||
|
{
|
||||||
|
accountGroup.PUT("/changePassword", controllers.ChangePassword)
|
||||||
|
}
|
||||||
|
|
||||||
|
profileGroup := apiGroup.Group("/profile")
|
||||||
|
{
|
||||||
|
profileGroup.GET("/:username", controllers.GetProfile)
|
||||||
|
profileGroup.GET("/me", controllers.GetOwnProfile)
|
||||||
|
profileGroup.GET("/privacy", controllers.GetPrivacySettings)
|
||||||
|
profileGroup.PATCH("/privacy", controllers.UpdatePrivacySettings)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
Reference in New Issue
Block a user