Skip to content

Commit

Permalink
Merge pull request #243 from seungkyua/20240221_change_project_leader
Browse files Browse the repository at this point in the history
20240221 change project leader
  • Loading branch information
seungkyua authored Feb 25, 2024
2 parents ef6e1fc + fbc46e5 commit fbd3bc3
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 72 deletions.
25 changes: 7 additions & 18 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/projects/check/existence": {
"/organizations/{organizationId}/projects/existence": {
"get": {
"security": [
{
Expand Down Expand Up @@ -2340,7 +2340,7 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/projects/pass/project-roles": {
"/organizations/{organizationId}/projects/project-roles": {
"get": {
"security": [
{
Expand Down Expand Up @@ -2383,7 +2383,7 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/projects/pass/project-roles/{projectRoleId}": {
"/organizations/{organizationId}/projects/project-roles/{projectRoleId}": {
"get": {
"security": [
{
Expand Down Expand Up @@ -3581,7 +3581,7 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/projects/{projectId}/members/project-roles/count": {
"/organizations/{organizationId}/projects/{projectId}/members/count": {
"get": {
"security": [
{
Expand Down Expand Up @@ -3817,13 +3817,6 @@ const docTemplate = `{
"name": "projectId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Project Stack ID",
"name": "stackId",
"in": "path",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -3867,13 +3860,6 @@ const docTemplate = `{
"in": "path",
"required": true
},
{
"type": "string",
"description": "Stack ID",
"name": "stackId",
"in": "path",
"required": true
},
{
"description": "Request body to create project namespace",
"name": "request",
Expand Down Expand Up @@ -8539,6 +8525,9 @@ const docTemplate = `{
},
"name": {
"type": "string"
},
"projectLeaderId": {
"type": "string"
}
}
},
Expand Down
25 changes: 7 additions & 18 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@
}
}
},
"/organizations/{organizationId}/projects/check/existence": {
"/organizations/{organizationId}/projects/existence": {
"get": {
"security": [
{
Expand Down Expand Up @@ -2334,7 +2334,7 @@
}
}
},
"/organizations/{organizationId}/projects/pass/project-roles": {
"/organizations/{organizationId}/projects/project-roles": {
"get": {
"security": [
{
Expand Down Expand Up @@ -2377,7 +2377,7 @@
}
}
},
"/organizations/{organizationId}/projects/pass/project-roles/{projectRoleId}": {
"/organizations/{organizationId}/projects/project-roles/{projectRoleId}": {
"get": {
"security": [
{
Expand Down Expand Up @@ -3575,7 +3575,7 @@
}
}
},
"/organizations/{organizationId}/projects/{projectId}/members/project-roles/count": {
"/organizations/{organizationId}/projects/{projectId}/members/count": {
"get": {
"security": [
{
Expand Down Expand Up @@ -3811,13 +3811,6 @@
"name": "projectId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Project Stack ID",
"name": "stackId",
"in": "path",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -3861,13 +3854,6 @@
"in": "path",
"required": true
},
{
"type": "string",
"description": "Stack ID",
"name": "stackId",
"in": "path",
"required": true
},
{
"description": "Request body to create project namespace",
"name": "request",
Expand Down Expand Up @@ -8533,6 +8519,9 @@
},
"name": {
"type": "string"
},
"projectLeaderId": {
"type": "string"
}
}
},
Expand Down
20 changes: 6 additions & 14 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,8 @@ definitions:
type: string
name:
type: string
projectLeaderId:
type: string
required:
- name
type: object
Expand Down Expand Up @@ -4694,7 +4696,7 @@ paths:
summary: Update project member Role
tags:
- Projects
/organizations/{organizationId}/projects/{projectId}/members/project-roles/count:
/organizations/{organizationId}/projects/{projectId}/members/count:
get:
consumes:
- application/json
Expand Down Expand Up @@ -4738,11 +4740,6 @@ paths:
name: projectId
required: true
type: string
- description: Project Stack ID
in: path
name: stackId
required: true
type: string
produces:
- application/json
responses:
Expand Down Expand Up @@ -4770,11 +4767,6 @@ paths:
name: projectId
required: true
type: string
- description: Stack ID
in: path
name: stackId
required: true
type: string
- description: Request body to create project namespace
in: body
name: request
Expand Down Expand Up @@ -4949,7 +4941,7 @@ paths:
summary: Check project namespace exist
tags:
- Projects
/organizations/{organizationId}/projects/check/existence:
/organizations/{organizationId}/projects/existence:
get:
consumes:
- application/json
Expand Down Expand Up @@ -4981,7 +4973,7 @@ paths:
summary: Check project name exist
tags:
- Projects
/organizations/{organizationId}/projects/pass/project-roles:
/organizations/{organizationId}/projects/project-roles:
get:
consumes:
- application/json
Expand Down Expand Up @@ -5009,7 +5001,7 @@ paths:
summary: Get project roles
tags:
- Projects
/organizations/{organizationId}/projects/pass/project-roles/{projectRoleId}:
/organizations/{organizationId}/projects/project-roles/{projectRoleId}:
get:
consumes:
- application/json
Expand Down
26 changes: 15 additions & 11 deletions internal/delivery/http/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (p ProjectHandler) GetProject(w http.ResponseWriter, r *http.Request) {
// @Param type query string false "type (name)"
// @Param value query string true "value (project name)"
// @Success 200 {object} domain.CheckExistedResponse
// @Router /organizations/{organizationId}/projects/check/existence [get]
// @Router /organizations/{organizationId}/projects/existence [get]
// @Security JWT
func (p ProjectHandler) IsProjectNameExist(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Expand Down Expand Up @@ -348,18 +348,24 @@ func (p ProjectHandler) UpdateProject(w http.ResponseWriter, r *http.Request) {
}

now := time.Now()
project, err := p.usecase.GetProject(organizationId, projectId)
project, err := p.usecase.GetProjectWithLeader(organizationId, projectId)
if err != nil {

ErrorJSON(w, r, err)
return
}
if project == nil {
project, err = p.usecase.GetProject(organizationId, projectId)
if err != nil {
ErrorJSON(w, r, err)
return
}
}

project.Name = projectReq.Name
project.Description = projectReq.Description
project.UpdatedAt = &now
//project.ProjectNamespaces = nil
//project.ProjectMembers = nil

if err := p.usecase.UpdateProject(project); err != nil {
if err := p.usecase.UpdateProject(project, projectReq.ProjectLeaderId); err != nil {
ErrorJSON(w, r, err)
return
}
Expand All @@ -380,7 +386,7 @@ func (p ProjectHandler) DeleteProject(w http.ResponseWriter, r *http.Request) {
// @Param organizationId path string true "Organization ID"
// @Param projectRoleId path string true "Project Role ID"
// @Success 200 {object} domain.GetProjectRoleResponse
// @Router /organizations/{organizationId}/projects/pass/project-roles/{projectRoleId} [get]
// @Router /organizations/{organizationId}/projects/project-roles/{projectRoleId} [get]
// @Security JWT
func (p ProjectHandler) GetProjectRole(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Expand Down Expand Up @@ -422,7 +428,7 @@ func (p ProjectHandler) GetProjectRole(w http.ResponseWriter, r *http.Request) {
// @Param organizationId path string true "Organization ID"
// @Param query query string false "project role search by query (query=all), (query=leader), (query=member), (query=viewer)"
// @Success 200 {object} domain.GetProjectRolesResponse
// @Router /organizations/{organizationId}/projects/pass/project-roles [get]
// @Router /organizations/{organizationId}/projects/project-roles [get]
// @Security JWT
func (p ProjectHandler) GetProjectRoles(w http.ResponseWriter, r *http.Request) {
urlParams := r.URL.Query()
Expand Down Expand Up @@ -692,7 +698,7 @@ func (p ProjectHandler) GetProjectMembers(w http.ResponseWriter, r *http.Request
// @Param organizationId path string true "Organization ID"
// @Param projectId path string true "Project ID"
// @Success 200 {object} domain.GetProjectMemberCountResponse
// @Router /organizations/{organizationId}/projects/{projectId}/members/project-roles/count [get]
// @Router /organizations/{organizationId}/projects/{projectId}/members/count [get]
// @Security JWT
func (p ProjectHandler) GetProjectMemberCount(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Expand Down Expand Up @@ -958,7 +964,6 @@ func (p ProjectHandler) UpdateProjectMembersRole(w http.ResponseWriter, r *http.
// @Produce json
// @Param organizationId path string true "Organization ID"
// @Param projectId path string true "Project ID"
// @Param stackId path string true "Stack ID"
// @Param request body domain.CreateProjectNamespaceRequest true "Request body to create project namespace"
// @Success 200 {object} domain.CommonProjectResponse
// @Router /organizations/{organizationId}/projects/{projectId}/namespaces [post]
Expand Down Expand Up @@ -1063,7 +1068,6 @@ func (p ProjectHandler) IsProjectNamespaceExist(w http.ResponseWriter, r *http.R
// @Produce json
// @Param organizationId path string true "Organization ID"
// @Param projectId path string true "Project ID"
// @Param stackId path string true "Project Stack ID"
// @Success 200 {object} domain.GetProjectNamespacesResponse
// @Router /organizations/{organizationId}/projects/{projectId}/namespaces [get]
// @Security JWT
Expand Down
24 changes: 23 additions & 1 deletion internal/repository/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type IProjectRepository interface {
GetProjectMembersByProjectIdAndRoleName(projectId string, memberRole string) ([]domain.ProjectMember, error)
GetProjectMemberCountByProjectId(projectId string) (*domain.GetProjectMemberCountResponse, error)
GetProjectMemberById(projectMemberId string) (*domain.ProjectMember, error)
GetProjectMemberByUserId(projectId string, projectUserId string) (pm *domain.ProjectMember, err error)
RemoveProjectMember(projectMemberId string) error
UpdateProjectMemberRole(pm *domain.ProjectMember) error
CreateProjectNamespace(organizationId string, pn *domain.ProjectNamespace) error
Expand Down Expand Up @@ -280,6 +281,22 @@ func (r *ProjectRepository) GetProjectMemberById(projectMemberId string) (pm *do
return pm, nil
}

func (r *ProjectRepository) GetProjectMemberByUserId(projectId string, projectUserId string) (pm *domain.ProjectMember, err error) {
res := r.db.Preload("ProjectUser").
Joins("ProjectRole").Where("project_id = ? and project_user_id = ?", projectId, projectUserId).First(&pm)
if res.Error != nil {
if errors.Is(res.Error, gorm.ErrRecordNotFound) {
log.Info("Cannot find project member")
return nil, nil
} else {
log.Error(res.Error)
return nil, res.Error
}
}

return pm, nil
}

func (r *ProjectRepository) RemoveProjectMember(projectMemberId string) error {
res := r.db.Delete(&domain.ProjectMember{ID: projectMemberId})
if res.Error != nil {
Expand All @@ -299,7 +316,12 @@ func (r *ProjectRepository) RemoveProjectMember(projectMemberId string) error {
//}

func (r *ProjectRepository) UpdateProjectMemberRole(pm *domain.ProjectMember) error {
res := r.db.Model(&pm).Updates(domain.ProjectMember{ProjectRoleId: pm.ProjectRoleId, UpdatedAt: pm.UpdatedAt})
res := r.db.Model(&pm).Updates(
domain.ProjectMember{
ProjectRoleId: pm.ProjectRoleId,
IsProjectLeader: pm.IsProjectLeader,
UpdatedAt: pm.UpdatedAt,
})
if res.Error != nil {
return res.Error
}
Expand Down
8 changes: 4 additions & 4 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,16 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
projectHandler := delivery.NewProjectHandler(usecaseFactory)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects", customMiddleware.Handle(internalApi.CreateProject, http.HandlerFunc(projectHandler.CreateProject))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects", customMiddleware.Handle(internalApi.GetProjects, http.HandlerFunc(projectHandler.GetProjects))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/project-roles", customMiddleware.Handle(internalApi.GetProjectRoles, http.HandlerFunc(projectHandler.GetProjectRoles))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/project-roles/{projectRoleId}", customMiddleware.Handle(internalApi.GetProjectRole, http.HandlerFunc(projectHandler.GetProjectRole))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/existence", customMiddleware.Handle(internalApi.GetProjectNamespace, http.HandlerFunc(projectHandler.IsProjectNameExist))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}", customMiddleware.Handle(internalApi.GetProject, http.HandlerFunc(projectHandler.GetProject))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/check/existence", customMiddleware.Handle(internalApi.GetProjectNamespace, http.HandlerFunc(projectHandler.IsProjectNameExist))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}", customMiddleware.Handle(internalApi.UpdateProject, http.HandlerFunc(projectHandler.UpdateProject))).Methods(http.MethodPut)
//r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}", customMiddleware.Handle(internalApi.DeleteProject, http.HandlerFunc(projectHandler.DeleteProject))).Methods(http.MethodDelete)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/pass/project-roles", customMiddleware.Handle(internalApi.GetProjectRoles, http.HandlerFunc(projectHandler.GetProjectRoles))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/pass/project-roles/{projectRoleId}", customMiddleware.Handle(internalApi.GetProjectRole, http.HandlerFunc(projectHandler.GetProjectRole))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members", customMiddleware.Handle(internalApi.AddProjectMember, http.HandlerFunc(projectHandler.AddProjectMember))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members/count", customMiddleware.Handle(internalApi.GetProjectMembers, http.HandlerFunc(projectHandler.GetProjectMemberCount))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members/{projectMemberId}", customMiddleware.Handle(internalApi.GetProjectMember, http.HandlerFunc(projectHandler.GetProjectMember))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members", customMiddleware.Handle(internalApi.GetProjectMembers, http.HandlerFunc(projectHandler.GetProjectMembers))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members/project-roles/count", customMiddleware.Handle(internalApi.GetProjectMembers, http.HandlerFunc(projectHandler.GetProjectMemberCount))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members/{projectMemberId}", customMiddleware.Handle(internalApi.RemoveProjectMember, http.HandlerFunc(projectHandler.RemoveProjectMember))).Methods(http.MethodDelete)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members", customMiddleware.Handle(internalApi.RemoveProjectMember, http.HandlerFunc(projectHandler.RemoveProjectMembers))).Methods(http.MethodDelete)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/members", customMiddleware.Handle(internalApi.UpdateProjectMemberRole, http.HandlerFunc(projectHandler.UpdateProjectMembersRole))).Methods(http.MethodPut)
Expand Down
Loading

0 comments on commit fbd3bc3

Please sign in to comment.