Module project, commit, submission
All checks were successful
Build and Release / release (push) Successful in 1m15s
All checks were successful
Build and Release / release (push) Successful in 1m15s
This commit is contained in:
48
internal/models/commit.go
Normal file
48
internal/models/commit.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"history-api/internal/dtos/response"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CommitEntity struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
SnapshotJson json.RawMessage `json:"snapshot_json"`
|
||||
SnapshotHash string `json:"snapshot_hash"`
|
||||
UserID string `json:"user_id"`
|
||||
EditSummary string `json:"edit_summary"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
User *UserSimpleEntity `json:"user"`
|
||||
}
|
||||
|
||||
func (c *CommitEntity) ToResponse() *response.CommitResponse {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
var userRes *response.UserSimpleResponse
|
||||
if c.User != nil {
|
||||
userRes = c.User.ToResponse()
|
||||
}
|
||||
|
||||
return &response.CommitResponse{
|
||||
ID: c.ID,
|
||||
ProjectID: c.ProjectID,
|
||||
SnapshotJson: c.SnapshotJson,
|
||||
SnapshotHash: c.SnapshotHash,
|
||||
UserID: c.UserID,
|
||||
EditSummary: c.EditSummary,
|
||||
CreatedAt: c.CreatedAt,
|
||||
User: userRes,
|
||||
}
|
||||
}
|
||||
|
||||
func CommitsEntityToResponse(entities []*CommitEntity) []*response.CommitResponse {
|
||||
res := make([]*response.CommitResponse, 0, len(entities))
|
||||
for _, e := range entities {
|
||||
res = append(res, e.ToResponse())
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -7,21 +7,33 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type CommitSimple struct {
|
||||
ID string `json:"id"`
|
||||
EditSummary string `json:"edit_summary"`
|
||||
}
|
||||
|
||||
type MemberSimple struct {
|
||||
UserID string `json:"user_id"`
|
||||
Role constants.ProjectMemberRole `json:"role"`
|
||||
DisplayName string `json:"display_name"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
type ProjectEntity struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
LatestRevisionID *string `json:"latest_revision_id"`
|
||||
VersionCount int32 `json:"version_count"`
|
||||
ProjectStatus constants.ProjectStatusType `json:"project_status"`
|
||||
LockedBy *string `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID string `json:"user_id"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
User *UserSimpleEntity `json:"user"`
|
||||
CommitIds []string `json:"commit_ids"`
|
||||
SubmissionIds []string `json:"submission_ids"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
LatestCommitID *string `json:"latest_commit_id"`
|
||||
ProjectStatus constants.ProjectStatusType `json:"project_status"`
|
||||
LockedBy *string `json:"locked_by"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
UserID string `json:"user_id"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
User *UserSimpleEntity `json:"user"`
|
||||
Commits []CommitSimple `json:"commits"`
|
||||
SubmissionIds []string `json:"submission_ids"`
|
||||
Members []MemberSimple `json:"members"`
|
||||
}
|
||||
|
||||
func (p *ProjectEntity) ParseUser(data []byte) error {
|
||||
@@ -32,6 +44,22 @@ func (p *ProjectEntity) ParseUser(data []byte) error {
|
||||
return json.Unmarshal(data, &p.User)
|
||||
}
|
||||
|
||||
func (p *ProjectEntity) ParseCommits(data []byte) error {
|
||||
if len(data) == 0 || string(data) == "null" || string(data) == "[]" {
|
||||
p.Commits = []CommitSimple{}
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(data, &p.Commits)
|
||||
}
|
||||
|
||||
func (p *ProjectEntity) ParseMembers(data []byte) error {
|
||||
if len(data) == 0 || string(data) == "null" || string(data) == "[]" {
|
||||
p.Members = []MemberSimple{}
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(data, &p.Members)
|
||||
}
|
||||
|
||||
func (p *ProjectEntity) ToResponse() *response.ProjectResponse {
|
||||
if p == nil {
|
||||
return nil
|
||||
@@ -41,21 +69,39 @@ func (p *ProjectEntity) ToResponse() *response.ProjectResponse {
|
||||
userResponse = p.User.ToResponse()
|
||||
}
|
||||
|
||||
commits := make([]response.CommitSimpleResponse, 0, len(p.Commits))
|
||||
for _, c := range p.Commits {
|
||||
commits = append(commits, response.CommitSimpleResponse{
|
||||
ID: c.ID,
|
||||
EditSummary: c.EditSummary,
|
||||
})
|
||||
}
|
||||
|
||||
members := make([]response.MemberSimpleResponse, 0, len(p.Members))
|
||||
for _, m := range p.Members {
|
||||
members = append(members, response.MemberSimpleResponse{
|
||||
UserID: m.UserID,
|
||||
Role: m.Role.String(),
|
||||
DisplayName: m.DisplayName,
|
||||
AvatarUrl: m.AvatarUrl,
|
||||
})
|
||||
}
|
||||
|
||||
return &response.ProjectResponse{
|
||||
ID: p.ID,
|
||||
Title: p.Title,
|
||||
Description: p.Description,
|
||||
LatestRevisionID: p.LatestRevisionID,
|
||||
VersionCount: p.VersionCount,
|
||||
ProjectStatus: p.ProjectStatus.String(),
|
||||
LockedBy: p.LockedBy,
|
||||
IsDeleted: p.IsDeleted,
|
||||
UserID: p.UserID,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
User: userResponse,
|
||||
CommitIds: p.CommitIds,
|
||||
SubmissionIds: p.SubmissionIds,
|
||||
ID: p.ID,
|
||||
Title: p.Title,
|
||||
Description: p.Description,
|
||||
LatestCommitID: p.LatestCommitID,
|
||||
ProjectStatus: p.ProjectStatus.String(),
|
||||
LockedBy: p.LockedBy,
|
||||
IsDeleted: p.IsDeleted,
|
||||
UserID: p.UserID,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
User: userResponse,
|
||||
Commits: commits,
|
||||
SubmissionIds: p.SubmissionIds,
|
||||
Members: members,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
75
internal/models/submission.go
Normal file
75
internal/models/submission.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"history-api/internal/dtos/response"
|
||||
"history-api/pkg/constants"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SubmissionEntity struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
CommitID string `json:"commit_id"`
|
||||
UserID string `json:"user_id"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
Status constants.StatusType `json:"status"`
|
||||
ReviewedBy *string `json:"reviewed_by"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
ReviewNote *string `json:"review_note"`
|
||||
Content *string `json:"content"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
User *UserSimpleEntity `json:"user"`
|
||||
Reviewer *UserSimpleEntity `json:"reviewer"`
|
||||
}
|
||||
|
||||
func (s *SubmissionEntity) ParseUser(data []byte) error {
|
||||
if len(data) == 0 || string(data) == "null" {
|
||||
s.User = nil
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(data, &s.User)
|
||||
}
|
||||
|
||||
func (s *SubmissionEntity) ParseReviewer(data []byte) error {
|
||||
if len(data) == 0 || string(data) == "null" {
|
||||
s.Reviewer = nil
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(data, &s.Reviewer)
|
||||
}
|
||||
|
||||
func (s *SubmissionEntity) ToResponse() *response.SubmissionResponse {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &response.SubmissionResponse{
|
||||
ID: s.ID,
|
||||
ProjectID: s.ProjectID,
|
||||
CommitID: s.CommitID,
|
||||
UserID: s.UserID,
|
||||
CreatedAt: s.CreatedAt,
|
||||
Status: s.Status.String(),
|
||||
ReviewedBy: s.ReviewedBy,
|
||||
ReviewedAt: s.ReviewedAt,
|
||||
ReviewNote: s.ReviewNote,
|
||||
Content: s.Content,
|
||||
User: s.User.ToResponse(),
|
||||
Reviewer: s.Reviewer.ToResponse(),
|
||||
}
|
||||
}
|
||||
|
||||
func SubmissionsEntityToResponse(submissions []*SubmissionEntity) []*response.SubmissionResponse {
|
||||
out := make([]*response.SubmissionResponse, 0)
|
||||
if submissions == nil {
|
||||
return out
|
||||
}
|
||||
for _, submission := range submissions {
|
||||
if submission == nil {
|
||||
continue
|
||||
}
|
||||
out = append(out, submission.ToResponse())
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user