202 lines
5.3 KiB
Go
202 lines
5.3 KiB
Go
package service_event
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"nixcn-cms/data"
|
|
"nixcn-cms/internal/cryptography"
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/internal/kyc"
|
|
"nixcn-cms/service/service_user"
|
|
"nixcn-cms/service/shared"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type AttendanceListData struct {
|
|
EventId uuid.UUID `json:"event_id" form:"event_id"`
|
|
}
|
|
|
|
type AttendanceListPayload struct {
|
|
Context context.Context
|
|
Data *AttendanceListData
|
|
}
|
|
|
|
type AttendanceListResponse struct {
|
|
AttendanceId string `json:"attendance_id"`
|
|
UserInfo service_user.UserInfoData `json:"user_info"`
|
|
KycType string `json:"kyc_type"`
|
|
KycInfo any `json:"kyc_info"`
|
|
}
|
|
|
|
type AttendanceListResult struct {
|
|
Common shared.CommonResult
|
|
Data []AttendanceListResponse
|
|
}
|
|
|
|
func (self *EventServiceImpl) AttendanceList(payload *AttendanceListPayload) (result *AttendanceListResult) {
|
|
attList, err := new(data.Attendance).GetAttendanceListByEventId(payload.Context, payload.Data.EventId)
|
|
|
|
if err != nil {
|
|
exc := new(exception.Builder).
|
|
SetStatus(exception.StatusUser).
|
|
SetService(exception.ServiceEvent).
|
|
SetEndpoint(exception.EndpointEventServiceAttendanceList).
|
|
SetType(exception.TypeSpecific).
|
|
SetOriginal(exception.EventAttendanceListError).
|
|
SetError(err).
|
|
Throw(payload.Context)
|
|
|
|
result = &AttendanceListResult{
|
|
Common: shared.CommonResult{
|
|
HttpCode: 500,
|
|
Exception: exc,
|
|
},
|
|
}
|
|
return
|
|
}
|
|
|
|
responseList := make([]AttendanceListResponse, 0)
|
|
kycRepo := new(data.Kyc)
|
|
userRepo := new(data.User)
|
|
|
|
for _, item := range *attList {
|
|
var userInfo service_user.UserInfoData
|
|
var kycType string
|
|
var kycInfo any
|
|
|
|
userData, err := userRepo.GetByUserId(payload.Context, &item.UserId)
|
|
if err != nil {
|
|
exc := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceEvent).
|
|
SetEndpoint(exception.EndpointEventServiceAttendanceList).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorDatabase).
|
|
SetError(err).
|
|
Throw(payload.Context)
|
|
|
|
result = &AttendanceListResult{
|
|
Common: shared.CommonResult{
|
|
HttpCode: 500,
|
|
Exception: exc,
|
|
},
|
|
}
|
|
return
|
|
}
|
|
|
|
if userData != nil {
|
|
userInfo = service_user.UserInfoData{
|
|
UserId: userData.UserId,
|
|
Email: userData.Email,
|
|
Username: &userData.Username,
|
|
Nickname: &userData.Nickname,
|
|
Subtitle: &userData.Subtitle,
|
|
Avatar: &userData.Avatar,
|
|
Bio: &userData.Bio,
|
|
PermissionLevel: &userData.PermissionLevel,
|
|
AllowPublic: &userData.AllowPublic,
|
|
}
|
|
}
|
|
|
|
if item.KycId != uuid.Nil {
|
|
kycData, err := kycRepo.GetByKycId(payload.Context, &item.KycId)
|
|
|
|
if err == nil && kycData != nil {
|
|
kycType = kycData.Type
|
|
|
|
// AES Decrypt
|
|
decodedKycInfo, err := cryptography.AESCBCDecrypt(string(kycData.KycInfo), []byte(viper.GetString("secrets.kyc_info_key")))
|
|
if err != nil {
|
|
exc := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceEvent).
|
|
SetEndpoint(exception.EndpointEventServiceAttendanceList).
|
|
SetType(exception.TypeSpecific).
|
|
SetOriginal(exception.EventAttendanceKycInfoDecryptFailed).
|
|
SetError(err).
|
|
Throw(payload.Context)
|
|
|
|
result = &AttendanceListResult{
|
|
Common: shared.CommonResult{HttpCode: 500, Exception: exc},
|
|
}
|
|
return
|
|
}
|
|
|
|
// JSON Unmarshal
|
|
switch kycType {
|
|
case "cnrid":
|
|
var kycDetail kyc.CNRidInfo
|
|
if err := json.Unmarshal(decodedKycInfo, &kycDetail); err != nil {
|
|
exc := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceEvent).
|
|
SetEndpoint(exception.EndpointEventServiceAttendanceList).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorJsonDecodeFailed).
|
|
SetError(err).
|
|
Throw(payload.Context)
|
|
|
|
result = &AttendanceListResult{
|
|
Common: shared.CommonResult{
|
|
HttpCode: 500,
|
|
Exception: exc,
|
|
},
|
|
}
|
|
return
|
|
}
|
|
kycInfo = kycDetail
|
|
|
|
case "passport":
|
|
var kycDetail kyc.PassportResp
|
|
if err := json.Unmarshal(decodedKycInfo, &kycDetail); err != nil {
|
|
exc := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceEvent).
|
|
SetEndpoint(exception.EndpointEventServiceAttendanceList).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorJsonDecodeFailed).
|
|
SetError(err).
|
|
Throw(payload.Context)
|
|
|
|
result = &AttendanceListResult{
|
|
Common: shared.CommonResult{
|
|
HttpCode: 500,
|
|
Exception: exc,
|
|
},
|
|
}
|
|
return
|
|
}
|
|
kycInfo = kycDetail
|
|
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
|
|
responseList = append(responseList, AttendanceListResponse{
|
|
AttendanceId: item.AttendanceId.String(),
|
|
UserInfo: userInfo,
|
|
KycType: kycType,
|
|
KycInfo: kycInfo,
|
|
})
|
|
}
|
|
|
|
result = &AttendanceListResult{
|
|
Common: shared.CommonResult{
|
|
HttpCode: 200,
|
|
Exception: new(exception.Builder).
|
|
SetStatus(exception.StatusSuccess).
|
|
SetService(exception.ServiceEvent).
|
|
SetEndpoint(exception.EndpointEventServiceList).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonSuccess).
|
|
Throw(payload.Context),
|
|
},
|
|
Data: responseList,
|
|
}
|
|
|
|
return
|
|
}
|