Skip to content

Commit

Permalink
Merge pull request #66 from suyuan32/feat-post
Browse files Browse the repository at this point in the history
Feat:  post management
  • Loading branch information
suyuan32 authored Feb 5, 2023
2 parents 5f3ab65 + b7afbc6 commit 4bfa34a
Show file tree
Hide file tree
Showing 73 changed files with 8,951 additions and 2,932 deletions.
3 changes: 2 additions & 1 deletion api/desc/all.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import "dictionary.api"
import "oauth.api"
import "token.api"
import "core.api"
import "department.api"
import "department.api"
import "post.api"
101 changes: 101 additions & 0 deletions api/desc/post.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import "base.api"

type (
// The response data of post information | 职位信息
PostInfo {
BaseInfo

// Name translation | 名称翻译
Trans string `json:"trans"`

// Status
Status uint32 `json:"status"`

// Sort
Sort uint32 `json:"sort"`

// Name
Name string `json:"name"`

// Code
Code string `json:"code"`

// Remark
Remark string `json:"remark"`
}

// Create or update post information request | 创建或更新职位信息
CreateOrUpdatePostReq {
// ID
// Required: true
Id uint64 `json:"id"`

// Status
Status uint32 `json:"status"`

// Sort
Sort uint32 `json:"sort"`

// Name
Name string `json:"name"`

// Code
Code string `json:"code"`

// Remark
Remark string `json:"remark"`
}

// The response data of post list | 职位列表数据
PostListResp {
BaseDataInfo

// Post list data | 职位 列表数据
Data PostListInfo `json:"data"`
}

// Post list data | 职位 列表数据
PostListInfo {
BaseListInfo

// The API list data | 职位 列表数据
Data []PostInfo `json:"data"`
}

// Get post list request params | 职位列表请求参数
PostListReq {
PageInfo

// Name
Name string `json:"name,optional"`
}
)

@server(
jwt: Auth
group: post
middleware: Authority
)

service core {
// Create or update post information | 创建或更新职位
@handler createOrUpdatePost
post /post/create_or_update (CreateOrUpdatePostReq) returns (BaseMsgResp)

// Delete post information | 删除职位信息
@handler deletePost
post /post/delete (IDReq) returns (BaseMsgResp)

// Get post list | 获取职位列表
@handler getPostList
post /post/list (PostListReq) returns (PostListResp)

// Delete post information | 删除职位信息
@handler batchDeletePost
post /post/batch_delete (IDsReq) returns (BaseMsgResp)

// Set post's status | 更新职位状态
@handler updatePostStatus
post /post/status (StatusCodeReq) returns (BaseMsgResp)

}
9 changes: 9 additions & 0 deletions api/desc/user.api
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ type (

// User's department id | 用户的部门ID
DepartmentId uint64 `json:"departmentId"`

// User's post id | 用户的职位ID
PostId uint64 `json:"postId"`
}

// The response data of user's basic information | 用户基本信息返回数据
Expand Down Expand Up @@ -311,6 +314,9 @@ type (

// The description of user | 用户的描述信息
Description string `json:"desc,optional"`

// User's post id | 用户的职位ID
PostId uint64 `json:"postId"`
}

// Get user list request | 获取用户列表请求参数
Expand Down Expand Up @@ -346,6 +352,9 @@ type (

// The user's department ID | 用户所属部门ID
DepartmentId uint64 `json:"departmentId,optional"`

// User's post id | 用户的职位ID
PostId uint64 `json:"postId,optional"`
}
)

Expand Down
45 changes: 45 additions & 0 deletions api/internal/handler/post/batch_delete_post_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package post

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-core/api/internal/logic/post"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
)

// swagger:route post /post/batch_delete post BatchDeletePost
//
// Delete post information | 删除职位信息
//
// Delete post information | 删除职位信息
//
// Parameters:
// + name: body
// require: true
// in: body
// type: IDsReq
//
// Responses:
// 200: BaseMsgResp

func BatchDeletePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.IDsReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := post.NewBatchDeletePostLogic(r, svcCtx)
resp, err := l.BatchDeletePost(&req)
if err != nil {
err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
45 changes: 45 additions & 0 deletions api/internal/handler/post/create_or_update_post_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package post

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-core/api/internal/logic/post"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
)

// swagger:route post /post/create_or_update post CreateOrUpdatePost
//
// Create or update post information | 创建或更新职位
//
// Create or update post information | 创建或更新职位
//
// Parameters:
// + name: body
// require: true
// in: body
// type: CreateOrUpdatePostReq
//
// Responses:
// 200: BaseMsgResp

func CreateOrUpdatePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateOrUpdatePostReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := post.NewCreateOrUpdatePostLogic(r, svcCtx)
resp, err := l.CreateOrUpdatePost(&req)
if err != nil {
err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
45 changes: 45 additions & 0 deletions api/internal/handler/post/delete_post_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package post

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-core/api/internal/logic/post"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
)

// swagger:route post /post/delete post DeletePost
//
// Delete post information | 删除职位信息
//
// Delete post information | 删除职位信息
//
// Parameters:
// + name: body
// require: true
// in: body
// type: IDReq
//
// Responses:
// 200: BaseMsgResp

func DeletePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.IDReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := post.NewDeletePostLogic(r, svcCtx)
resp, err := l.DeletePost(&req)
if err != nil {
err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
45 changes: 45 additions & 0 deletions api/internal/handler/post/get_post_list_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package post

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-core/api/internal/logic/post"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
)

// swagger:route post /post/list post GetPostList
//
// Get post list | 获取职位列表
//
// Get post list | 获取职位列表
//
// Parameters:
// + name: body
// require: true
// in: body
// type: PostListReq
//
// Responses:
// 200: PostListResp

func GetPostListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PostListReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := post.NewGetPostListLogic(r, svcCtx)
resp, err := l.GetPostList(&req)
if err != nil {
err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
45 changes: 45 additions & 0 deletions api/internal/handler/post/update_post_status_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package post

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"

"github.com/suyuan32/simple-admin-core/api/internal/logic/post"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
)

// swagger:route post /post/status post UpdatePostStatus
//
// Set post's status | 更新职位状态
//
// Set post's status | 更新职位状态
//
// Parameters:
// + name: body
// require: true
// in: body
// type: StatusCodeReq
//
// Responses:
// 200: BaseMsgResp

func UpdatePostStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.StatusCodeReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := post.NewUpdatePostStatusLogic(r, svcCtx)
resp, err := l.UpdatePostStatus(&req)
if err != nil {
err = svcCtx.Trans.TransError(r.Header.Get("Accept-Language"), err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
Loading

0 comments on commit 4bfa34a

Please sign in to comment.