diff --git a/services/f3/driver/common.go b/services/f3/driver/common.go index 9eedda858e..95ae80094c 100644 --- a/services/f3/driver/common.go +++ b/services/f3/driver/common.go @@ -22,8 +22,23 @@ func (o *common) ListPage(ctx context.Context, page int) generic.ChildrenSlice { return generic.NewChildrenSlice(0) } +func (o *common) GetNativeID() string { + return "" +} + +func (o *common) SetNative(native any) { +} + +func (o *common) getPageSize() int { + return o.getTreeDriver().GetPageSize() +} + func (o *common) getKind() generic.Kind { return o.GetNode().GetKind() } +func (o *common) getTreeDriver() *treeDriver { + return o.GetTreeDriver().(*treeDriver) +} + func (o *common) IsNull() bool { return false } diff --git a/services/f3/driver/tree.go b/services/f3/driver/tree.go index 1532d4d261..4800d5a4a1 100644 --- a/services/f3/driver/tree.go +++ b/services/f3/driver/tree.go @@ -26,14 +26,66 @@ func (o *treeDriver) Init() { func (o *treeDriver) Factory(ctx context.Context, kind generic.Kind) generic.NodeDriverInterface { switch kind { - case f3_tree.KindUsers: - return newUsers() - case f3_tree.KindOrganizations: - return newOrganizations() - case f3_tree.KindTopics: - return newTopics() case f3_tree.KindForge: return newForge() + case f3_tree.KindOrganizations: + return newOrganizations() + // case f3_tree.KindOrganization: + // return newOrganization() + case f3_tree.KindUsers: + return newUsers() + case f3_tree.KindUser: + return newUser() + case f3_tree.KindProjects: + return newProjects() + // case f3_tree.KindProject: + // return newProject() + // case f3_tree.KindIssues: + // return newIssues() + // case f3_tree.KindIssue: + // return newIssue() + // case f3_tree.KindComments: + // return newComments() + // case f3_tree.KindComment: + // return newComment() + // case f3_tree.KindAssets: + // return newAssets() + // case f3_tree.KindAsset: + // return newAsset() + // case f3_tree.KindLabels: + // return newLabels() + // case f3_tree.KindLabel: + // return newLabel() + // case f3_tree.KindReactions: + // return newReactions() + // case f3_tree.KindReaction: + // return newReaction() + // case f3_tree.KindReviews: + // return newReviews() + // case f3_tree.KindReview: + // return newReview() + // case f3_tree.KindReviewComments: + // return newReviewComments() + // case f3_tree.KindReviewComment: + // return newReviewComment() + // case f3_tree.KindMilestones: + // return newMilestones() + // case f3_tree.KindMilestone: + // return newMilestone() + // case f3_tree.KindPullRequests: + // return newPullRequests() + // case f3_tree.KindPullRequest: + // return newPullRequest() + // case f3_tree.KindReleases: + // return newReleases() + // case f3_tree.KindRelease: + // return newRelease() + case f3_tree.KindTopics: + return newTopics() + // case f3_tree.KindRepositories: + // return newRepositories() + // case f3_tree.KindRepository: + // return newRepository(ctx) case generic.KindRoot: return newRoot(o.GetTree().(f3_tree.TreeInterface).NewFormat(kind)) default: diff --git a/services/f3/driver/user.go b/services/f3/driver/user.go new file mode 100644 index 0000000000..e7fefcdfd3 --- /dev/null +++ b/services/f3/driver/user.go @@ -0,0 +1,17 @@ +// Copyright Earl Warren +// Copyright Loïc Dachary +// SPDX-License-Identifier: MIT + +package driver + +import ( + "lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic" +) + +type user struct { + common +} + +func newUser() generic.NodeDriverInterface { + return &user{} +} diff --git a/services/f3/driver/users.go b/services/f3/driver/users.go index 71223ac04a..222b428181 100644 --- a/services/f3/driver/users.go +++ b/services/f3/driver/users.go @@ -5,6 +5,13 @@ package driver import ( + "context" + "fmt" + + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" + + f3_tree "lab.forgefriends.org/friendlyforgeformat/gof3/tree/f3" "lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic" ) @@ -12,6 +19,30 @@ type users struct { container } +func (o *users) ListPage(ctx context.Context, page int) generic.ChildrenSlice { + sess := db.GetEngine(ctx).In("type", user_model.UserTypeIndividual, user_model.UserTypeF3) + if page != 0 { + sess = db.SetSessionPagination(sess, &db.ListOptions{Page: page, PageSize: o.getPageSize()}) + } + sess = sess.Select("`user`.*") + users := make([]*user_model.User, 0, o.getPageSize()) + + if err := sess.Find(&users); err != nil { + panic(fmt.Errorf("error while listing users: %v", err)) + } + + return f3_tree.ConvertListed(ctx, o.GetNode(), f3_tree.ConvertToAny(users...)...) +} + +func (o *users) GetIDFromName(ctx context.Context, name string) generic.NodeID { + user, err := user_model.GetUserByName(ctx, name) + if err != nil { + panic(fmt.Errorf("GetUserByName: %v", err)) + } + + return generic.NodeID(fmt.Sprintf("%d", user.ID)) +} + func newUsers() generic.NodeDriverInterface { return &users{} }