Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(console): owner and description of project #905

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ public ResponseEntity<ResponseMessage<String>> createProject(ProjectRequest proj
projectId = projectService
.createProject(Project.builder()
.name(projectRequest.getProjectName())
.owner(User.builder().id(user.getId()).build())
.owner(User.builder()
.id(idConvertor.revert(projectRequest.getOwnerId()))
.build())
.isDefault(false)
.description(projectRequest.getDescription())
.build());
}

Expand Down Expand Up @@ -125,7 +128,10 @@ public ResponseEntity<ResponseMessage<ProjectVO>> getProjectByUrl(String project
@Override
public ResponseEntity<ResponseMessage<String>> updateProject(String projectUrl,
ProjectRequest projectRequest) {
Boolean res = projectService.modifyProject(projectUrl, projectRequest.getProjectName());
Boolean res = projectService.modifyProject(projectUrl,
projectRequest.getProjectName(),
projectRequest.getDescription(),
idConvertor.revert(projectRequest.getOwnerId()));
if(!res) {
throw new StarWhaleApiException(new SWProcessException(ErrorType.DB).tip("Update project failed."),
HttpStatus.INTERNAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public class ProjectRequest implements Serializable {
@JsonProperty("projectId")
private String projectId;

@JsonProperty("ownerId")
private String ownerId;

@JsonProperty("description")
private String description;

@JsonProperty(value = "recover", defaultValue = "false", required = true)
private Boolean recover;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ public class ProjectVO implements Serializable {

private String name;

private String description;

private Long createdTime;

private UserVO owner;

private Boolean isDefault;

public static ProjectVO empty() {
return new ProjectVO("", "", -1L, UserVO.empty(), false);
return new ProjectVO("", "", "", -1L, UserVO.empty(), false);
}

public static ProjectVO system() {
return new ProjectVO("0", "SYSTEM", -1L, UserVO.empty(), false);
return new ProjectVO("0", "SYSTEM", "System",-1L, UserVO.empty(), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public ProjectVO convert(ProjectEntity entity) throws ConvertException {
.name(entity.getProjectName())
.owner(userConvertor.convert(entity.getOwner()))
.createdTime(localDateTimeConvertor.convert(entity.getCreatedTime()))
.description(entity.getDescription())
.build();
}

Expand All @@ -63,6 +64,7 @@ public ProjectEntity revert(ProjectVO vo) throws ConvertException {
return ProjectEntity.builder()
.id(idConvertor.revert(vo.getId()))
.projectName(vo.getName())
.description(vo.getDescription())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public Long createProject(Project project) {
ProjectEntity entity = ProjectEntity.builder()
.projectName(project.getName())
.ownerId(project.getOwner().getId())
.description(project.getDescription())
.isDefault(project.isDefault() ? 1 : 0)
.build();
projectMapper.createProject(entity);
Expand Down Expand Up @@ -186,11 +187,13 @@ public Long recoverProject(String projectUrl) {
return id;
}

public Boolean modifyProject(String projectUrl, String projectName) {
public Boolean modifyProject(String projectUrl, String projectName, String description, Long userId) {
Long projectId = projectManager.getProjectId(projectUrl);
ProjectEntity entity = ProjectEntity.builder()
.id(projectId)
.projectName(projectName)
.description(description)
.ownerId(userId)
.build();
int res = projectMapper.modifyProject(entity);
log.info("Project has been modified ID={}", entity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Project {

private String name;

private String description;

private User owner;

private boolean isDefault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class ProjectEntity extends BaseEntity {

private UserEntity owner;

private String description;

private Integer isDeleted;

private Integer isDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table project_info
add project_description text null after owner_id;
18 changes: 15 additions & 3 deletions server/controller/src/main/resources/mapper/ProjectMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="ai.starwhale.mlops.domain.project.mapper.ProjectMapper">
<insert id="createProject" parameterType="ai.starwhale.mlops.domain.project.po.ProjectEntity" useGeneratedKeys="true" keyProperty="id">
insert into project_info(project_name, owner_id)
values (#{project.projectName}, #{project.ownerId})
insert into project_info(project_name, owner_id, project_description)
values (#{project.projectName}, #{project.ownerId}, #{project.description})
</insert>

<update id="deleteProject" parameterType="java.lang.Long">
Expand All @@ -27,14 +27,25 @@

<update id="modifyProject" parameterType="ai.starwhale.mlops.domain.project.po.ProjectEntity">
update project_info
set project_name = #{project.projectName}
<set>
<if test="project.projectName != null and project.projectName != ''">
project_name = #{project.projectName},
</if>
<if test="project.description != null and project.description != ''">
project_description = #{project.description},
</if>
<if test="project.ownerId != null">
owner_id = #{project.ownerId}
</if>
</set>
where id = #{project.id}
</update>

<sql id="select_project">
select p.id as project_id,
p.project_name,
p.owner_id,
p.project_description,
p.is_deleted as project_is_deleted,
p.is_default as project_is_default,
p.created_time as project_created_time,
Expand Down Expand Up @@ -98,6 +109,7 @@
<resultMap id="projectResultMap" type="ai.starwhale.mlops.domain.project.po.ProjectEntity">
<id property="id" column="project_id" />
<result property="projectName" column="project_name"/>
<result property="description" column="project_description" />
<result property="isDeleted" column="project_is_deleted"/>
<result property="isDefault" column="project_is_default"/>
<result property="createdTime" column="project_created_time"/>
Expand Down