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

Feature: Organizations #98

Closed
wants to merge 1 commit into from
Closed
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
59 changes: 59 additions & 0 deletions src/main/java/co/novu/api/organizations/OrganizationHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package co.novu.api.organizations;

import co.novu.api.organizations.requests.CreateOrganizationRequest;
import co.novu.api.organizations.requests.UpdateMemberRoleRequest;
import co.novu.api.organizations.requests.UpdateOrganizationBrandRequest;
import co.novu.api.organizations.requests.UpdateOrganizationNameRequest;
import co.novu.api.organizations.responses.FetchMembersResponse;
import co.novu.api.organizations.responses.UpdateOrganizationBrandResponse;
import co.novu.api.organizations.responses.MemberResponse;
import co.novu.api.organizations.responses.OrganizationResponse;
import co.novu.api.organizations.responses.FetchOrganizationResponse;
import co.novu.api.organizations.responses.UpdateOrganizationNameResponse;
import co.novu.common.base.NovuConfig;
import co.novu.common.rest.RestHandler;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class OrganizationHandler {

private final RestHandler restHandler;

private final NovuConfig novuConfig;
private static final String ENDPOINT = "organizations";


public OrganizationResponse createOrganization(CreateOrganizationRequest request) {
return restHandler.handlePost(request, OrganizationResponse.class, novuConfig, ENDPOINT);
}

public FetchOrganizationResponse fetchAllOrganizations() {
return restHandler.handleGet(FetchOrganizationResponse.class, novuConfig, ENDPOINT);
}

public UpdateOrganizationNameResponse updateOrganizationName(UpdateOrganizationNameRequest request) {
return restHandler.handlePatch(request, UpdateOrganizationNameResponse.class, novuConfig, ENDPOINT);
}

public OrganizationResponse fetchCurrentOrganization() {
return restHandler.handleGet(OrganizationResponse.class, novuConfig, ENDPOINT + "/me");
}

public MemberResponse removeMemberWithId(String memberId) {
return restHandler.handleDelete(MemberResponse.class, novuConfig, ENDPOINT + memberId);
}

public MemberResponse updateMemberRole(UpdateMemberRoleRequest request, String memberId) {
return restHandler.handlePut(request, MemberResponse.class, novuConfig, ENDPOINT + "/members/" + memberId + "/roles");
}

public FetchMembersResponse fetchMembersOfOrganization() {
return restHandler.handleGet(FetchMembersResponse.class, novuConfig, ENDPOINT + "/members");
}

public UpdateOrganizationBrandResponse updateOrganizationBrand(UpdateOrganizationBrandRequest request) {
return restHandler.handlePut(request, UpdateOrganizationBrandResponse.class, novuConfig, ENDPOINT + "/branding");
}


}
13 changes: 13 additions & 0 deletions src/main/java/co/novu/api/organizations/pojos/Branding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.novu.api.organizations.pojos;

import lombok.Data;

@Data
public class Branding {
private String direction;
private String logo;
private String color;
private String fontColor;
private String contentBackground;
private String fontFamily;
}
14 changes: 14 additions & 0 deletions src/main/java/co/novu/api/organizations/pojos/InviteDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package co.novu.api.organizations.pojos;

import lombok.Data;

@Data
public class InviteDetails {
private String email;
private String token;
private String invitationDate;
private String answerDate;
private String _inviterId;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package co.novu.api.organizations.pojos;

import lombok.Data;

import java.util.List;

@Data
public class PartnerConfigurations {
private List<String> projectIds;
private String accessToken;
private String configurationId;
private String teamId;
private String partnerType;
}
13 changes: 13 additions & 0 deletions src/main/java/co/novu/api/organizations/pojos/UserDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.novu.api.organizations.pojos;

import lombok.Data;

@Data
public class UserDetails {
private String _id;
private String firstName;
private String lastName;
private String email;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package co.novu.api.organizations.requests;

import co.novu.common.contracts.IRequest;
import lombok.Data;

@Data
public class CreateOrganizationRequest implements IRequest {
private String name;
private String logo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.novu.api.organizations.requests;

import co.novu.common.contracts.IRequest;
import lombok.Data;

@Data
public class UpdateMemberRoleRequest implements IRequest {
private String role;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.novu.api.organizations.requests;

import co.novu.common.contracts.IRequest;
import lombok.Data;

@Data
public class UpdateOrganizationBrandRequest implements IRequest {
private String logo;
private String color;
private String fontColor;
private String contentBackground;
private String fontFamily;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.novu.api.organizations.requests;

import co.novu.common.contracts.IRequest;
import lombok.Data;

@Data
public class UpdateOrganizationNameRequest implements IRequest {
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package co.novu.api.organizations.responses;

import lombok.Data;

import java.util.List;

@Data
public class FetchMembersResponse {
private List<MemberResponseData> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package co.novu.api.organizations.responses;

import lombok.Data;

import java.util.List;

@Data
public class FetchOrganizationResponse {
private List<OrganizationResponseData> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.novu.api.organizations.responses;

import lombok.Data;

@Data
public class MemberResponse {
private MemberResponseData data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package co.novu.api.organizations.responses;

import co.novu.api.organizations.pojos.InviteDetails;
import co.novu.api.organizations.pojos.UserDetails;
import lombok.Data;

import java.util.List;

@Data
public class MemberResponseData {
private String _id;
private String _userId;
private UserDetails user;
private List<String> roles;
private InviteDetails invite;
private String memberStatus;
private String _organizationId;

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.novu.api.organizations.responses;

import lombok.Data;

@Data
public class OrganizationResponse {
private OrganizationResponseData data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.novu.api.organizations.responses;

import co.novu.api.organizations.pojos.Branding;
import co.novu.api.organizations.pojos.PartnerConfigurations;
import lombok.Data;

import java.util.List;

@Data
public class OrganizationResponseData {
private String name;
private String logo;
private Branding branding;
private List<PartnerConfigurations> partnerConfigurations;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.novu.api.organizations.responses;

import co.novu.api.organizations.pojos.Branding;
import lombok.Data;



@Data
public class UpdateOrganizationBrandResponse {
private Branding data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.novu.api.organizations.responses;

import lombok.Data;

@Data
public class UpdateOrganizationNameResponse {
private UpdateOrganizationNameResponseData data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.novu.api.organizations.responses;

import lombok.Data;

@Data
public class UpdateOrganizationNameResponseData {
private String name;
}
90 changes: 90 additions & 0 deletions src/main/java/co/novu/common/base/Novu.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
import co.novu.api.notifications.responses.NotificationResponse;
import co.novu.api.notifications.responses.NotificationStatsResponse;
import co.novu.api.notifications.responses.NotificationsResponse;
import co.novu.api.organizations.OrganizationHandler;
import co.novu.api.organizations.requests.CreateOrganizationRequest;
import co.novu.api.organizations.requests.UpdateMemberRoleRequest;
import co.novu.api.organizations.requests.UpdateOrganizationBrandRequest;
import co.novu.api.organizations.requests.UpdateOrganizationNameRequest;
import co.novu.api.organizations.responses.FetchMembersResponse;
import co.novu.api.organizations.responses.UpdateOrganizationBrandResponse;
import co.novu.api.organizations.responses.MemberResponse;
import co.novu.api.organizations.responses.OrganizationResponse;
import co.novu.api.organizations.responses.FetchOrganizationResponse;
import co.novu.api.organizations.responses.UpdateOrganizationNameResponse;
import co.novu.api.subscribers.requests.BulkSubscriberRequest;
import co.novu.api.subscribers.requests.MarkAllMessagesRequest;
import co.novu.api.subscribers.responses.CreateBulkSubscriberResponse;
Expand Down Expand Up @@ -139,6 +150,8 @@ public class Novu {

private final TenantsHandler tenantsHandler;

private final OrganizationHandler organizationHandler;

public Novu(String apiKey) {
this(new NovuConfig(apiKey));
}
Expand All @@ -161,6 +174,7 @@ public Novu(NovuConfig novuConfig) {
this.executiveDetailsHandler = new ExecutiveDetailsHandler(restHandler, novuConfig);
this.blueprintsHandler = new BlueprintsHandler(restHandler, novuConfig);
this.tenantsHandler = new TenantsHandler(restHandler, novuConfig);
this.organizationHandler = new OrganizationHandler(restHandler, novuConfig);
}

public TriggerEventResponse triggerEvent(TriggerEventRequest request) {
Expand Down Expand Up @@ -883,4 +897,80 @@ public DeleteTenantResponse deleteTenant(String identifier) {
throw e;
}
}

public OrganizationResponse createOrganization(CreateOrganizationRequest request) {
try {
return organizationHandler.createOrganization(request);
} catch (Exception e) {
log.error("Error creating Organization", e);
throw e;
}
}

public FetchOrganizationResponse fetchAllOrganizations() {
try {
return organizationHandler.fetchAllOrganizations();
} catch (Exception e) {
log.error("Error fetching Organizations", e);
throw e;
}
}

public UpdateOrganizationNameResponse updateOrganizationName(UpdateOrganizationNameRequest request) {
try {
return organizationHandler.updateOrganizationName(request);
} catch (Exception e) {
log.error("Error Updating Organization Name", e);
throw e;
}
}

public OrganizationResponse fetchCurrentOrganization() {
try {
return organizationHandler.fetchCurrentOrganization();
} catch (Exception e) {
log.error("Error Fetching Current Organization", e);
throw e;
}
}

public MemberResponse removeMemberWithId(String memberId) {
try {
return organizationHandler.removeMemberWithId(memberId);
} catch (Exception e) {
log.error("Error Removing Member With MemberId", e);
throw e;
}
}

public MemberResponse updateMemberRole(UpdateMemberRoleRequest request,String memberId) {
try {
return organizationHandler.updateMemberRole(request,memberId);
} catch (Exception e) {
log.error("Error Updating Member Role", e);
throw e;
}
}

public FetchMembersResponse fetchMembersOfOrganization() {
try {
return organizationHandler.fetchMembersOfOrganization();
} catch (Exception e) {
log.error("Error Fetching Organization Members", e);
throw e;
}
}

public UpdateOrganizationBrandResponse UpdateOrganizationBrand(UpdateOrganizationBrandRequest request) {
try {
return organizationHandler.updateOrganizationBrand(request);
} catch (Exception e) {
log.error("Error Updating Organization Brand", e);
throw e;
}
}




}
Loading