v2.1
This commit is contained in:
1 parent
d18a665c79
commit
5ef5057032
37 files changed
+773
-59
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"pmail/dto"
|
||||
"pmail/dto/response"
|
||||
"pmail/services/del_email"
|
||||
)
|
||||
|
||||
type emailDeleteRequest struct {
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
|
||||
func EmailDelete(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
reqBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
var reqData emailDeleteRequest
|
||||
err = json.Unmarshal(reqBytes, &reqData)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
|
||||
if len(reqData.IDs) <= 0 {
|
||||
response.NewErrorResponse(response.ParamsError, "ID错误", "").FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
err = del_email.DelEmail(ctx, reqData.IDs)
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse("success").FPrint(w)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"pmail/dto"
|
||||
"pmail/dto/response"
|
||||
"pmail/services/group"
|
||||
)
|
||||
|
||||
type moveRequest struct {
|
||||
GroupId int `json:"group_id"`
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
|
||||
func Move(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
reqBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
var reqData moveRequest
|
||||
err = json.Unmarshal(reqBytes, &reqData)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
|
||||
if len(reqData.IDs) <= 0 {
|
||||
response.NewErrorResponse(response.ParamsError, "ID错误", "").FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
if !group.MoveMailToGroup(ctx, reqData.IDs, reqData.GroupId) {
|
||||
response.NewErrorResponse(response.ServerError, "Error", "").FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse("success").FPrint(w)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"pmail/dto"
|
||||
"pmail/dto/response"
|
||||
"pmail/services/detail"
|
||||
)
|
||||
|
||||
type markReadRequest struct {
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
|
||||
func MarkRead(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
reqBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
var reqData markReadRequest
|
||||
err = json.Unmarshal(reqBytes, &reqData)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
|
||||
if len(reqData.IDs) <= 0 {
|
||||
response.NewErrorResponse(response.ParamsError, "ID错误", "").FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
for _, id := range reqData.IDs {
|
||||
detail.GetEmailDetail(ctx, id, true)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse("success").FPrint(w)
|
||||
|
||||
}
|
||||
@@ -1,27 +1,32 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"pmail/db"
|
||||
"pmail/dto"
|
||||
"pmail/dto/response"
|
||||
"pmail/i18n"
|
||||
"pmail/services/group"
|
||||
"pmail/utils/array"
|
||||
)
|
||||
|
||||
type groupItem struct {
|
||||
Label string `json:"label"`
|
||||
Tag string `json:"tag"`
|
||||
Children []*groupItem `json:"children"`
|
||||
func GetUserGroupList(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
infos := group.GetGroupList(ctx)
|
||||
response.NewSuccessResponse(infos).FPrint(w)
|
||||
}
|
||||
|
||||
func GetUserGroup(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
retData := []*groupItem{
|
||||
retData := []*group.GroupItem{
|
||||
{
|
||||
Label: i18n.GetText(ctx.Lang, "all_email"),
|
||||
Children: []*groupItem{
|
||||
Children: []*group.GroupItem{
|
||||
{
|
||||
Label: i18n.GetText(ctx.Lang, "inbox"),
|
||||
Tag: dto.SearchTag{Type: 0, Status: -1}.ToString(),
|
||||
Tag: dto.SearchTag{Type: 0, Status: -1, GroupId: 0}.ToString(),
|
||||
},
|
||||
{
|
||||
Label: i18n.GetText(ctx.Lang, "outbox"),
|
||||
@@ -35,5 +40,59 @@ func GetUserGroup(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
},
|
||||
}
|
||||
|
||||
retData = array.Merge(retData, group.GetGroupInfoList(ctx))
|
||||
|
||||
response.NewSuccessResponse(retData).FPrint(w)
|
||||
}
|
||||
|
||||
type addGroupRequest struct {
|
||||
Name string `json:"name"`
|
||||
ParentId int `json:"parent_id"`
|
||||
}
|
||||
|
||||
func AddGroup(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
var reqData *addGroupRequest
|
||||
reqBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
err = json.Unmarshal(reqBytes, &reqData)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
|
||||
res, err := db.Instance.Exec(db.WithContext(ctx, "insert into `group` (name,parent_id,user_id) values (?,?,?)"), reqData.Name, reqData.ParentId, ctx.UserInfo.ID)
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, "DBError", err.Error()).FPrint(w)
|
||||
return
|
||||
}
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, "DBError", err.Error()).FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse(id).FPrint(w)
|
||||
}
|
||||
|
||||
type delGroupRequest struct {
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
func DelGroup(ctx *dto.Context, w http.ResponseWriter, req *http.Request) {
|
||||
var reqData *delGroupRequest
|
||||
reqBytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
err = json.Unmarshal(reqBytes, &reqData)
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
succ, err := group.DelGroup(ctx, reqData.Id)
|
||||
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, "DBError", err.Error()).FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse(succ).FPrint(w)
|
||||
}
|
||||
Reference in new issue
Block a user