Skip to content

Commit 16ee16b

Browse files
committed
merge
2 parents 7f6dfcb + d8617aa commit 16ee16b

File tree

11 files changed

+148
-128
lines changed

11 files changed

+148
-128
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ hs_err_pid*
2929
.idea
3030

3131
*.swp
32+
33+
target/surefire-reports/

pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@
7070
<artifactId>java-client</artifactId>
7171
<version>${couchbase.version}</version>
7272
</dependency>
73-
74-
73+
<!-- https://mvnrepository.com/artifact/org.mindrot/jbcrypt -->
74+
<dependency>
75+
<groupId>org.mindrot</groupId>
76+
<artifactId>jbcrypt</artifactId>
77+
<version>0.3m</version>
78+
</dependency>
7579
<dependency>
7680
<groupId>org.junit.jupiter</groupId>
7781
<artifactId>junit-jupiter</artifactId>

src.iml

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.3.6" level="project" />
3030
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.3.6" level="project" />
3131
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.6" level="project" />
32+
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.6" level="project" />
33+
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.6" level="project" />
3234
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.3.6" level="project" />
3335
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.4.5" level="project" />
3436
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.4.5" level="project" />
@@ -42,6 +44,8 @@
4244
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
4345
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.27" level="project" />
4446
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.4.5" level="project" />
47+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.4" level="project" />
48+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.4" level="project" />
4549
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.4" level="project" />
4650
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4" level="project" />
4751
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4" level="project" />
@@ -51,11 +55,6 @@
5155
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.45" level="project" />
5256
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.3.6" level="project" />
5357
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.3.6" level="project" />
54-
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-security:2.4.5" level="project" />
55-
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.6" level="project" />
56-
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:5.4.6" level="project" />
57-
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.4.6" level="project" />
58-
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-web:5.4.6" level="project" />
5958
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.4.5" level="project" />
6059
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.4.5" level="project" />
6160
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.4.5" level="project" />
@@ -76,33 +75,6 @@
7675
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
7776
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.3.6" level="project" />
7877
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.7.0" level="project" />
79-
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-webflux:2.4.5" level="project" />
80-
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-reactor-netty:2.4.5" level="project" />
81-
<orderEntry type="library" name="Maven: io.projectreactor.netty:reactor-netty-http:1.0.6" level="project" />
82-
<orderEntry type="library" name="Maven: io.netty:netty-codec-http:4.1.63.Final" level="project" />
83-
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.63.Final" level="project" />
84-
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.63.Final" level="project" />
85-
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.63.Final" level="project" />
86-
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.63.Final" level="project" />
87-
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.63.Final" level="project" />
88-
<orderEntry type="library" name="Maven: io.netty:netty-codec-http2:4.1.63.Final" level="project" />
89-
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.63.Final" level="project" />
90-
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.63.Final" level="project" />
91-
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.63.Final" level="project" />
92-
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns-native-macos:osx-x86_64:4.1.63.Final" level="project" />
93-
<orderEntry type="library" name="Maven: io.netty:netty-transport-native-unix-common:4.1.63.Final" level="project" />
94-
<orderEntry type="library" name="Maven: io.netty:netty-transport-native-epoll:linux-x86_64:4.1.63.Final" level="project" />
95-
<orderEntry type="library" name="Maven: io.projectreactor.netty:reactor-netty-core:1.0.6" level="project" />
96-
<orderEntry type="library" name="Maven: io.netty:netty-handler-proxy:4.1.63.Final" level="project" />
97-
<orderEntry type="library" name="Maven: io.netty:netty-codec-socks:4.1.63.Final" level="project" />
98-
<orderEntry type="library" name="Maven: org.springframework:spring-webflux:5.3.6" level="project" />
99-
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.4.5" level="project" />
100-
<orderEntry type="library" name="Maven: org.springframework.vault:spring-vault-core:2.2.3.RELEASE" level="project" />
101-
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.6" level="project" />
102-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.4" level="project" />
103-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.4" level="project" />
104-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.4" level="project" />
105-
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:2.4.5" level="project" />
10678
<orderEntry type="library" name="Maven: io.springfox:springfox-boot-starter:3.0.0" level="project" />
10779
<orderEntry type="library" name="Maven: io.springfox:springfox-oas:3.0.0" level="project" />
10880
<orderEntry type="library" name="Maven: io.swagger.core.v3:swagger-annotations:2.1.2" level="project" />
@@ -124,10 +96,14 @@
12496
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-webflux:3.0.0" level="project" />
12597
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.20" level="project" />
12698
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.20" level="project" />
99+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.4" level="project" />
127100
<orderEntry type="library" scope="RUNTIME" name="Maven: org.mapstruct:mapstruct:1.3.1.Final" level="project" />
128101
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:3.0.0" level="project" />
129102
<orderEntry type="library" name="Maven: com.couchbase.client:java-client:3.1.5" level="project" />
130103
<orderEntry type="library" name="Maven: com.couchbase.client:core-io:2.1.5" level="project" />
104+
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.4.5" level="project" />
105+
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.3" level="project" />
106+
<orderEntry type="library" name="Maven: org.mindrot:jbcrypt:0.3m" level="project" />
131107
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.1" level="project" />
132108
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
133109
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
@@ -139,8 +115,5 @@
139115
<orderEntry type="library" scope="TEST" name="Maven: org.junit.vintage:junit-vintage-engine:5.7.1" level="project" />
140116
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
141117
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.1" level="project" />
142-
<orderEntry type="library" scope="TEST" name="Maven: io.reactivex:rxjava-reactive-streams:1.2.1" level="project" />
143-
<orderEntry type="library" scope="TEST" name="Maven: io.reactivex:rxjava:1.3.8" level="project" />
144-
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.3" level="project" />
145118
</component>
146119
</module>

src/main/java/org/couchbase/quickstart/controllers/ProfileController.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
import io.swagger.annotations.ApiResponse;
1010
import io.swagger.annotations.ApiResponses;
1111
import static org.couchbase.quickstart.configs.CollectionNames.PROFILE;
12+
13+
import org.couchbase.quickstart.configs.CollectionNames;
14+
import org.couchbase.quickstart.configs.DBProperties;
1215
import org.couchbase.quickstart.models.Profile;
13-
import org.couchbase.quickstart.models.ProfileResult;
16+
import org.couchbase.quickstart.models.ProfileRequest;
1417
import org.springframework.http.HttpStatus;
1518
import org.springframework.http.MediaType;
1619
import org.springframework.http.ResponseEntity;
@@ -23,88 +26,62 @@
2326
import java.util.UUID;
2427

2528
@RestController
26-
@RequestMapping("/api/v1/profiles")
29+
@RequestMapping("/api/v1/profile")
2730
public class ProfileController {
2831

2932
private Cluster cluster;
3033
private Collection profileCol;
34+
private DBProperties dbProperties;
3135

32-
public ProfileController(Cluster cluster, Bucket bucket) {
36+
public ProfileController(Cluster cluster, Bucket bucket, DBProperties dbProperties) {
3337
this.cluster = cluster;
3438
this.profileCol = bucket.collection(PROFILE);
39+
this.dbProperties = dbProperties;
3540
}
3641

3742

3843
@CrossOrigin(value="*")
3944
@PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE)
40-
@ApiOperation(value = "Post User Profile")
45+
@ApiOperation(value = "Create a user profile from the request")
4146
@ApiResponses({
4247
@ApiResponse(code = 201, message = "Created", response = Profile.class),
43-
@ApiResponse(code = 401, message = "Unauthorized", response = Error.class),
44-
@ApiResponse(code = 404, message = "Not Found", response = Error.class),
4548
@ApiResponse(code = 500, message = "Internal Server Error", response = Error.class)
4649
})
47-
public ResponseEntity<Profile> save(@RequestBody final Profile userProfile) {
50+
public ResponseEntity<Profile> save(@RequestBody final ProfileRequest userProfile) {
4851
//generates an id and save the user
49-
userProfile.setPid(UUID.randomUUID().toString());
50-
profileCol.insert(userProfile.getPid(), userProfile);
51-
return ResponseEntity.status(HttpStatus.CREATED).body(userProfile);
52-
}
53-
54-
55-
@CrossOrigin(value="*")
56-
@GetMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE)
57-
@ApiOperation(value = "Search for User Profiles", produces = MediaType.APPLICATION_JSON_VALUE)
58-
@ApiResponses(
59-
value = {
60-
@ApiResponse(code = 200, message = "OK"),
61-
@ApiResponse(code = 500, message = "Error occurred in getting user profiles", response = Error.class)
62-
})
63-
public ResponseEntity<List<Profile>> getProfiles(
64-
@RequestParam(required=false, defaultValue = "5") int limit,
65-
@RequestParam(required=false, defaultValue = "0") int skip,
66-
@RequestParam String searchFirstName) {
67-
68-
final List<Profile> profiles = cluster.query("SELECT p.* FROM user_profile._default.profile p WHERE lower(p.firstName) LIKE $firstName LIMIT $limit OFFSET $skip",
69-
queryOptions().parameters(JsonObject.create()
70-
.put("firstName", "%"+searchFirstName.toLowerCase()+"%")
71-
.put("limit", limit)
72-
.put("skip", skip))
73-
.scanConsistency(QueryScanConsistency.REQUEST_PLUS))
74-
.rowsAs(Profile.class);
75-
return ResponseEntity.status(HttpStatus.OK).body(profiles);
52+
Profile profile = userProfile.getProfile();
53+
profileCol.insert(profile.getPid(), profile);
54+
return ResponseEntity.status(HttpStatus.CREATED).body(profile);
7655
}
7756

7857
@CrossOrigin(value="*")
7958
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
80-
@ApiOperation(value = "Get a User Profile", produces = MediaType.APPLICATION_JSON_VALUE)
59+
@ApiOperation(value = "Get a user profile by Id", produces = MediaType.APPLICATION_JSON_VALUE)
8160
@ApiResponses(
8261
value = {
8362
@ApiResponse(code = 200, message = "OK"),
8463
@ApiResponse(code = 500, message = "Error occurred in getting user profiles", response = Error.class)
8564
})
8665
public ResponseEntity<Profile> getProfile(@RequestParam String pid) {
8766
Profile profile = profileCol.get(pid).contentAs(Profile.class);
88-
profile.setPid(pid);
8967
return ResponseEntity.status(HttpStatus.OK).body(profile);
9068
}
9169

9270
@CrossOrigin(value="*")
9371
@PutMapping(path = "/{id}")
94-
@ApiOperation(value = "Modify a Users Profile", response = Profile.class)
72+
@ApiOperation(value = "Update a user profile", response = Profile.class)
9573
@ApiResponses({
96-
@ApiResponse(code = 200, message = "OK", response = Profile.class),
97-
@ApiResponse(code = 401, message = "Unauthorized", response = Error.class),
98-
@ApiResponse(code = 404, message = "Not Found", response = Error.class),
99-
@ApiResponse(code = 500, message = "Internal Server Error", response = Error.class)
74+
@ApiResponse(code = 200, message = "Updated the user profile", response = Profile.class),
75+
@ApiResponse(code = 404, message = "user profile not found", response = Error.class),
76+
@ApiResponse(code = 500, message = "returns internal server error", response = Error.class)
10077
})
10178
public ResponseEntity<Profile> update( @PathVariable("id") String id, @RequestBody Profile profile) {
10279

10380
try {
10481
profileCol.upsert(id, profile);
105-
return ResponseEntity.status(HttpStatus.CREATED).body(new ProfileResult(profile, ""));
82+
return ResponseEntity.status(HttpStatus.CREATED).body(profile);
10683
} catch (Exception e){
107-
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(new ProfileResult(new Profile(), String.format("Error: %s",e.getMessage())));
84+
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(null);
10885
}
10986
}
11087

@@ -123,8 +100,32 @@ public ResponseEntity delete(@PathVariable UUID id){
123100
profileCol.remove(id.toString());
124101
return ResponseEntity.status(HttpStatus.OK).body(null);
125102
} catch (Exception e){
126-
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(new ProfileResult(new Profile(), String.format("Error: %s",e.getMessage())));
103+
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(null);
127104
}
128105
}
129106

107+
@CrossOrigin(value="*")
108+
@GetMapping(path = "/profiles/", produces = MediaType.APPLICATION_JSON_VALUE)
109+
@ApiOperation(value = "Search for user profiles", produces = MediaType.APPLICATION_JSON_VALUE)
110+
@ApiResponses(
111+
value = {
112+
@ApiResponse(code = 200, message = "Returns the list of user profiles"),
113+
@ApiResponse(code = 500, message = "Error occurred in getting user profiles", response = Error.class)
114+
})
115+
public ResponseEntity<List<Profile>> getProfiles(
116+
@RequestParam(required=false, defaultValue = "5") int limit,
117+
@RequestParam(required=false, defaultValue = "0") int skip,
118+
@RequestParam String search) {
119+
120+
final List<Profile> profiles = cluster.query("SELECT p.* FROM $bucketName._default.$collectionName p WHERE lower(p.firstName) LIKE $search OR lower(p.lastName) LIKE $search LIMIT $limit OFFSET $skip",
121+
queryOptions().parameters(JsonObject.create()
122+
.put("bucketName", dbProperties.getBucketName())
123+
.put("collectionName", CollectionNames.PROFILE)
124+
.put("search", "%"+ search.toLowerCase()+"%")
125+
.put("limit", limit)
126+
.put("skip", skip))
127+
.scanConsistency(QueryScanConsistency.REQUEST_PLUS))
128+
.rowsAs(Profile.class);
129+
return ResponseEntity.status(HttpStatus.OK).body(profiles);
130+
}
130131
}

src/main/java/org/couchbase/quickstart/models/Profile.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.couchbase.quickstart.models;
22

3+
import org.mindrot.jbcrypt.*;
4+
35
public class Profile {
46
private String pid;
57
private String firstName, lastName, email, password;
@@ -18,7 +20,7 @@ public class Profile {
1820

1921
public String getPassword() { return password; }
2022
public void setPassword(String password) {
21-
this.password = password;
23+
this.password = BCrypt.hashpw(password, BCrypt.gensalt());
2224
}
2325

2426
public Profile() { }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.couchbase.quickstart.models;
2+
3+
import java.util.UUID;
4+
5+
public class ProfileRequest {
6+
7+
private String firstName, lastName, email, password;
8+
9+
public String getFirstName() { return firstName; }
10+
public void setFirstName(String firstName) { this.firstName = firstName; }
11+
12+
public String getLastName() { return lastName; }
13+
public void setLastName(String lastName) { this.lastName = lastName; }
14+
15+
public String getEmail() { return email; }
16+
public void setEmail(String email) { this.email = email; }
17+
18+
public String getPassword() { return password; }
19+
public void setPassword(String password) {
20+
this.password = password;
21+
}
22+
23+
public ProfileRequest() { }
24+
25+
public ProfileRequest(String firstName, String lastName, String email, String password){
26+
27+
this.firstName = firstName;
28+
this.lastName = lastName;
29+
this.email = email;
30+
this.password = password;
31+
}
32+
33+
public Profile getProfile() {
34+
return new Profile(UUID.randomUUID().toString(), firstName, lastName, email, password);
35+
}
36+
}

src/main/java/org/couchbase/quickstart/models/ProfileResult.java

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

0 commit comments

Comments
 (0)