Skip to content

Commit

Permalink
enhancement(apps): Implement ProjectApp functionality with CRUD opera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
zZHorizonZz committed Jul 30, 2023
1 parent 87cd261 commit 42326ba
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 12 deletions.
18 changes: 18 additions & 0 deletions server/src/main/java/dev/shiperist/data/OsType.java
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;
}
}
20 changes: 20 additions & 0 deletions server/src/main/java/dev/shiperist/data/ReleaseType.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AccountEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
private Long id;

@Column(name = "user_id")
private Long userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UserEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
private Long id;

@Column(name = "name")
private String name;
Expand Down
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;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.shiperist.entity.project;

import dev.shiperist.entity.account.UserEntity;
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase;
import jakarta.persistence.*;
import lombok.Data;
Expand All @@ -16,7 +17,7 @@ public class ProjectEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
private Long id;

@Column(name = "name", unique = true)
private String name;
Expand All @@ -40,4 +41,10 @@ public class ProjectEntity extends PanacheEntityBase {
@Column(name = "members")
@OneToMany(mappedBy = "project", fetch = FetchType.EAGER)
private Set<ProjectMemberEntity> members;

@ManyToMany(mappedBy = "projects")
private Set<UserEntity> users;

@OneToMany(mappedBy = "project", fetch = FetchType.EAGER)
private Set<ProjectAppEntity> projectApps;
}
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 server/src/main/java/dev/shiperist/model/project/ProjectApp.java
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;
}
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> {
}
9 changes: 0 additions & 9 deletions server/src/main/java/dev/shiperist/resource/AuthResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ public Uni<Response> recoverPassword(User user) {
return Uni.createFrom().item(Response.ok().build());
}

/*
TODO: Return this structure:
{
"access_token": "jwt-token-representing-the-user",
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": "a-refresh-token"
}
*/
@POST
@PermitAll
@Path("/token")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.shiperist.resource;

public class ProjectAppRelease {
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.shiperist.resource;

public class ProjectAppUploadResource {
}
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);
}
}

0 comments on commit 42326ba

Please sign in to comment.