From a657cb1e123a218dc2ba287a0e1fe96f18d83fe4 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 18 Sep 2024 23:32:20 -0400 Subject: [PATCH] more stuff (: --- .../controller/v1/OrganizationController.java | 6 ++- .../java/cc/pulseapp/api/model/Feature.java | 3 +- .../api/model/org/DetailedOrganization.java | 27 +++++++++++++ .../pulseapp/api/model/org/Organization.java | 5 +++ .../org/response/OrganizationResponse.java | 40 ------------------- .../pulseapp/api/model/page/StatusPage.java | 12 +++--- .../api/service/OrganizationService.java | 12 +++--- .../api/service/StatusPageService.java | 2 +- 8 files changed, 51 insertions(+), 56 deletions(-) create mode 100644 src/main/java/cc/pulseapp/api/model/org/DetailedOrganization.java delete mode 100644 src/main/java/cc/pulseapp/api/model/org/response/OrganizationResponse.java diff --git a/src/main/java/cc/pulseapp/api/controller/v1/OrganizationController.java b/src/main/java/cc/pulseapp/api/controller/v1/OrganizationController.java index 69d7192..4b84bbf 100644 --- a/src/main/java/cc/pulseapp/api/controller/v1/OrganizationController.java +++ b/src/main/java/cc/pulseapp/api/controller/v1/OrganizationController.java @@ -1,7 +1,7 @@ package cc.pulseapp.api.controller.v1; +import cc.pulseapp.api.model.org.DetailedOrganization; import cc.pulseapp.api.model.org.Organization; -import cc.pulseapp.api.model.org.response.OrganizationResponse; import cc.pulseapp.api.service.OrganizationService; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; @@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * This controller is responsible for * handling {@link Organization} requests. @@ -38,7 +40,7 @@ public final class OrganizationController { * @return the organizations */ @GetMapping("/@me") @ResponseBody @NonNull - public ResponseEntity getOrganizations() { + public ResponseEntity> getOrganizations() { return ResponseEntity.ok(orgService.getOrganizations()); } } \ No newline at end of file diff --git a/src/main/java/cc/pulseapp/api/model/Feature.java b/src/main/java/cc/pulseapp/api/model/Feature.java index 9292775..4b44e70 100644 --- a/src/main/java/cc/pulseapp/api/model/Feature.java +++ b/src/main/java/cc/pulseapp/api/model/Feature.java @@ -33,7 +33,6 @@ public enum Feature { @Setter private Object value; - /** * Get a feature by its id. * @@ -58,7 +57,7 @@ public enum Feature { public static int hash() { int hash = 0; for (Feature feature : VALUES) { - hash+= Objects.hash(feature.isEnabled(), feature.getValue()); + hash += Objects.hash(feature.isEnabled(), feature.getValue()); } return hash; } diff --git a/src/main/java/cc/pulseapp/api/model/org/DetailedOrganization.java b/src/main/java/cc/pulseapp/api/model/org/DetailedOrganization.java new file mode 100644 index 0000000..4ba1388 --- /dev/null +++ b/src/main/java/cc/pulseapp/api/model/org/DetailedOrganization.java @@ -0,0 +1,27 @@ +package cc.pulseapp.api.model.org; + +import cc.pulseapp.api.model.page.StatusPage; +import lombok.Getter; +import lombok.NonNull; + +import java.util.List; + +/** + * A "detailed" {@link Organization}, or in + * other words, an {@link Organization} with + * owned {@link StatusPage}'s. + * + * @author Braydon + */ +@Getter +public final class DetailedOrganization extends cc.pulseapp.api.model.org.Organization { + /** + * The status pages owned by this organization. + */ + @NonNull private final List statusPages; + + public DetailedOrganization(@NonNull cc.pulseapp.api.model.org.Organization origin, @NonNull List statusPages) { + super(origin.getSnowflake(), origin.getName(), origin.getSlug(), origin.getLogo(), origin.getOwnerSnowflake()); + this.statusPages = statusPages; + } +} \ No newline at end of file diff --git a/src/main/java/cc/pulseapp/api/model/org/Organization.java b/src/main/java/cc/pulseapp/api/model/org/Organization.java index cd3e6c7..18caaca 100644 --- a/src/main/java/cc/pulseapp/api/model/org/Organization.java +++ b/src/main/java/cc/pulseapp/api/model/org/Organization.java @@ -34,6 +34,11 @@ public class Organization { */ @Indexed @NonNull private final String slug; + /** + * The hash to the logo of this organization, if any. + */ + private final String logo; + /** * The snowflake of the {@link User} * that owns this organization. diff --git a/src/main/java/cc/pulseapp/api/model/org/response/OrganizationResponse.java b/src/main/java/cc/pulseapp/api/model/org/response/OrganizationResponse.java deleted file mode 100644 index dc725e2..0000000 --- a/src/main/java/cc/pulseapp/api/model/org/response/OrganizationResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -package cc.pulseapp.api.model.org.response; - -import cc.pulseapp.api.model.page.StatusPage; -import cc.pulseapp.api.model.user.User; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NonNull; -import lombok.ToString; - -import java.util.List; - -/** - * The response to return when fetching - * a {@link User}'s {@link Organization}'s. - * - * @author Braydon - */ -@AllArgsConstructor @Getter @ToString -public final class OrganizationResponse { - /** - * The organizations in this response. - */ - @NonNull private final List organizations; - - /** - * An organization wrapper that includes the owned status pages. - */ - @Getter - public static class Organization extends cc.pulseapp.api.model.org.Organization { - /** - * The status pages owned by this organization. - */ - @NonNull private final List statusPages; - - public Organization(@NonNull cc.pulseapp.api.model.org.Organization origin, @NonNull List statusPages) { - super(origin.getSnowflake(), origin.getName(), origin.getSlug(), origin.getOwnerSnowflake()); - this.statusPages = statusPages; - } - } -} \ No newline at end of file diff --git a/src/main/java/cc/pulseapp/api/model/page/StatusPage.java b/src/main/java/cc/pulseapp/api/model/page/StatusPage.java index f398ea5..f5edec7 100644 --- a/src/main/java/cc/pulseapp/api/model/page/StatusPage.java +++ b/src/main/java/cc/pulseapp/api/model/page/StatusPage.java @@ -7,6 +7,8 @@ import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.mapping.Document; /** + * A status page owned by an {@link Organization}. + * * @author Braydon */ @AllArgsConstructor @Getter @@ -23,16 +25,16 @@ public final class StatusPage { */ @Indexed @NonNull private final String name; - /** - * The description of this status page, if any. - */ - private final String description; - /** * The slug of this status page. */ @NonNull private final String slug; + /** + * The description of this status page, if any. + */ + private final String description; + /** * The hash to the logo of this status page, if any. */ diff --git a/src/main/java/cc/pulseapp/api/service/OrganizationService.java b/src/main/java/cc/pulseapp/api/service/OrganizationService.java index f7ed7f6..1f5b313 100644 --- a/src/main/java/cc/pulseapp/api/service/OrganizationService.java +++ b/src/main/java/cc/pulseapp/api/service/OrganizationService.java @@ -3,8 +3,8 @@ package cc.pulseapp.api.service; import cc.pulseapp.api.exception.impl.BadRequestException; import cc.pulseapp.api.model.Feature; import cc.pulseapp.api.model.IGenericResponse; +import cc.pulseapp.api.model.org.DetailedOrganization; import cc.pulseapp.api.model.org.Organization; -import cc.pulseapp.api.model.org.response.OrganizationResponse; import cc.pulseapp.api.model.user.User; import cc.pulseapp.api.repository.OrganizationRepository; import cc.pulseapp.api.repository.StatusPageRepository; @@ -70,17 +70,17 @@ public final class OrganizationService { throw new BadRequestException(Error.ORG_NAME_TAKEN); } // Create the org and return it - return orgRepository.save(new Organization(snowflakeService.generateSnowflake(), name, slug, owner.getSnowflake())); + return orgRepository.save(new Organization(snowflakeService.generateSnowflake(), name, slug, null, owner.getSnowflake())); } @NonNull - public OrganizationResponse getOrganizations() { + public List getOrganizations() { User user = authService.getAuthenticatedUser(); - List organizations = new ArrayList<>(); + List organizations = new ArrayList<>(); for (Organization org : orgRepository.findByOwnerSnowflake(user.getSnowflake())) { - organizations.add(new OrganizationResponse.Organization(org, statusPageRepository.findByOrgSnowflake(org.getSnowflake()))); + organizations.add(new DetailedOrganization(org, statusPageRepository.findByOrgSnowflake(org.getSnowflake()))); } - return new OrganizationResponse(organizations); + return organizations; } /** diff --git a/src/main/java/cc/pulseapp/api/service/StatusPageService.java b/src/main/java/cc/pulseapp/api/service/StatusPageService.java index 86b2c8c..e040d75 100644 --- a/src/main/java/cc/pulseapp/api/service/StatusPageService.java +++ b/src/main/java/cc/pulseapp/api/service/StatusPageService.java @@ -57,7 +57,7 @@ public final class StatusPageService { String slug = name.replace(" ", "-") + "-" + ThreadLocalRandom.current().nextInt(10000, 99999); return pageRepository.save(new StatusPage( - snowflakeService.generateSnowflake(), name, null, slug, null, + snowflakeService.generateSnowflake(), name, slug, null, null, null, StatusPageTheme.AUTO, true, owner.getSnowflake()) ); }