Add attendance_list in service_event, add set user permission in user
update Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
201
service/service_event/attendance_list.go
Normal file
201
service/service_event/attendance_list.go
Normal file
@@ -0,0 +1,201 @@
|
||||
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
|
||||
}
|
||||
@@ -31,7 +31,7 @@ type CheckinResult struct {
|
||||
|
||||
func (self *EventServiceImpl) Checkin(payload *CheckinPayload) (result *CheckinResult) {
|
||||
attendandeData, err := new(data.Attendance).
|
||||
GetAttendanceByEventIdAndUserId(payload.Context, payload.Data.EventId, payload.UserId)
|
||||
GetAttendance(payload.Context, payload.Data.EventId, payload.UserId)
|
||||
if err != nil {
|
||||
result = &CheckinResult{
|
||||
Common: shared.CommonResult{
|
||||
|
||||
@@ -117,7 +117,7 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
|
||||
return
|
||||
}
|
||||
|
||||
attendenceSearch, err := new(data.Attendance).GetAttendanceByEventIdAndUserId(payload.Context, eventId, userId)
|
||||
attendenceSearch, err := new(data.Attendance).GetAttendance(payload.Context, eventId, userId)
|
||||
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return &EventJoinResult{
|
||||
|
||||
@@ -7,6 +7,7 @@ type EventService interface {
|
||||
GetEventInfo(*EventInfoPayload) *EventInfoResult
|
||||
ListEvents(*EventListPayload) *EventListResult
|
||||
JoinEvent(*EventJoinPayload) *EventJoinResult
|
||||
AttendanceList(*AttendanceListPayload) *AttendanceListResult
|
||||
}
|
||||
|
||||
type EventServiceImpl struct{}
|
||||
|
||||
Reference in New Issue
Block a user