Compare commits
24 Commits
1de2544b92
...
df6d6e857b
Author | SHA1 | Date |
---|---|---|
truthhun | df6d6e857b | 10 months ago |
truthhun | 89d79d6451 | 10 months ago |
truthhun | 7079e327de | 10 months ago |
truthhun | 1deb33774d | 10 months ago |
truthhun | 166d6998d3 | 10 months ago |
truthhun | abc27ea5aa | 10 months ago |
truthhun | b7b6a31688 | 10 months ago |
truthhun | f24f95f082 | 10 months ago |
truthhun | 1a8e0e1a54 | 10 months ago |
truthhun | 635622af73 | 11 months ago |
truthhun | f2b170d770 | 11 months ago |
truthhun | 7cba55c387 | 11 months ago |
truthhun | 55256b7ecd | 11 months ago |
truthhun | 3a179457b0 | 11 months ago |
truthhun | aa653542b5 | 11 months ago |
truthhun | 289bbc7d6c | 11 months ago |
truthhun | 006a8f1827 | 11 months ago |
truthhun | b09629b117 | 11 months ago |
truthhun | 7bc1cb40ef | 11 months ago |
truthhun | e4d8131357 | 11 months ago |
truthhun | 10bdfada92 | 11 months ago |
truthhun | 51e052d25d | 11 months ago |
truthhun | 232c67c96d | 11 months ago |
truthhun | 38d508d42e | 11 months ago |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,497 @@
|
|||||||
|
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||||
|
// source: api/v1/punishment.proto
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package v1 is a reverse proxy.
|
||||||
|
|
||||||
|
It translates gRPC into RESTful JSON APIs.
|
||||||
|
*/
|
||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/descriptor"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Suppress "imported and not used" errors
|
||||||
|
var _ codes.Code
|
||||||
|
var _ io.Reader
|
||||||
|
var _ status.Status
|
||||||
|
var _ = runtime.String
|
||||||
|
var _ = utilities.NewDoubleArray
|
||||||
|
var _ = descriptor.ForMessage
|
||||||
|
var _ = metadata.Join
|
||||||
|
|
||||||
|
func request_PunishmentAPI_CreatePunishment_0(ctx context.Context, marshaler runtime.Marshaler, client PunishmentAPIClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq CreatePunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.CreatePunishment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_PunishmentAPI_CreatePunishment_0(ctx context.Context, marshaler runtime.Marshaler, server PunishmentAPIServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq CreatePunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := server.CreatePunishment(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_PunishmentAPI_UpdatePunishment_0(ctx context.Context, marshaler runtime.Marshaler, client PunishmentAPIClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq Punishment
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.UpdatePunishment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_PunishmentAPI_UpdatePunishment_0(ctx context.Context, marshaler runtime.Marshaler, server PunishmentAPIServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq Punishment
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := server.UpdatePunishment(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
filter_PunishmentAPI_GetPunishment_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||||
|
)
|
||||||
|
|
||||||
|
func request_PunishmentAPI_GetPunishment_0(ctx context.Context, marshaler runtime.Marshaler, client PunishmentAPIClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq GetPunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
if err := req.ParseForm(); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_PunishmentAPI_GetPunishment_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.GetPunishment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_PunishmentAPI_GetPunishment_0(ctx context.Context, marshaler runtime.Marshaler, server PunishmentAPIServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq GetPunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
if err := req.ParseForm(); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_PunishmentAPI_GetPunishment_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := server.GetPunishment(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
filter_PunishmentAPI_ListPunishment_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||||
|
)
|
||||||
|
|
||||||
|
func request_PunishmentAPI_ListPunishment_0(ctx context.Context, marshaler runtime.Marshaler, client PunishmentAPIClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq ListPunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
if err := req.ParseForm(); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_PunishmentAPI_ListPunishment_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.ListPunishment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_PunishmentAPI_ListPunishment_0(ctx context.Context, marshaler runtime.Marshaler, server PunishmentAPIServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq ListPunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
if err := req.ParseForm(); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_PunishmentAPI_ListPunishment_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := server.ListPunishment(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func request_PunishmentAPI_CancelPunishment_0(ctx context.Context, marshaler runtime.Marshaler, client PunishmentAPIClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq CancelPunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := client.CancelPunishment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_PunishmentAPI_CancelPunishment_0(ctx context.Context, marshaler runtime.Marshaler, server PunishmentAPIServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq CancelPunishmentRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||||
|
if berr != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||||
|
}
|
||||||
|
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := server.CancelPunishment(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterPunishmentAPIHandlerServer registers the http handlers for service PunishmentAPI to "mux".
|
||||||
|
// UnaryRPC :call PunishmentAPIServer directly.
|
||||||
|
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||||
|
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterPunishmentAPIHandlerFromEndpoint instead.
|
||||||
|
func RegisterPunishmentAPIHandlerServer(ctx context.Context, mux *runtime.ServeMux, server PunishmentAPIServer) error {
|
||||||
|
|
||||||
|
mux.Handle("POST", pattern_PunishmentAPI_CreatePunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_PunishmentAPI_CreatePunishment_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_CreatePunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("PUT", pattern_PunishmentAPI_UpdatePunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_PunishmentAPI_UpdatePunishment_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_UpdatePunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_PunishmentAPI_GetPunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_PunishmentAPI_GetPunishment_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_GetPunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_PunishmentAPI_ListPunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_PunishmentAPI_ListPunishment_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_ListPunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("PUT", pattern_PunishmentAPI_CancelPunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
var stream runtime.ServerTransportStream
|
||||||
|
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_PunishmentAPI_CancelPunishment_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||||
|
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_CancelPunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterPunishmentAPIHandlerFromEndpoint is same as RegisterPunishmentAPIHandler but
|
||||||
|
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||||
|
func RegisterPunishmentAPIHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||||
|
conn, err := grpc.Dial(endpoint, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
if cerr := conn.Close(); cerr != nil {
|
||||||
|
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
if cerr := conn.Close(); cerr != nil {
|
||||||
|
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
|
||||||
|
return RegisterPunishmentAPIHandler(ctx, mux, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterPunishmentAPIHandler registers the http handlers for service PunishmentAPI to "mux".
|
||||||
|
// The handlers forward requests to the grpc endpoint over "conn".
|
||||||
|
func RegisterPunishmentAPIHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||||
|
return RegisterPunishmentAPIHandlerClient(ctx, mux, NewPunishmentAPIClient(conn))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterPunishmentAPIHandlerClient registers the http handlers for service PunishmentAPI
|
||||||
|
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "PunishmentAPIClient".
|
||||||
|
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "PunishmentAPIClient"
|
||||||
|
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||||
|
// "PunishmentAPIClient" to call the correct interceptors.
|
||||||
|
func RegisterPunishmentAPIHandlerClient(ctx context.Context, mux *runtime.ServeMux, client PunishmentAPIClient) error {
|
||||||
|
|
||||||
|
mux.Handle("POST", pattern_PunishmentAPI_CreatePunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_PunishmentAPI_CreatePunishment_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_CreatePunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("PUT", pattern_PunishmentAPI_UpdatePunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_PunishmentAPI_UpdatePunishment_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_UpdatePunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_PunishmentAPI_GetPunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_PunishmentAPI_GetPunishment_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_GetPunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_PunishmentAPI_ListPunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_PunishmentAPI_ListPunishment_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_ListPunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("PUT", pattern_PunishmentAPI_CancelPunishment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_PunishmentAPI_CancelPunishment_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_PunishmentAPI_CancelPunishment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
pattern_PunishmentAPI_CreatePunishment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "punishment"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
|
||||||
|
pattern_PunishmentAPI_UpdatePunishment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "punishment"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
|
||||||
|
pattern_PunishmentAPI_GetPunishment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "punishment"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
|
||||||
|
pattern_PunishmentAPI_ListPunishment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "punishment", "list"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
|
||||||
|
pattern_PunishmentAPI_CancelPunishment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "punishment", "cancel"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
forward_PunishmentAPI_CreatePunishment_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_PunishmentAPI_UpdatePunishment_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_PunishmentAPI_GetPunishment_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_PunishmentAPI_ListPunishment_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_PunishmentAPI_CancelPunishment_0 = runtime.ForwardResponseMessage
|
||||||
|
)
|
@ -0,0 +1,243 @@
|
|||||||
|
package biz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
pb "moredoc/api/v1"
|
||||||
|
"moredoc/middleware/auth"
|
||||||
|
"moredoc/model"
|
||||||
|
"moredoc/util"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PunishmentAPIService struct {
|
||||||
|
pb.UnimplementedPunishmentAPIServer
|
||||||
|
dbModel *model.DBModel
|
||||||
|
logger *zap.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPunishmentAPIService(dbModel *model.DBModel, logger *zap.Logger) (service *PunishmentAPIService) {
|
||||||
|
return &PunishmentAPIService{dbModel: dbModel, logger: logger.Named("PunishmentAPIService")}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PunishmentAPIService) checkPermission(ctx context.Context) (userClaims *auth.UserClaims, err error) {
|
||||||
|
return checkGRPCPermission(s.dbModel, ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PunishmentAPIService) CreatePunishment(ctx context.Context, req *pb.CreatePunishmentRequest) (*emptypb.Empty, error) {
|
||||||
|
userClaims, err := s.checkPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.UserId) == 0 {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "请选择用户")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.Type) == 0 {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "请选择处罚类型")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, userId := range req.UserId {
|
||||||
|
if userId == 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, typ := range req.Type {
|
||||||
|
punishment := &model.Punishment{
|
||||||
|
UserId: userId,
|
||||||
|
Type: int(typ),
|
||||||
|
Enable: req.Enable,
|
||||||
|
Reason: req.Reason,
|
||||||
|
Remark: req.Remark,
|
||||||
|
EndTime: req.EndTime,
|
||||||
|
}
|
||||||
|
s.logger.Debug("CreatePunishment", zap.Any("punishment", punishment), zap.Any("req", req))
|
||||||
|
punishment.Operators = s.dbModel.MakePunishmentOperators(userClaims.UserId, typ)
|
||||||
|
err = s.dbModel.CreatePunishment(punishment)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("CreatePunishment", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &emptypb.Empty{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PunishmentAPIService) UpdatePunishment(ctx context.Context, req *pb.Punishment) (*emptypb.Empty, error) {
|
||||||
|
userClaims, err := s.checkPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
punishment := &model.Punishment{}
|
||||||
|
err = util.CopyStruct(req, punishment)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("CopyStruct", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logger.Debug("UpdatePunishment", zap.Any("punishment", punishment), zap.Any("req", req))
|
||||||
|
|
||||||
|
if existPunishment, _ := s.dbModel.GetPunishment(punishment.Id, "id", "operators"); existPunishment.Id > 0 {
|
||||||
|
punishment.Operators = s.dbModel.MakePunishmentOperators(userClaims.UserId, req.Type, existPunishment.Operators)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.dbModel.UpdatePunishment(punishment)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("UpdatePunishment", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &emptypb.Empty{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PunishmentAPIService) GetPunishment(ctx context.Context, req *pb.GetPunishmentRequest) (*pb.Punishment, error) {
|
||||||
|
_, err := s.checkPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
punishment, err := s.dbModel.GetPunishment(req.Id)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("GetPunishment", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
res := &pb.Punishment{}
|
||||||
|
err = util.CopyStruct(punishment, res)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("CopyStruct", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if punishment.UserId > 0 {
|
||||||
|
user, _ := s.dbModel.GetUser(punishment.UserId, "id", "username")
|
||||||
|
if user.Id > 0 {
|
||||||
|
res.Username = user.Username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PunishmentAPIService) ListPunishment(ctx context.Context, req *pb.ListPunishmentRequest) (*pb.ListPunishmentReply, error) {
|
||||||
|
_, err := s.checkPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := &model.OptionGetPunishmentList{
|
||||||
|
Page: int(req.Page),
|
||||||
|
Size: int(req.Size_),
|
||||||
|
WithCount: true,
|
||||||
|
SelectFields: req.Field,
|
||||||
|
QueryLike: make(map[string][]interface{}),
|
||||||
|
QueryIn: make(map[string][]interface{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.UserId) > 0 {
|
||||||
|
opt.QueryIn["user_id"] = util.Slice2Interface(req.UserId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.Type) > 0 {
|
||||||
|
opt.QueryIn["type"] = util.Slice2Interface(req.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.Enable) > 0 {
|
||||||
|
opt.QueryIn["enable"] = util.Slice2Interface(req.Enable)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Order != "" {
|
||||||
|
opt.Sort = strings.Split(req.Order, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Wd != "" {
|
||||||
|
wd := strings.TrimSpace(req.Wd)
|
||||||
|
opt.QueryLike["reason"] = []interface{}{wd}
|
||||||
|
opt.QueryLike["remark"] = []interface{}{wd}
|
||||||
|
}
|
||||||
|
|
||||||
|
data, total, err := s.dbModel.GetPunishmentList(opt)
|
||||||
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
|
s.logger.Error("GetPunishmentList", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
res := &pb.ListPunishmentReply{
|
||||||
|
Total: total,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = util.CopyStruct(data, &res.Punishment)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("CopyStruct", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res.Punishment) > 0 {
|
||||||
|
var (
|
||||||
|
userIds []int64
|
||||||
|
userIdMapIndexes = make(map[int64][]int)
|
||||||
|
)
|
||||||
|
|
||||||
|
for i, v := range res.Punishment {
|
||||||
|
userIds = append(userIds, v.UserId)
|
||||||
|
userIdMapIndexes[v.UserId] = append(userIdMapIndexes[v.UserId], i)
|
||||||
|
}
|
||||||
|
|
||||||
|
users, _, _ := s.dbModel.GetUserList(&model.OptionGetUserList{
|
||||||
|
Ids: userIds,
|
||||||
|
WithCount: false,
|
||||||
|
SelectFields: []string{
|
||||||
|
"id",
|
||||||
|
"username",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, v := range users {
|
||||||
|
if indexes, ok := userIdMapIndexes[v.Id]; ok {
|
||||||
|
for _, index := range indexes {
|
||||||
|
res.Punishment[index].Username = v.Username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消惩罚
|
||||||
|
func (s *PunishmentAPIService) CancelPunishment(ctx context.Context, req *pb.CancelPunishmentRequest) (*emptypb.Empty, error) {
|
||||||
|
userCliams, err := s.checkPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logger.Debug("CancelPunishment", zap.Any("req", req))
|
||||||
|
|
||||||
|
data, _, err := s.dbModel.GetPunishmentList(&model.OptionGetPunishmentList{
|
||||||
|
Ids: req.Id,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
|
s.logger.Error("GetPunishmentList", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range data {
|
||||||
|
item.Enable = false
|
||||||
|
item.Operators = s.dbModel.MakePunishmentOperators(userCliams.UserId, 0, item.Operators)
|
||||||
|
err = s.dbModel.UpdatePunishment(&item, "enable", "operators")
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("UpdatePunishment", zap.Error(err))
|
||||||
|
return nil, status.Errorf(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &emptypb.Empty{}, nil
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
import service from '~/utils/request'
|
||||||
|
|
||||||
|
export const createPunishment = (data) => {
|
||||||
|
return service({
|
||||||
|
url: '/api/v1/punishment',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updatePunishment = (data) => {
|
||||||
|
return service({
|
||||||
|
url: '/api/v1/punishment',
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getPunishment = (params) => {
|
||||||
|
return service({
|
||||||
|
url: '/api/v1/punishment',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const listPunishment = (params) => {
|
||||||
|
return service({
|
||||||
|
url: '/api/v1/punishment/list',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消惩罚
|
||||||
|
export const cancelPunishment = (data) => {
|
||||||
|
return service({
|
||||||
|
url: '/api/v1/punishment/cancel',
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,243 @@
|
|||||||
|
<template>
|
||||||
|
<div class="com-form-punishment">
|
||||||
|
<el-form
|
||||||
|
ref="formPunishment"
|
||||||
|
label-position="top"
|
||||||
|
label-width="80px"
|
||||||
|
:model="punishment"
|
||||||
|
>
|
||||||
|
<el-form-item
|
||||||
|
label="用户"
|
||||||
|
prop="user_id"
|
||||||
|
:rules="
|
||||||
|
punishment.id === 0
|
||||||
|
? [{ required: true, trigger: 'blur', message: '请选择用户' }]
|
||||||
|
: []
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<el-select
|
||||||
|
v-if="punishment.id === 0"
|
||||||
|
v-model="punishment.user_id"
|
||||||
|
filterable
|
||||||
|
multiple
|
||||||
|
remote
|
||||||
|
reserve-keyword
|
||||||
|
placeholder="请输入和选择用户"
|
||||||
|
:remote-method="remoteSearchUser"
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="user in users"
|
||||||
|
:key="'userid' + user.id"
|
||||||
|
:label="user.username"
|
||||||
|
:value="user.id"
|
||||||
|
>
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-input v-else :disabled="true" v-model="punishment.username" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
prop="type"
|
||||||
|
:rules="[
|
||||||
|
{ required: true, trigger: 'blur', message: '请选择处罚类型' },
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<template slot="label">
|
||||||
|
处罚类型
|
||||||
|
<ToolTip
|
||||||
|
content="禁止评论:不允许发表评论;禁止上传:不允许上传文档;禁止收藏:不允许收藏;禁止下载:不允许下载文档;禁用账户:包括上述全部禁用项"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<el-checkbox-group v-if="punishment.id === 0" v-model="punishment.type">
|
||||||
|
<el-checkbox
|
||||||
|
v-for="item in punishmentTypeOptions"
|
||||||
|
:label="item.value"
|
||||||
|
:key="'checkbox-pt' + item.value"
|
||||||
|
>{{ item.label }}</el-checkbox
|
||||||
|
>
|
||||||
|
</el-checkbox-group>
|
||||||
|
<el-select v-else v-model="punishment.type" :disabled="true">
|
||||||
|
<el-option
|
||||||
|
v-for="item in punishmentTypeOptions"
|
||||||
|
:label="item.label"
|
||||||
|
:key="'select-pt-' + item.value"
|
||||||
|
:value="item.value"
|
||||||
|
>
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-row :gutter="20">
|
||||||
|
<el-col :span="8">
|
||||||
|
<el-form-item label="是否启用处罚">
|
||||||
|
<el-switch
|
||||||
|
v-model="punishment.enable"
|
||||||
|
style="display: block"
|
||||||
|
active-color="#13ce66"
|
||||||
|
inactive-color="#ff4949"
|
||||||
|
active-text="是"
|
||||||
|
inactive-text="否"
|
||||||
|
>
|
||||||
|
</el-switch> </el-form-item
|
||||||
|
></el-col>
|
||||||
|
<el-col :span="16">
|
||||||
|
<el-form-item>
|
||||||
|
<template slot="label">
|
||||||
|
截止时间
|
||||||
|
<ToolTip content="用户被处罚的截止时间,留空则为永久" />
|
||||||
|
</template>
|
||||||
|
<el-date-picker
|
||||||
|
v-model="punishment.end_time"
|
||||||
|
type="datetime"
|
||||||
|
placeholder="请选择处罚截止时间"
|
||||||
|
:picker-options="datetimePickerPunishmentOptions"
|
||||||
|
>
|
||||||
|
</el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<el-form-item label="处罚原因">
|
||||||
|
<el-input
|
||||||
|
type="textarea"
|
||||||
|
v-model="punishment.reason"
|
||||||
|
:rows="3"
|
||||||
|
placeholder="请输入处罚原因,被处罚用户可见"
|
||||||
|
></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="处罚备注">
|
||||||
|
<el-input
|
||||||
|
type="textarea"
|
||||||
|
v-model="punishment.remark"
|
||||||
|
:rows="3"
|
||||||
|
placeholder="请输入处罚备注,管理员可见"
|
||||||
|
></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
class="btn-block"
|
||||||
|
icon="el-icon-check"
|
||||||
|
:loading="loading"
|
||||||
|
@click="onSubmit"
|
||||||
|
>提交</el-button
|
||||||
|
>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { createPunishment, updatePunishment } from '~/api/punishment'
|
||||||
|
import {
|
||||||
|
punishmentTypeOptions,
|
||||||
|
datetimePickerPunishmentOptions,
|
||||||
|
} from '~/utils/enum'
|
||||||
|
import { listUser } from '~/api/user'
|
||||||
|
export default {
|
||||||
|
name: 'FormPunishment',
|
||||||
|
props: {
|
||||||
|
initPunishment: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
punishmentTypeOptions,
|
||||||
|
datetimePickerPunishmentOptions,
|
||||||
|
loading: false,
|
||||||
|
punishment: {
|
||||||
|
id: 0,
|
||||||
|
user_id: '',
|
||||||
|
remark: '',
|
||||||
|
reason: '',
|
||||||
|
type: [],
|
||||||
|
enable: true,
|
||||||
|
},
|
||||||
|
users: [],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
initPunishment: {
|
||||||
|
handler(val) {
|
||||||
|
let enable = val.enable || false
|
||||||
|
this.punishment = {
|
||||||
|
id: 0,
|
||||||
|
user_id: '',
|
||||||
|
remark: '',
|
||||||
|
reason: '',
|
||||||
|
type: [],
|
||||||
|
...val,
|
||||||
|
enable: enable,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// created() {
|
||||||
|
// this.punishment = { ...this.initPunishment }
|
||||||
|
// },
|
||||||
|
methods: {
|
||||||
|
onSubmit() {
|
||||||
|
this.$refs.formPunishment.validate(async (valid) => {
|
||||||
|
if (!valid) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.loading = true
|
||||||
|
const punishment = { ...this.punishment }
|
||||||
|
if (this.punishment.id > 0) {
|
||||||
|
delete punishment.operators
|
||||||
|
const res = await updatePunishment(punishment)
|
||||||
|
if (res.status === 200) {
|
||||||
|
this.$message.success('修改成功')
|
||||||
|
this.$emit('success', res.data)
|
||||||
|
} else {
|
||||||
|
this.$message.error(res.data.message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await createPunishment(punishment)
|
||||||
|
if (res.status === 200) {
|
||||||
|
this.$message.success('新增成功')
|
||||||
|
this.$emit('success', res.data)
|
||||||
|
} else {
|
||||||
|
this.$message.error(res.data.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async remoteSearchUser(wd) {
|
||||||
|
this.searchUser(wd)
|
||||||
|
},
|
||||||
|
async searchUser(wd, userId = []) {
|
||||||
|
const res = await listUser({
|
||||||
|
page: 1,
|
||||||
|
size: 10,
|
||||||
|
wd: wd,
|
||||||
|
id: userId || [],
|
||||||
|
field: ['id', 'username'],
|
||||||
|
})
|
||||||
|
if (res.status === 200) {
|
||||||
|
this.users = res.data.user || []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clearValidate() {
|
||||||
|
this.$refs.formPunishment.clearValidate()
|
||||||
|
},
|
||||||
|
resetFields() {
|
||||||
|
this.punishment = {
|
||||||
|
id: 0,
|
||||||
|
title: '',
|
||||||
|
link: '',
|
||||||
|
sort: 0,
|
||||||
|
enable: true,
|
||||||
|
description: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reset() {
|
||||||
|
this.resetFields()
|
||||||
|
this.clearValidate()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<el-tooltip class="item" effect="dark" :content="content" placement="top">
|
||||||
|
<el-button size="small" type="text" icon="el-icon-info"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'ToolTip',
|
||||||
|
props: {
|
||||||
|
content: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue