-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement(apps): Implement ProjectApp functionality with CRUD opera…
…tion
- Loading branch information
1 parent
87cd261
commit 42326ba
Showing
14 changed files
with
294 additions
and
12 deletions.
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,18 @@ | ||
package dev.shiperist.data; | ||
|
||
public enum OsType { | ||
ANDROID("android"), | ||
IOS("ios"), | ||
WINDOWS("windows"), | ||
WEB("web"); | ||
|
||
private final String value; | ||
|
||
OsType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
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,20 @@ | ||
package dev.shiperist.data; | ||
|
||
public enum ReleaseType { | ||
|
||
ALPHA("alpha"), | ||
|
||
BETA("beta"), | ||
|
||
PRODUCTION("production"); | ||
|
||
private final String value; | ||
|
||
ReleaseType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
server/src/main/java/dev/shiperist/entity/project/ProjectAppEntity.java
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,58 @@ | ||
package dev.shiperist.entity.project; | ||
|
||
import dev.shiperist.data.OsType; | ||
import dev.shiperist.data.ReleaseType; | ||
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; | ||
import jakarta.persistence.*; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
@Entity(name = "Account") | ||
@Table(name = "account", schema = "public") | ||
@EqualsAndHashCode(callSuper = true) | ||
public class ProjectAppEntity extends PanacheEntityBase { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "project_id") | ||
private Long projectId; | ||
|
||
@Column(name = "name", unique = true) | ||
private String name; | ||
|
||
@Column(name = "display_name") | ||
private String displayName; | ||
|
||
@Column(name = "description") | ||
private String description; | ||
|
||
@Column(name = "image") | ||
private String image; | ||
|
||
@Column(name = "status") | ||
private String status; | ||
|
||
@CreationTimestamp | ||
@Column(name = "created_at", updatable = false) | ||
private Date createdAt; | ||
|
||
@CreationTimestamp | ||
@Column(name = "updated_at") | ||
private Date updatedAt; | ||
|
||
@Column(name = "os") | ||
private OsType os; | ||
|
||
@Column(name = "release_type") | ||
private ReleaseType releaseType; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "project_id", insertable = false, updatable = false) | ||
private ProjectEntity project; | ||
} |
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
25 changes: 25 additions & 0 deletions
25
server/src/main/java/dev/shiperist/mapper/project/ProjectAppMapper.java
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,25 @@ | ||
package dev.shiperist.mapper.project; | ||
|
||
import dev.shiperist.entity.project.ProjectAppEntity; | ||
import dev.shiperist.mapper.QuarkusMappingConfig; | ||
import dev.shiperist.model.project.ProjectApp; | ||
import org.mapstruct.InheritInverseConfiguration; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.MappingTarget; | ||
|
||
import java.util.List; | ||
|
||
@Mapper(config = QuarkusMappingConfig.class) | ||
public interface ProjectAppMapper { | ||
|
||
List<ProjectApp> toDomainList(List<ProjectAppEntity> entities); | ||
|
||
ProjectApp toDomain(ProjectAppEntity entity); | ||
|
||
@InheritInverseConfiguration(name = "toDomain") | ||
ProjectAppEntity toEntity(ProjectApp domain); | ||
|
||
void updateEntityFromDomain(ProjectApp domain, @MappingTarget ProjectAppEntity entity); | ||
|
||
void updateDomainFromEntity(ProjectAppEntity entity, @MappingTarget ProjectApp domain); | ||
} |
22 changes: 22 additions & 0 deletions
22
server/src/main/java/dev/shiperist/model/project/ProjectApp.java
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,22 @@ | ||
package dev.shiperist.model.project; | ||
|
||
import dev.shiperist.data.OsType; | ||
import dev.shiperist.data.ReleaseType; | ||
import lombok.Data; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
public class ProjectApp { | ||
private Long id; | ||
private Long projectId; | ||
private String name; | ||
private String displayName; | ||
private String description; | ||
private String image; | ||
private String status; | ||
private Date createdAt; | ||
private Date updatedAt; | ||
private OsType os; | ||
private ReleaseType releaseType; | ||
} |
11 changes: 11 additions & 0 deletions
11
server/src/main/java/dev/shiperist/repository/project/ProjectAppRepository.java
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,11 @@ | ||
package dev.shiperist.repository.project; | ||
|
||
import dev.shiperist.entity.project.ProjectAppEntity; | ||
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase; | ||
import io.quarkus.hibernate.reactive.panache.common.WithSession; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@WithSession | ||
@ApplicationScoped | ||
public class ProjectAppRepository implements PanacheRepositoryBase<ProjectAppEntity, Long> { | ||
} |
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
4 changes: 4 additions & 0 deletions
4
server/src/main/java/dev/shiperist/resource/ProjectAppRelease.java
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,4 @@ | ||
package dev.shiperist.resource; | ||
|
||
public class ProjectAppRelease { | ||
} |
52 changes: 52 additions & 0 deletions
52
server/src/main/java/dev/shiperist/resource/ProjectAppResource.java
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,52 @@ | ||
package dev.shiperist.resource; | ||
|
||
import dev.shiperist.model.project.ProjectApp; | ||
import dev.shiperist.service.project.ProjectAppService; | ||
import io.smallrye.mutiny.Uni; | ||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.MediaType; | ||
import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
||
import java.util.List; | ||
|
||
|
||
@RequestScoped | ||
@Path("/projects/{projectId}/apps") | ||
@Tag(name = "Project Apps") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public class ProjectAppResource { | ||
|
||
@Inject | ||
ProjectAppService projectAppService; | ||
|
||
@POST | ||
public Uni<ProjectApp> createProjectApp(@PathParam("projectId") Long projectId, ProjectApp app) { | ||
return projectAppService.createProjectApp(projectId, app.getName(), app.getDescription(), app.getImage(), app.getOs(), app.getReleaseType()); | ||
} | ||
|
||
@PATCH | ||
@Path("{id}") | ||
public Uni<ProjectApp> updateProjectApp(@PathParam("id") Long id, ProjectApp app) { | ||
return projectAppService.updateProjectApp(id, app.getName(), app.getDescription(), app.getImage()); | ||
} | ||
|
||
@DELETE | ||
@Path("{id}") | ||
public Uni<Boolean> deleteProjectApp(@PathParam("id") Long id) { | ||
return projectAppService.deleteProjectApp(id); | ||
} | ||
|
||
@GET | ||
@Path("{id}") | ||
public Uni<ProjectApp> getProjectApp(@PathParam("id") Long id) { | ||
return projectAppService.getProjectApp(id); | ||
} | ||
|
||
@GET | ||
public Uni<List<ProjectApp>> getProjectApps(@PathParam("projectId") Long projectId) { | ||
return projectAppService.getProjectApps(projectId); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/dev/shiperist/resource/ProjectAppUploadResource.java
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,4 @@ | ||
package dev.shiperist.resource; | ||
|
||
public class ProjectAppUploadResource { | ||
} |
70 changes: 70 additions & 0 deletions
70
server/src/main/java/dev/shiperist/service/project/ProjectAppService.java
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,70 @@ | ||
package dev.shiperist.service.project; | ||
|
||
import dev.shiperist.data.OsType; | ||
import dev.shiperist.data.ReleaseType; | ||
import dev.shiperist.entity.project.ProjectAppEntity; | ||
import dev.shiperist.mapper.project.ProjectAppMapper; | ||
import dev.shiperist.model.project.ProjectApp; | ||
import dev.shiperist.repository.project.ProjectAppRepository; | ||
import dev.shiperist.repository.project.ProjectRepository; | ||
import io.smallrye.mutiny.Uni; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import java.util.List; | ||
|
||
@ApplicationScoped | ||
public class ProjectAppService { | ||
|
||
|
||
@Inject | ||
ProjectRepository projectService; | ||
|
||
@Inject | ||
ProjectAppRepository projectAppRepository; | ||
|
||
@Inject | ||
ProjectAppMapper projectAppMapper; | ||
|
||
public Uni<ProjectApp> createProjectApp(Long projectId, String name, String description, String image, OsType os, ReleaseType releaseType) { | ||
return projectService.findById(projectId) | ||
.onItem().ifNull().failWith(() -> new RuntimeException("Project not found")) | ||
.map(project -> { | ||
ProjectAppEntity projectApp = new ProjectAppEntity(); | ||
projectApp.setName(name); | ||
projectApp.setDescription(description); | ||
projectApp.setImage(image); | ||
projectApp.setOs(os); | ||
projectApp.setReleaseType(releaseType); | ||
projectApp.setProjectId(projectId); | ||
return projectApp; | ||
}) | ||
.onItem().ifNotNull().transformToUni(projectAppRepository::persistAndFlush) | ||
.onItem().ifNotNull().transform(projectAppMapper::toDomain); | ||
} | ||
|
||
public Uni<ProjectApp> updateProjectApp(Long id, String name, String description, String image) { | ||
return projectAppRepository.findById(id) | ||
.onItem().ifNull().failWith(() -> new RuntimeException("Project App not found")) | ||
.map(projectApp -> { | ||
projectApp.setName(name); | ||
projectApp.setDescription(description); | ||
projectApp.setImage(image); | ||
return projectApp; | ||
}) | ||
.onItem().ifNotNull().transformToUni(projectAppRepository::persistAndFlush) | ||
.onItem().ifNotNull().transform(projectAppMapper::toDomain); | ||
} | ||
|
||
public Uni<ProjectApp> getProjectApp(Long id) { | ||
return projectAppRepository.findById(id).map(projectAppMapper::toDomain); | ||
} | ||
|
||
public Uni<List<ProjectApp>> getProjectApps(Long projectId) { | ||
return projectAppRepository.list("projectId", projectId).map(projectAppMapper::toDomainList); | ||
} | ||
|
||
public Uni<Boolean> deleteProjectApp(Long id) { | ||
return projectAppRepository.deleteById(id); | ||
} | ||
} |