more stuff (:
All checks were successful
Deploy API / deploy (ubuntu-latest, 2.44.0) (push) Successful in 49s

This commit is contained in:
Braydon 2024-09-18 23:32:20 -04:00
parent 993dfafed9
commit a657cb1e12
8 changed files with 51 additions and 56 deletions

@ -1,7 +1,7 @@
package cc.pulseapp.api.controller.v1; 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.Organization;
import cc.pulseapp.api.model.org.response.OrganizationResponse;
import cc.pulseapp.api.service.OrganizationService; import cc.pulseapp.api.service.OrganizationService;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired; 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.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* This controller is responsible for * This controller is responsible for
* handling {@link Organization} requests. * handling {@link Organization} requests.
@ -38,7 +40,7 @@ public final class OrganizationController {
* @return the organizations * @return the organizations
*/ */
@GetMapping("/@me") @ResponseBody @NonNull @GetMapping("/@me") @ResponseBody @NonNull
public ResponseEntity<OrganizationResponse> getOrganizations() { public ResponseEntity<List<DetailedOrganization>> getOrganizations() {
return ResponseEntity.ok(orgService.getOrganizations()); return ResponseEntity.ok(orgService.getOrganizations());
} }
} }

@ -33,7 +33,6 @@ public enum Feature {
@Setter private Object value; @Setter private Object value;
/** /**
* Get a feature by its id. * Get a feature by its id.
* *

@ -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<StatusPage> statusPages;
public DetailedOrganization(@NonNull cc.pulseapp.api.model.org.Organization origin, @NonNull List<StatusPage> statusPages) {
super(origin.getSnowflake(), origin.getName(), origin.getSlug(), origin.getLogo(), origin.getOwnerSnowflake());
this.statusPages = statusPages;
}
}

@ -34,6 +34,11 @@ public class Organization {
*/ */
@Indexed @NonNull private final String slug; @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} * The snowflake of the {@link User}
* that owns this organization. * that owns this organization.

@ -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<Organization> 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<StatusPage> statusPages;
public Organization(@NonNull cc.pulseapp.api.model.org.Organization origin, @NonNull List<StatusPage> statusPages) {
super(origin.getSnowflake(), origin.getName(), origin.getSlug(), origin.getOwnerSnowflake());
this.statusPages = statusPages;
}
}
}

@ -7,6 +7,8 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
/** /**
* A status page owned by an {@link Organization}.
*
* @author Braydon * @author Braydon
*/ */
@AllArgsConstructor @Getter @AllArgsConstructor @Getter
@ -23,16 +25,16 @@ public final class StatusPage {
*/ */
@Indexed @NonNull private final String name; @Indexed @NonNull private final String name;
/**
* The description of this status page, if any.
*/
private final String description;
/** /**
* The slug of this status page. * The slug of this status page.
*/ */
@NonNull private final String slug; @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. * The hash to the logo of this status page, if any.
*/ */

@ -3,8 +3,8 @@ package cc.pulseapp.api.service;
import cc.pulseapp.api.exception.impl.BadRequestException; import cc.pulseapp.api.exception.impl.BadRequestException;
import cc.pulseapp.api.model.Feature; import cc.pulseapp.api.model.Feature;
import cc.pulseapp.api.model.IGenericResponse; 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.Organization;
import cc.pulseapp.api.model.org.response.OrganizationResponse;
import cc.pulseapp.api.model.user.User; import cc.pulseapp.api.model.user.User;
import cc.pulseapp.api.repository.OrganizationRepository; import cc.pulseapp.api.repository.OrganizationRepository;
import cc.pulseapp.api.repository.StatusPageRepository; import cc.pulseapp.api.repository.StatusPageRepository;
@ -70,17 +70,17 @@ public final class OrganizationService {
throw new BadRequestException(Error.ORG_NAME_TAKEN); throw new BadRequestException(Error.ORG_NAME_TAKEN);
} }
// Create the org and return it // 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 @NonNull
public OrganizationResponse getOrganizations() { public List<DetailedOrganization> getOrganizations() {
User user = authService.getAuthenticatedUser(); User user = authService.getAuthenticatedUser();
List<OrganizationResponse.Organization> organizations = new ArrayList<>(); List<DetailedOrganization> organizations = new ArrayList<>();
for (Organization org : orgRepository.findByOwnerSnowflake(user.getSnowflake())) { 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;
} }
/** /**

@ -57,7 +57,7 @@ public final class StatusPageService {
String slug = name.replace(" ", "-") + String slug = name.replace(" ", "-") +
"-" + ThreadLocalRandom.current().nextInt(10000, 99999); "-" + ThreadLocalRandom.current().nextInt(10000, 99999);
return pageRepository.save(new StatusPage( return pageRepository.save(new StatusPage(
snowflakeService.generateSnowflake(), name, null, slug, null, snowflakeService.generateSnowflake(), name, slug, null, null,
null, StatusPageTheme.AUTO, true, owner.getSnowflake()) null, StatusPageTheme.AUTO, true, owner.getSnowflake())
); );
} }