mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
pb "lunar-tear/server/gen/proto"
|
||||
"lunar-tear/server/internal/store"
|
||||
"lunar-tear/server/internal/userdata"
|
||||
)
|
||||
|
||||
type DokanServiceServer struct {
|
||||
pb.UnimplementedDokanServiceServer
|
||||
users store.UserRepository
|
||||
sessions store.SessionRepository
|
||||
}
|
||||
|
||||
func NewDokanServiceServer(users store.UserRepository, sessions store.SessionRepository) *DokanServiceServer {
|
||||
return &DokanServiceServer{users: users, sessions: sessions}
|
||||
}
|
||||
|
||||
func (s *DokanServiceServer) RegisterDokanConfirmed(ctx context.Context, req *pb.RegisterDokanConfirmedRequest) (*pb.RegisterDokanConfirmedResponse, error) {
|
||||
log.Printf("[DokanService] RegisterDokanConfirmed: dokanIds=%v", req.DokanId)
|
||||
|
||||
userId := currentUserId(ctx, s.users, s.sessions)
|
||||
snapshot, err := s.users.UpdateUser(userId, func(user *store.UserState) {
|
||||
for _, id := range req.DokanId {
|
||||
user.DokanConfirmed[id] = true
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("update user: %w", err)
|
||||
}
|
||||
|
||||
tables := userdata.FullClientTableMap(snapshot)
|
||||
diff := userdata.BuildDiffFromTables(userdata.SelectTables(tables, []string{"IUserDokan"}))
|
||||
|
||||
return &pb.RegisterDokanConfirmedResponse{
|
||||
DiffUserData: diff,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user