This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Forums CRUD #27
Open
tan-yun-e
wants to merge
19
commits into
main
Choose a base branch
from
Yun-E
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c82a198
feat: forums wip
tan-yun-e 2f89e87
feat: forums errors
tan-yun-e cf1088e
feat: forums usecase
tan-yun-e f016f4f
feat: forums repo and httphandler
tan-yun-e c456a60
feat: forum httphandler
tan-yun-e f4344a0
feat: forums usecase
tan-yun-e 46670ad
fix: payload forum
tan-yun-e 8c2924e
Update internal/payload/forum.go
tan-yun-e b11a072
feat: edits
tan-yun-e ef53933
feat: more edits
tan-yun-e a0bfaa9
feat: remove forum roles
tan-yun-e 512df91
feat: more edits
tan-yun-e 2ad92e0
feat: rename
tan-yun-e 70f06c1
feat: rename
tan-yun-e ee553f9
fix: logic
tan-yun-e 95d5122
feat: security rbac pkg
qin-guan 65a590d
rename: forumShortName
tan-yun-e 9cb9417
feat: more edits
tan-yun-e 2e5687b
feat: remove forum post files
tan-yun-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package forumpost | ||
|
||
import "errors" | ||
|
||
type Role string | ||
|
||
func (Role) Values() (kinds []string) { | ||
for _, s := range Roles { | ||
kinds = append(kinds, string(s)) | ||
} | ||
return | ||
} | ||
|
||
func (fr Role) Validate() error { | ||
switch fr { | ||
case RoleOwner, RoleEducator, RoleMember: | ||
return nil | ||
default: | ||
return errors.New("group role is not valid") | ||
} | ||
} | ||
|
||
var ( | ||
Roles = []Role{RoleOwner, RoleEducator, RoleMember} | ||
|
||
RoleOwner Role = "owner" | ||
RoleEducator Role = "educator" | ||
RoleMember Role = "member" | ||
) | ||
|
||
type Options struct { | ||
Title string | ||
Content string | ||
} | ||
|
||
type Option func(*Options) | ||
|
||
func Name(n string) Option { | ||
return func(opts *Options) { | ||
opts.Title = n | ||
} | ||
} | ||
|
||
func ShortName(n string) Option { | ||
return func(opts *Options) { | ||
opts.Content = n | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package forumpost | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/np-inprove/server/internal/entity" | ||
"github.com/np-inprove/server/internal/entity/forumpost" | ||
) | ||
|
||
type Reader interface { | ||
FindForumPostsByUser() ([]*entity.ForumPost, error) | ||
FindForumPost() (*entity.ForumPost, error) | ||
|
||
FindGroupUser(ctx context.Context, principal, shortName string) (*entity.GroupUser, error) | ||
} | ||
|
||
type Writer interface { | ||
CreateForumPost(ctx context.Context, forumID int, opts ...forumpost.Option) (*entity.ForumPost, error) | ||
} | ||
|
||
type Repository interface { | ||
Reader | ||
Writer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package payload | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gookit/validate" | ||
) | ||
|
||
type ForumPost struct { | ||
ID int `json:"id,omitempty"` | ||
Title string `json:"title,omitempty"` | ||
Content string `json:"content,omitempty"` | ||
TimeDate string `json:"description,omitempty"` | ||
} | ||
|
||
func (fp ForumPost) Render(_ http.ResponseWriter, _ *http.Request) error { | ||
return nil | ||
} | ||
|
||
type CreateForumPostRequest struct { | ||
Name string `json:"name,omitempty" validate:"required|minLen:3"` | ||
ShortName string `json:"shortName,omitempty" validate:"required|alphaDash"` | ||
Description string `json:"description,omitempty"` | ||
} | ||
|
||
func (c CreateForumPostRequest) Validate() *validate.Validation { | ||
return validate.Struct(c) | ||
} | ||
|
||
type UpdateForumPostRequest struct { | ||
Name string `json:"name,omitempty" validate:"required|minLen:3"` | ||
ShortName string `json:"shortName,omitempty" validate:"required|alphaDash"` | ||
Description string `json:"description,omitempty"` | ||
} | ||
|
||
func (u UpdateForumPostRequest) Validate() *validate.Validation { | ||
return validate.Struct(u) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP did not mean to stage files on forumpost