Remove search engine, add event list api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -10,27 +10,27 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type InfoData struct {
|
||||
type EventInfoData struct {
|
||||
EventId uuid.UUID `json:"event_id"`
|
||||
}
|
||||
|
||||
type InfoPayload struct {
|
||||
type EventInfoPayload struct {
|
||||
Context context.Context
|
||||
Data *InfoData
|
||||
Data *EventInfoData
|
||||
}
|
||||
|
||||
type InfoResponse struct {
|
||||
type EventInfoResponse struct {
|
||||
Name string `json:"name"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
EndTime time.Time `json:"end_time"`
|
||||
}
|
||||
|
||||
type InfoResult struct {
|
||||
type EventInfoResult struct {
|
||||
Common shared.CommonResult
|
||||
Data *InfoResponse
|
||||
Data *EventInfoResponse
|
||||
}
|
||||
|
||||
func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
|
||||
func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *EventInfoResult) {
|
||||
event, err := new(data.Event).GetEventById(payload.Context, payload.Data.EventId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
@@ -42,7 +42,7 @@ func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &InfoResult{
|
||||
result = &EventInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 404,
|
||||
Exception: exception,
|
||||
@@ -52,7 +52,7 @@ func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
|
||||
return
|
||||
}
|
||||
|
||||
result = &InfoResult{
|
||||
result = &EventInfoResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: new(exception.Builder).
|
||||
@@ -63,7 +63,7 @@ func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
Throw(payload.Context),
|
||||
},
|
||||
Data: &InfoResponse{
|
||||
Data: &EventInfoResponse{
|
||||
Name: event.Name,
|
||||
StartTime: event.StartTime,
|
||||
EndTime: event.EndTime,
|
||||
131
service/service_event/list_events.go
Normal file
131
service/service_event/list_events.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package service_event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/shared"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type EventListPayload struct {
|
||||
Context context.Context
|
||||
Limit *string
|
||||
Offset *string
|
||||
}
|
||||
|
||||
type EventListResult struct {
|
||||
Common shared.CommonResult
|
||||
Data *[]data.EventIndexDoc `json:"event_list"`
|
||||
}
|
||||
|
||||
func (self *EventServiceImpl) ListEvents(payload *EventListPayload) (result *EventListResult) {
|
||||
var limit string
|
||||
if payload.Limit == nil || *payload.Limit == "" {
|
||||
limit = "20"
|
||||
} else {
|
||||
limit = *payload.Limit
|
||||
}
|
||||
|
||||
var offset string
|
||||
if payload.Offset == nil || *payload.Offset == "" {
|
||||
exc := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
return &EventListResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exc,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
} else {
|
||||
offset = *payload.Offset
|
||||
}
|
||||
|
||||
limitNum, err := strconv.Atoi(limit)
|
||||
if err != nil {
|
||||
exc := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
return &EventListResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exc,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
offsetNum, err := strconv.Atoi(offset)
|
||||
if err != nil {
|
||||
exc := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
return &EventListResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exc,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
eventList, err := new(data.Event).
|
||||
FastListEvents(payload.Context, int64(limitNum), int64(offsetNum))
|
||||
if err != nil {
|
||||
exc := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.EventListDatabaseFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
return &EventListResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exc,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
successExc := new(exception.Builder).
|
||||
SetStatus(exception.StatusSuccess).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventListResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: successExc,
|
||||
},
|
||||
Data: eventList,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -4,7 +4,8 @@ type EventService interface {
|
||||
Checkin(*CheckinPayload) *CheckinResult
|
||||
CheckinSubmit(*CheckinSubmitPayload) *CheckinSubmitResult
|
||||
CheckinQuery(*CheckinQueryPayload) *CheckinQueryResult
|
||||
Info(*InfoPayload) *InfoResult
|
||||
GetEventInfo(*EventInfoPayload) *EventInfoResult
|
||||
ListEvents(*EventListPayload) *EventListResult
|
||||
}
|
||||
|
||||
type EventServiceImpl struct{}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package service_user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/shared"
|
||||
)
|
||||
|
||||
type UserTablePayload struct {
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
type UserTableResponse struct {
|
||||
UserTable *[]data.User `json:"user_table"`
|
||||
}
|
||||
|
||||
type UserTableResult struct {
|
||||
Common shared.CommonResult
|
||||
Data *UserTableResponse
|
||||
}
|
||||
|
||||
// ListUserFullTable
|
||||
func (self *UserServiceImpl) GetUserFullTable(payload *UserTablePayload) (result *UserTableResult) {
|
||||
var err error
|
||||
|
||||
userFullTable, err := new(data.User).
|
||||
GetFullTable(payload.Context)
|
||||
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceFull).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &UserTableResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceFull).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &UserTableResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: &UserTableResponse{userFullTable},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -16,16 +16,18 @@ type UserListPayload struct {
|
||||
|
||||
type UserListResult struct {
|
||||
Common shared.CommonResult
|
||||
Data *[]data.UserSearchDoc `json:"user_list"`
|
||||
Data *[]data.UserIndexDoc `json:"user_list"`
|
||||
}
|
||||
|
||||
func (self *UserServiceImpl) ListUsers(payload *UserListPayload) (result *UserListResult) {
|
||||
var limit string
|
||||
var limit string = *payload.Limit
|
||||
if payload.Limit == nil || *payload.Limit == "" {
|
||||
limit = "0"
|
||||
limit = "20"
|
||||
} else {
|
||||
limit = *payload.Limit
|
||||
}
|
||||
|
||||
var offset string
|
||||
var offset string = *payload.Offset
|
||||
if payload.Offset == nil || *payload.Offset == "" {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
@@ -50,7 +52,7 @@ func (self *UserServiceImpl) ListUsers(payload *UserListPayload) (result *UserLi
|
||||
}
|
||||
|
||||
// Parse string to int64
|
||||
limitNum, err := strconv.ParseInt(limit, 10, 64)
|
||||
limitNum, err := strconv.Atoi(limit)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
@@ -72,7 +74,7 @@ func (self *UserServiceImpl) ListUsers(payload *UserListPayload) (result *UserLi
|
||||
return
|
||||
}
|
||||
|
||||
offsetNum, err := strconv.ParseInt(offset, 10, 64)
|
||||
offsetNum, err := strconv.Atoi(offset)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
@@ -103,7 +105,7 @@ func (self *UserServiceImpl) ListUsers(payload *UserListPayload) (result *UserLi
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceList).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.UserListMeilisearchFailed).
|
||||
SetOriginal(exception.UserListDatabaseFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ type UserService interface {
|
||||
GetUserInfo(*UserInfoPayload) *UserInfoResult
|
||||
UpdateUserInfo(*UserInfoPayload) *UserInfoResult
|
||||
ListUsers(*UserListPayload) *UserListResult
|
||||
GetUserFullTable(*UserTablePayload) *UserTableResult
|
||||
CreateUser()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user