Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit 3f6dd47

Browse files
authored
Merge pull request #88 from SaltyNote/mongo
migrate to mongo
2 parents a67b1af + f815b4d commit 3f6dd47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+127
-506
lines changed

docker-compose.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
version: "3.8"
22

33
services:
4-
mysql:
5-
image: mariadb:10.4
6-
ports:
7-
- "3306:3306"
8-
environment:
9-
MYSQL_DATABASE: saltynote
10-
MYSQL_ROOT_PASSWORD: password
11-
volumes:
12-
- mysql_data:/var/lib/mysql/data
134

145
redis:
156
image: 'redis:7.0-alpine'
167
command: redis-server --requirepass 88888888
178
ports:
189
- '6379:6379'
1910

11+
mongodb:
12+
image: mongo:6-jammy
13+
restart: always
14+
environment:
15+
MONGO_INITDB_ROOT_USERNAME: saltynote
16+
MONGO_INITDB_ROOT_PASSWORD: password
17+
MONGO_INITDB_DATABASE: saltynote
18+
ports:
19+
- '27017:27017'
20+
volumes:
21+
- mongo_data:/data/db
22+
2023
volumes:
21-
mysql_data:
24+
mongo_data:

pom.xml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
<artifactId>spring-boot-starter-mail</artifactId>
5151
</dependency>
5252

53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-data-mongodb</artifactId>
56+
</dependency>
57+
5358
<dependency>
5459
<groupId>org.springframework.boot</groupId>
5560
<artifactId>spring-boot-devtools</artifactId>
@@ -84,19 +89,6 @@
8489
<artifactId>freemarker</artifactId>
8590
</dependency>
8691

87-
<dependency>
88-
<groupId>org.flywaydb</groupId>
89-
<artifactId>flyway-core</artifactId>
90-
</dependency>
91-
<dependency>
92-
<groupId>org.flywaydb</groupId>
93-
<artifactId>flyway-mysql</artifactId>
94-
</dependency>
95-
<dependency>
96-
<groupId>org.mariadb.jdbc</groupId>
97-
<artifactId>mariadb-java-client</artifactId>
98-
<version>3.1.3</version>
99-
</dependency>
10092
<dependency>
10193
<groupId>org.projectlombok</groupId>
10294
<artifactId>lombok</artifactId>

script/mysql.sh

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

src/main/java/com/saltynote/service/ServiceApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
78
import org.springframework.cache.annotation.EnableCaching;
89
import org.springframework.context.annotation.Bean;
910

10-
@SpringBootApplication
11+
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
1112
@EnableCaching
1213
public class ServiceApplication {
1314

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.saltynote.service.configure;
22

3-
import com.saltynote.service.generator.IdGenerator;
4-
import com.saltynote.service.generator.SnowflakeIdGenerator;
53
import org.springframework.beans.factory.annotation.Value;
6-
import org.springframework.context.annotation.Bean;
74
import org.springframework.context.annotation.Configuration;
85

96
@Configuration
@@ -15,9 +12,4 @@ public class ServiceConfig {
1512
@Value("${saltynote.machine.id}")
1613
private int machineId;
1714

18-
@Bean
19-
public IdGenerator snowflakeIdGenerator() {
20-
return new SnowflakeIdGenerator(datacenterId, machineId);
21-
}
22-
2315
}

src/main/java/com/saltynote/service/controller/NoteController.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public NoteController(NoteService noteService, NoteConverter noteConverter) {
4343
}
4444

4545
@GetMapping("/note/{id}")
46-
public ResponseEntity<Note> getNoteById(@PathVariable("id") Long id, Authentication auth) {
46+
public ResponseEntity<Note> getNoteById(@PathVariable("id") String id, Authentication auth) {
4747
Optional<Note> note = noteService.getById(id);
4848
checkNoteOwner(note, auth);
4949
return note.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
5050
}
5151

5252
@RequestMapping(value = "/note/{id}", method = { RequestMethod.POST, RequestMethod.PUT })
53-
public ResponseEntity<Note> updateNoteById(@PathVariable("id") Long id, @RequestBody NoteDto noteDto,
53+
public ResponseEntity<Note> updateNoteById(@PathVariable("id") String id, @RequestBody NoteDto noteDto,
5454
Authentication auth) {
5555
Optional<Note> queryNote = noteService.getById(id);
5656
checkNoteOwner(queryNote, auth);
@@ -59,9 +59,7 @@ public ResponseEntity<Note> updateNoteById(@PathVariable("id") Long id, @Request
5959
noteTobeUpdate.setNote(noteDto.getNote());
6060
}
6161

62-
if (StringUtils.isNotBlank(noteDto.getTags())) {
63-
noteTobeUpdate.setTags(noteDto.getTags());
64-
}
62+
noteTobeUpdate.setTags(noteDto.getTags());
6563

6664
if (StringUtils.isNotBlank(noteDto.getHighlightColor())) {
6765
noteTobeUpdate.setHighlightColor(noteDto.getHighlightColor());
@@ -71,7 +69,7 @@ public ResponseEntity<Note> updateNoteById(@PathVariable("id") Long id, @Request
7169
}
7270

7371
@DeleteMapping("/note/{id}")
74-
public ResponseEntity<ServiceResponse> deleteNoteById(@PathVariable("id") Long id, Authentication auth) {
72+
public ResponseEntity<ServiceResponse> deleteNoteById(@PathVariable("id") String id, Authentication auth) {
7573
Optional<Note> note = noteService.getById(id);
7674
checkNoteOwner(note, auth);
7775
noteService.delete(note.get());
@@ -82,7 +80,7 @@ public ResponseEntity<ServiceResponse> deleteNoteById(@PathVariable("id") Long i
8280
// requests will be
8381
// blocked by Chrome. Further investigation is required from me for this issue.
8482
@PostMapping("/note/{id}/delete")
85-
public ResponseEntity<ServiceResponse> postDeleteNoteById(@PathVariable("id") Long id, Authentication auth) {
83+
public ResponseEntity<ServiceResponse> postDeleteNoteById(@PathVariable("id") String id, Authentication auth) {
8684
return deleteNoteById(id, auth);
8785
}
8886

src/main/java/com/saltynote/service/controller/UserController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ResponseEntity<JwtUser> signup(@Valid @RequestBody UserNewRequest userNew
9393
SiteUser user = userNewRequest.toSiteUser();
9494
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
9595
user = userService.create(user);
96-
if (user.getId() != null && user.getId() > 0) {
96+
if (user.getId() != null && !user.getId().isBlank()) {
9797
vaultService.deleteById(vaultOp.get().getId());
9898
return ResponseEntity.ok(new JwtUser(user.getId(), user.getUsername()));
9999
}
@@ -199,7 +199,7 @@ public ResponseEntity<ServiceResponse> updatePassword(@Valid @RequestBody Passwo
199199
}
200200

201201
@DeleteMapping("/account/{id}")
202-
public ResponseEntity<ServiceResponse> accountDeletion(@PathVariable("id") Long userId, Authentication auth) {
202+
public ResponseEntity<ServiceResponse> accountDeletion(@PathVariable("id") String userId, Authentication auth) {
203203
JwtUser jwtUser = (JwtUser) auth.getPrincipal();
204204
if (!Objects.equals(userId, jwtUser.getId())) {
205205
throw new WebAppRuntimeException(HttpStatus.BAD_REQUEST, "User information is not confirmed");

src/main/java/com/saltynote/service/domain/Identifiable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public interface Identifiable {
44

5-
Long getId();
5+
String getId();
66

77
}

src/main/java/com/saltynote/service/domain/LoginUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class LoginUser extends User implements IdentifiableUser {
1111

1212
@Getter
13-
private final Long id;
13+
private final String id;
1414

1515
public LoginUser(SiteUser user) {
1616
super(user.getUsername(), user.getPassword(), Collections.emptyList());

src/main/java/com/saltynote/service/domain/VaultEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@Accessors(chain = true)
99
public class VaultEntity {
1010

11-
private Long userId;
11+
private String userId;
1212

1313
private String secret;
1414

0 commit comments

Comments
 (0)