Added completed user. Some fixes and more more more...
This commit is contained in:
parent
b96dd39795
commit
ea8ab7c0ed
33 changed files with 576 additions and 212 deletions
|
|
@ -36,6 +36,7 @@ func CreateImagesController(images_path string, service *services.ImagesService)
|
|||
// @Success 200 {object} responses.ImageResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /images/ [post]
|
||||
// @Security BasicAuth
|
||||
func (r *ImagesController) PostImage(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
|
|
@ -139,6 +140,21 @@ func (r *ImagesController) GetImage(c *gin.Context) {
|
|||
c.File(filePath)
|
||||
}
|
||||
|
||||
// @Summary Delete image by path
|
||||
// @Description Delete image from server by given path
|
||||
// @Tags images
|
||||
// @Param filename path string true "Path to image"
|
||||
// @Produce image/png
|
||||
// @Produce image/jpeg
|
||||
// @Success 200 {object} responses.GetAllImagesList
|
||||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /images [get]
|
||||
func (r *ImagesController) GetAllImage(c *gin.Context) {
|
||||
panic("Not implemented")
|
||||
}
|
||||
|
||||
// @Summary Delete image by path
|
||||
// @Description Delete image from server by given path
|
||||
// @Tags images
|
||||
|
|
@ -150,6 +166,7 @@ func (r *ImagesController) GetImage(c *gin.Context) {
|
|||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /images/{path} [delete]
|
||||
// @Security BasicAuth
|
||||
func (r *ImagesController) DeleteImage(c *gin.Context) {
|
||||
panic("Not implemented")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ func CreatePostController(service *services.PostService, userService *services.U
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /post [post]
|
||||
//
|
||||
// @Security BasicAuth
|
||||
func (r *PostController) Post(c *gin.Context) {
|
||||
var request requests.CreatePostRequest
|
||||
|
||||
|
|
@ -227,6 +229,8 @@ func (r *PostController) GetById(c *gin.Context) {
|
|||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /post/{id} [put]
|
||||
//
|
||||
// @Security BasicAuth
|
||||
func (r *PostController) Put(c *gin.Context) {
|
||||
var request requests.PutPostRequest
|
||||
|
||||
|
|
@ -276,6 +280,8 @@ func (r *PostController) Put(c *gin.Context) {
|
|||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /post/{id} [delete]
|
||||
//
|
||||
// @Security BasicAuth
|
||||
func (r *PostController) Delete(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
id_valid, err := uuid.Parse(id)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"58team_blog/internal/utils"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -107,6 +108,7 @@ func (r *UserController) Login(c *gin.Context) {
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /logout [get]
|
||||
// @Security BasicAuth
|
||||
func (r *UserController) Logout(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get("user")
|
||||
|
|
@ -132,7 +134,8 @@ func (r *UserController) Logout(c *gin.Context) {
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 409 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /user/ [post]
|
||||
// @Router /team/ [post]
|
||||
// @Security BasicAuth
|
||||
func (r *UserController) Post(c *gin.Context) {
|
||||
var request requests.CreateUserRequest
|
||||
if err := c.BindJSON(&request); err != nil {
|
||||
|
|
@ -151,8 +154,17 @@ func (r *UserController) Post(c *gin.Context) {
|
|||
}
|
||||
|
||||
cmd := commands.CreateUserCommand{
|
||||
Username: request.Username,
|
||||
Password: encrypted_password,
|
||||
Username: request.Username,
|
||||
Password: encrypted_password,
|
||||
Role: request.Role,
|
||||
Name: request.Name,
|
||||
Speciality: request.Speciality,
|
||||
Description: request.Description,
|
||||
Skills: strings.Join(request.Skills, ";"),
|
||||
Avatar: request.Avatar,
|
||||
JoinDate: request.JoinDate,
|
||||
Projects: strings.Join(request.Projects, ";"),
|
||||
Motto: request.Motto,
|
||||
}
|
||||
|
||||
user, err := r.service.Create(cmd)
|
||||
|
|
@ -177,7 +189,7 @@ func (r *UserController) Post(c *gin.Context) {
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /user/{id} [get]
|
||||
// @Router /team/{id} [get]
|
||||
func (r *UserController) FindById(c *gin.Context) {
|
||||
id_path := c.Param("id")
|
||||
|
||||
|
|
@ -214,7 +226,7 @@ func (r *UserController) FindById(c *gin.Context) {
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /user/name/{name} [get]
|
||||
// @Router /team/name/{name} [get]
|
||||
func (r *UserController) FindByName(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
|
||||
|
|
@ -230,6 +242,7 @@ func (r *UserController) FindByName(c *gin.Context) {
|
|||
}
|
||||
|
||||
response := mapper.ResponseFromUserFindByNameResult(user)
|
||||
|
||||
c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
|
|
@ -240,7 +253,7 @@ func (r *UserController) FindByName(c *gin.Context) {
|
|||
// @Success 200 {object} responses.UserResponseList
|
||||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /user/ [get]
|
||||
// @Router /members/ [get]
|
||||
func (r *UserController) GetAll(c *gin.Context) {
|
||||
users, err := r.service.GetAll()
|
||||
if err != nil {
|
||||
|
|
@ -249,8 +262,9 @@ func (r *UserController) GetAll(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
responses := mapper.ResponseFromUserGetAllResult(users)
|
||||
c.JSON(http.StatusOK, responses)
|
||||
resp := mapper.ResponseFromUserGetAllResult(users)
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary Change user
|
||||
|
|
@ -264,7 +278,8 @@ func (r *UserController) GetAll(c *gin.Context) {
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /user/{id} [put]
|
||||
// @Router /team/{id} [put]
|
||||
// @Security BasicAuth
|
||||
func (r *UserController) Put(c *gin.Context) {
|
||||
var request requests.PutUserRequest
|
||||
id_path := c.Param("id")
|
||||
|
|
@ -292,10 +307,21 @@ func (r *UserController) Put(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
skills := strings.Join(request.Skills, ";")
|
||||
projects := strings.Join(request.Projects, ";")
|
||||
|
||||
cmd := commands.UpdateUserCommand{
|
||||
Id: id,
|
||||
Username: request.Username,
|
||||
Password: password,
|
||||
Id: id,
|
||||
Username: request.Username,
|
||||
Name: request.Name,
|
||||
Password: password,
|
||||
Role: request.Role,
|
||||
Speciality: request.Speciality,
|
||||
Description: request.Description,
|
||||
Skills: skills,
|
||||
Avatar: request.Avatar,
|
||||
Projects: projects,
|
||||
Motto: request.Motto,
|
||||
}
|
||||
|
||||
user, err := r.service.Update(cmd)
|
||||
|
|
@ -318,7 +344,8 @@ func (r *UserController) Put(c *gin.Context) {
|
|||
// @Failure 400 {object} responses.ErrorResponse
|
||||
// @Failure 404 {object} responses.ErrorResponse
|
||||
// @Failure 500 {object} responses.ErrorResponse
|
||||
// @Router /user/{id} [delete]
|
||||
// @Router /team/{id} [delete]
|
||||
// @Security BasicAuth
|
||||
func (r *UserController) Delete(c *gin.Context) {
|
||||
id_path := c.Param("id")
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ func itemFromResult(item *common.PostResult) responses.GetListPostResponseItem {
|
|||
UserId: item.UserId.String(),
|
||||
Title: item.Title,
|
||||
Description: item.Description,
|
||||
UpdatedAt: item.UpdatedAt.String(),
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
Tags: item.Tags,
|
||||
Category: item.Category,
|
||||
}
|
||||
}
|
||||
|
||||
func ResponseFromPostGetAllResult(result *queries.PostGetAllResult) responses.GetListPostResponse {
|
||||
var resp []responses.GetListPostResponseItem
|
||||
resp := responses.GetListPostResponse{}
|
||||
|
||||
for _, r := range result.Result.Result {
|
||||
resp = append(resp, itemFromResult(r))
|
||||
|
|
|
|||
|
|
@ -3,11 +3,25 @@ package mapper
|
|||
import (
|
||||
"58team_blog/internal/application/queries"
|
||||
"58team_blog/internal/interfaces/api/responses"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ResponseFromUserFindByIdResult(user *queries.UserFindByIdResult) responses.UserResponse {
|
||||
res := user.Result
|
||||
skills := strings.Split(res.Skills, ";")
|
||||
projects := strings.Split(res.Projects, ";")
|
||||
|
||||
return responses.UserResponse{
|
||||
Id: user.Result.Id.String(),
|
||||
UserName: user.Result.UserName,
|
||||
Id: res.Id.String(),
|
||||
UserName: res.UserName,
|
||||
Name: res.Name,
|
||||
Role: res.Role,
|
||||
Speciality: res.Speciality,
|
||||
Description: res.Description,
|
||||
Skills: skills,
|
||||
Avatar: res.Avatar,
|
||||
JoinDate: res.JoinDate,
|
||||
Projects: projects,
|
||||
Motto: res.Motto,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,25 @@ package mapper
|
|||
import (
|
||||
"58team_blog/internal/application/queries"
|
||||
"58team_blog/internal/interfaces/api/responses"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ResponseFromUserFindByNameResult(result *queries.UserFindByNameResult) responses.UserResponse {
|
||||
res := result.Result
|
||||
skills := strings.Split(res.Skills, ";")
|
||||
projects := strings.Split(res.Projects, ";")
|
||||
|
||||
return responses.UserResponse{
|
||||
Id: result.Result.Id.String(),
|
||||
UserName: result.Result.UserName,
|
||||
Id: res.Id.String(),
|
||||
UserName: res.UserName,
|
||||
Name: res.Name,
|
||||
Role: res.Role,
|
||||
Speciality: res.Speciality,
|
||||
Description: res.Description,
|
||||
Skills: skills,
|
||||
Avatar: res.Avatar,
|
||||
JoinDate: res.JoinDate,
|
||||
Projects: projects,
|
||||
Motto: res.Motto,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func ResponseFromUserGetAllResult(result *queries.UserGetAllResult) responses.UserResponseList {
|
||||
var list responses.UserResponseList
|
||||
list := responses.UserResponseList{}
|
||||
|
||||
for _, i := range result.Result.Result {
|
||||
list = append(list, ResponseFromUserResult(i))
|
||||
|
|
|
|||
|
|
@ -3,11 +3,24 @@ package mapper
|
|||
import (
|
||||
"58team_blog/internal/application/common"
|
||||
"58team_blog/internal/interfaces/api/responses"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ResponseFromUserResult(result *common.UserResult) responses.UserResponse {
|
||||
skills := strings.Split(result.Skills, ";")
|
||||
projects := strings.Split(result.Projects, ";")
|
||||
|
||||
return responses.UserResponse{
|
||||
Id: result.Id.String(),
|
||||
UserName: result.UserName,
|
||||
Id: result.Id.String(),
|
||||
UserName: result.UserName,
|
||||
Name: result.Name,
|
||||
Role: result.Role,
|
||||
Speciality: result.Speciality,
|
||||
Description: result.Description,
|
||||
Skills: skills,
|
||||
Avatar: result.Avatar,
|
||||
JoinDate: result.JoinDate,
|
||||
Projects: projects,
|
||||
Motto: result.Motto,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package requests
|
||||
|
||||
type CreatePostRequest struct {
|
||||
Title string `json:"title" validate:"required,min=8,max=255"`
|
||||
Description string `json:"description" validate:"required,min=8,max=255"`
|
||||
Content string `json:"content" validate:"required,min=36"`
|
||||
UserId string `json:"userId" validate:"required,uuid5"`
|
||||
Title string `json:"title" binding:"required,min=8,max=255"`
|
||||
Description string `json:"description" binding:"required,min=8,max=255"`
|
||||
Content string `json:"content" binding:"required,min=36"`
|
||||
UserId string `json:"userId" binding:"required,uuid5"`
|
||||
Category string `json:"category"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,17 @@
|
|||
package requests
|
||||
|
||||
import "time"
|
||||
|
||||
type CreateUserRequest struct {
|
||||
Username string `json:"username" validate:"required,min=3,max=32"`
|
||||
Password string `json:"password" validate:"required,min=6,max=32,password"`
|
||||
Username string `json:"username" binding:"required,min=3,max=32"`
|
||||
Password string `json:"password" binding:"required,min=6,max=32,password"`
|
||||
Name string `json:"name" binding:"required,min=2,max=100"`
|
||||
Role string `json:"role" binding:"required"`
|
||||
Speciality string `json:"speciality" binding:"required,min=2,max=100"`
|
||||
Description string `json:"description" binding:"required,min=10,max=500"`
|
||||
Skills []string `json:"skills" binding:"required,min=1,inlineList"`
|
||||
Avatar string `json:"avatar" binding:"required"`
|
||||
JoinDate time.Time `json:"joinDate" binding:"required"`
|
||||
Projects []string `json:"projects" binding:"required,min=1,inlineList"`
|
||||
Motto string `json:"motto" binding:"required,min=2,max=200"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package requests
|
||||
|
||||
type LoginUserRequest struct {
|
||||
Username string `json:"username" validate:"required,min=3,max=32"`
|
||||
Password string `json:"password" validate:"required,min=6,max=32,password"`
|
||||
Username string `json:"username" binding:"required,min=3,max=32"`
|
||||
Password string `json:"password" binding:"required,min=6,max=32,password"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
package requests
|
||||
|
||||
type PutUserRequest struct {
|
||||
Username string `json:"username" validate:"required,min=3,max=32"`
|
||||
Password string `json:"password" validate:"required,min=6,max=32,password"`
|
||||
Username string `json:"username" binding:"required,min=3,max=32"`
|
||||
Password string `json:"password" binding:"required,min=6,max=32,password"`
|
||||
Name string `json:"name" binding:"required,min=2,max=100"`
|
||||
Role string `json:"role" binding:"required"`
|
||||
Speciality string `json:"speciality" binding:"required,min=2,max=100"`
|
||||
Description string `json:"description" binding:"required,min=10,max=500"`
|
||||
Skills []string `json:"skills" binding:"required,min=1,inlineList"`
|
||||
Avatar string `json:"avatar" binding:"required"`
|
||||
Projects []string `json:"projects" binding:"required,min=1,inlineList"`
|
||||
Motto string `json:"motto" binding:"required,min=2,max=200"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
package responses
|
||||
|
||||
import "time"
|
||||
|
||||
type GetListPostResponseItem struct {
|
||||
Id string `json:"id"`
|
||||
UserId string `json:"userId"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Tags []string `json:"tags"`
|
||||
Category string `json:"category"`
|
||||
Username string `json:"username"`
|
||||
Id string `json:"id"`
|
||||
UserId string `json:"userId"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Tags []string `json:"tags"`
|
||||
Category string `json:"category"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type GetListPostResponse []GetListPostResponseItem
|
||||
|
|
|
|||
4
internal/interfaces/api/responses/image_get_all.go
Normal file
4
internal/interfaces/api/responses/image_get_all.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
package responses
|
||||
|
||||
type GetAllImagesList struct {
|
||||
}
|
||||
|
|
@ -1,8 +1,18 @@
|
|||
package responses
|
||||
|
||||
type UserResponse struct {
|
||||
Id string `json:"id"`
|
||||
UserName string `json:"username"`
|
||||
}
|
||||
import "time"
|
||||
|
||||
type UserResponse struct {
|
||||
Id string `json:"id"`
|
||||
UserName string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Role string `json:"role"`
|
||||
Speciality string `json:"speciality"`
|
||||
Description string `json:"description"`
|
||||
Skills []string `json:"skills"`
|
||||
Avatar string `json:"avatar"`
|
||||
JoinDate time.Time `json:"joinDate"`
|
||||
Projects []string `json:"projects"`
|
||||
Motto string `json:"motto"`
|
||||
}
|
||||
type UserResponseList []UserResponse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue