Skip to content

Commit ce23365

Browse files
init
1 parent 31fd01b commit ce23365

33 files changed

+1228
-879
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package io.easystartup.suggestfeature.beans;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import org.springframework.data.annotation.Id;
5+
import org.springframework.data.annotation.Reference;
6+
import org.springframework.data.annotation.Transient;
7+
import org.springframework.data.mongodb.core.index.CompoundIndex;
8+
import org.springframework.data.mongodb.core.index.Indexed;
9+
import org.springframework.data.mongodb.core.mapping.Document;
10+
11+
/*
12+
* @author indianBond
13+
* Mapping of end customer to organization
14+
*/
15+
@Document
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
@CompoundIndex(name = "userId_1_organizationId_1", def = "{'userId': 1, 'organizationId': 1}", unique = true)
18+
public class Customer {
19+
20+
public static final String FIELD_ID = "_id";
21+
public static final String FIELD_USER_ID = "userId";
22+
public static final String FIELD_ORGANIZATION_ID = "organizationId";
23+
24+
@Id
25+
private String id;
26+
27+
@Indexed
28+
private String userId;
29+
private Long createdAt;
30+
private String organizationId;
31+
32+
@Transient
33+
@Reference // Alternative to skip index
34+
private User user;
35+
36+
public Customer() {
37+
}
38+
39+
public String getId() {
40+
return id;
41+
}
42+
43+
public void setId(String id) {
44+
this.id = id;
45+
}
46+
47+
public String getUserId() {
48+
return userId;
49+
}
50+
51+
public void setUserId(String userId) {
52+
this.userId = userId;
53+
}
54+
55+
public Long getCreatedAt() {
56+
return createdAt;
57+
}
58+
59+
public void setCreatedAt(Long createdAt) {
60+
this.createdAt = createdAt;
61+
}
62+
63+
public String getOrganizationId() {
64+
return organizationId;
65+
}
66+
67+
public void setOrganizationId(String organizationId) {
68+
this.organizationId = organizationId;
69+
}
70+
71+
public User getUser() {
72+
return user;
73+
}
74+
75+
public void setUser(User user) {
76+
this.user = user;
77+
}
78+
}

backend/src/main/java/io/easystartup/suggestfeature/beans/Member.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import org.springframework.data.annotation.Id;
5+
import org.springframework.data.annotation.Reference;
6+
import org.springframework.data.annotation.Transient;
57
import org.springframework.data.mongodb.core.index.CompoundIndex;
68
import org.springframework.data.mongodb.core.index.Indexed;
79
import org.springframework.data.mongodb.core.mapping.Document;
@@ -32,6 +34,10 @@ public enum Role {
3234
private String organizationId;
3335
private Role role;
3436

37+
@Transient
38+
@Reference // Alternative to skip index
39+
private User user;
40+
3541
public Member() {
3642
}
3743

@@ -74,4 +80,12 @@ public Role getRole() {
7480
public void setRole(Role role) {
7581
this.role = role;
7682
}
83+
84+
public User getUser() {
85+
return user;
86+
}
87+
88+
public void setUser(User user) {
89+
this.user = user;
90+
}
7791
}

backend/src/main/java/io/easystartup/suggestfeature/rest/UserRestApi.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
import io.easystartup.suggestfeature.utils.JacksonMapper;
1212
import jakarta.ws.rs.*;
1313
import jakarta.ws.rs.core.Response;
14+
import org.apache.commons.lang3.StringUtils;
1415
import org.springframework.beans.factory.annotation.Autowired;
1516
import org.springframework.data.mongodb.core.query.Criteria;
1617
import org.springframework.data.mongodb.core.query.Query;
1718
import org.springframework.stereotype.Component;
1819

20+
import java.util.List;
21+
1922
/*
2023
* @author indianBond
2124
*/
@@ -96,4 +99,28 @@ public Response createOrg(OrganizationRequest req) {
9699
return Response.ok(JacksonMapper.toJson(organization)).build();
97100
}
98101

102+
@GET
103+
@Path("/fetch-members")
104+
@Consumes("application/json")
105+
@Produces("application/json")
106+
public Response fetchMembers() {
107+
String orgId = UserContext.current().getOrgId();
108+
if (StringUtils.isBlank(orgId)) {
109+
return Response.status(Response.Status.UNAUTHORIZED).entity("Invalid org").build();
110+
}
111+
Criteria criteria = Criteria.where(Member.FIELD_ORGANIZATION_ID).is(orgId);
112+
Query query = new Query(criteria);
113+
List<Member> members = mongoConnection.getDefaultMongoTemplate().find(query, Member.class);
114+
members.forEach(member -> {
115+
Criteria userCriteria = Criteria.where(User.FIELD_ID).is(member.getUserId());
116+
User dangerousUser = mongoConnection.getDefaultMongoTemplate().findOne(new Query(userCriteria), User.class);
117+
User user = new User();
118+
user.setId(dangerousUser.getId());
119+
user.setEmail(dangerousUser.getEmail());
120+
user.setName(dangerousUser.getName());
121+
member.setUser(user);
122+
});
123+
return Response.ok(JacksonMapper.toJson(members)).build();
124+
}
125+
99126
}

docs/docs/intro.md

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,4 @@
22
sidebar_position: 1
33
---
44

5-
# Tutorial Intro
6-
7-
Let's discover **Docusaurus in less than 5 minutes**.
8-
9-
## Getting Started
10-
11-
Get started by **creating a new site**.
12-
13-
Or **try Docusaurus immediately** with **[docusaurus.new](https://docusaurus.new)**.
14-
15-
### What you'll need
16-
17-
- [Node.js](https://nodejs.org/en/download/) version 18.0 or above:
18-
- When installing Node.js, you are recommended to check all checkboxes related to dependencies.
19-
20-
## Generate a new site
21-
22-
Generate a new Docusaurus site using the **classic template**.
23-
24-
The classic template will automatically be added to your project after you run the command:
25-
26-
```bash
27-
npm init docusaurus@latest my-website classic
28-
```
29-
30-
You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor.
31-
32-
The command also installs all necessary dependencies you need to run Docusaurus.
33-
34-
## Start your site
35-
36-
Run the development server:
37-
38-
```bash
39-
cd my-website
40-
npm run start
41-
```
42-
43-
The `cd` command changes the directory you're working with. In order to work with your newly created Docusaurus site, you'll need to navigate the terminal there.
44-
45-
The `npm run start` command builds your website locally and serves it through a development server, ready for you to view at http://localhost:3000/.
46-
47-
Open `docs/intro.md` (this page) and edit some lines: the site **reloads automatically** and displays your changes.
5+
# Getting Started

docs/docs/tutorial-basics/_category_.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/docs/tutorial-basics/congratulations.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/docs/tutorial-basics/create-a-blog-post.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

docs/docs/tutorial-basics/create-a-document.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

docs/docs/tutorial-basics/create-a-page.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)