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

Null 358 email verfication #33

Merged
merged 17 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6a6cbc2
feat: api doc ์ž‘์„ฑ ๋ฐ ์„ค์ • ํŒŒ์ผ ์ˆ˜์ •
BaeJinho4028 Sep 16, 2024
b51ab65
feat: dto ๋ฐ controller ์ž‘์„ฑ
BaeJinho4028 Sep 16, 2024
8144bab
feat: ์ด๋ฉ”์ผ ์ „์†ก ๊ธฐ๋Šฅ ๊ตฌํ˜„
BaeJinho4028 Sep 17, 2024
2e83d67
feat: DB ๋ฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๊ตฌํ˜„
BaeJinho4028 Sep 17, 2024
cc32ad8
fix: test yml ์ˆ˜์ •
BaeJinho4028 Sep 17, 2024
23bf9f6
refactor: dto ๋ฐ ์˜ˆ์™ธ ์ˆ˜์ •
BaeJinho4028 Sep 17, 2024
60c237a
feat: ์œ ์ € ์ •๋ณด์— ์ด๋ฆ„, ์ „ํ™”๋ฒˆํ˜ธ ์ถ”๊ฐ€
BaeJinho4028 Sep 17, 2024
c3f696f
NULL-354 feat: ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ, ํƒˆํ‡ด ๊ธฐ๋Šฅ ์ถ”๊ฐ€
BaeJinho4028 Sep 17, 2024
5ba00a9
chore: ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ ์ •๋ณด ์‚ญ์ œ
BaeJinho4028 Sep 17, 2024
b138618
fix: ์˜ค๋ฅ˜ ์ˆ˜์ •
BaeJinho4028 Sep 17, 2024
c54e066
fix: ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜1
BaeJinho4028 Sep 18, 2024
26eb896
fix: ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜2 - ํšŒ์› ํƒˆํ‡ด์‹œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ ์‚ญ์ œ
BaeJinho4028 Sep 18, 2024
a5db258
fix: ์ถฉ๋Œ ํ•ด๊ฒฐ
BaeJinho4028 Sep 19, 2024
d3471c8
fix: ํ”ผ๋“œ๋ฐฑ ์ ์šฉ 3
BaeJinho4028 Sep 21, 2024
72a1f1f
fix: ์ด๋ฉ”์ผ ์ค‘๋ณต ์ฒดํฌ ์ถ”๊ฐ€
BaeJinho4028 Sep 21, 2024
839519e
fix: ํšŒ์›๊ฐ€์ž…, ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ ์‹œ ์ด๋ฉ”์ผ ์ฒดํฌ ์ถ”๊ฐ€
BaeJinho4028 Sep 21, 2024
4067de4
fix: ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ 4
BaeJinho4028 Sep 21, 2024
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ dependencies {
// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'

// Email
implementation 'org.springframework.boot:spring-boot-starter-mail'

// HealthCheck
implementation 'org.springframework.boot:spring-boot-starter-actuator'

// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/user/login", "/user/register", "/user/refresh").permitAll()
.requestMatchers("/user/login", "/user/register", "/user/refresh", "/user/email/**").permitAll()
.requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
.requestMatchers("/actuator/health").permitAll()
.anyRequest().authenticated()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.oatnote.event;

public record UserWithdrawEvent(
String userId
) {

}
24 changes: 18 additions & 6 deletions src/main/java/com/example/oatnote/memotag/MemoTagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public void deleteTag(String tagId, String userId) {
tagService.deleteTag(tag);
}

public void deleteAllUserData(String userId) {
memoTagRelationService.deleteAllUserData(userId);
memoService.deleteAllUserData(userId);
tagService.deleteAllUserData(userId);
}

Memo createMemoTags(ProcessedMemoResponse aiMemoTagsResponse, String userId) {
Memo memo = new Memo(
aiMemoTagsResponse.content(),
Expand All @@ -229,26 +235,32 @@ List<Tag> updateMemosTagsRelations(
String userId
) {
List<Tag> tags = new ArrayList<>();
for (var linkedTagId : aiMemoTagsResponse.parentTagIds()) {
tags.add(tagService.getTag(linkedTagId, userId));
memoTagRelationService.createRelation(savedMemo.getId(), linkedTagId, IS_LINKED_MEMO_TAG, userId);
List<String> parentTagIds = tagService.getParentTagsIds(linkedTagId);
createParentTagsRelations(savedMemo.getId(), parentTagIds, userId);
}
for (var addRelation : aiMemoTagsResponse.tagsRelations().added()) {
tagService.createRelation(addRelation.parentId(), addRelation.childId());
tagService.createRelation(addRelation.parentId(), addRelation.childId(), userId);
}
for (var deletedRelation : aiMemoTagsResponse.tagsRelations().deleted()) {
tagService.deleteRelation(deletedRelation.parentId(), deletedRelation.childId());
}
for (var linkedTagId : aiMemoTagsResponse.parentTagIds()) {
tags.add(tagService.getTag(linkedTagId, userId));
memoTagRelationService.createRelation(savedMemo.getId(), linkedTagId, IS_LINKED_MEMO_TAG);
memoTagRelationService.createRelation(savedMemo.getId(), linkedTagId, IS_LINKED_MEMO_TAG, userId);
List<String> parentTagIds = tagService.getParentTagsIds(linkedTagId);
createParentTagsRelations(savedMemo.getId(), parentTagIds);
createParentTagsRelations(savedMemo.getId(), parentTagIds, userId);
}
return tags;
}

void createParentTagsRelations(String memoId, List<String> parentTagIds) {
void createParentTagsRelations(String memoId, List<String> parentTagIds, String userId) {
if (parentTagIds != null && !parentTagIds.isEmpty()) {
for (var tagId : parentTagIds) {
memoTagRelationService.createRelation(memoId, tagId, !IS_LINKED_MEMO_TAG);
createParentTagsRelations(memoId, tagService.getParentTagsIds(tagId));
memoTagRelationService.createRelation(memoId, tagId, !IS_LINKED_MEMO_TAG, userId);
createParentTagsRelations(memoId, tagService.getParentTagsIds(tagId), userId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.oatnote.memotag;

import java.util.ArrayList;

import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import com.example.oatnote.event.UserRegisteredEvent;
import com.example.oatnote.memotag.service.tag.model.Tag;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class UserWithdrawalListener {

private MemoTagService memoTagService;

@EventListener
public void handleUserWithdrawalEvent(UserRegisteredEvent event) {
deleteAllUserData(event.userId());
}

private void deleteAllUserData(String userId) {
memoTagService.deleteAllUserData(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface MemoRepository extends MongoRepository<Memo, String> {

@Query("{ 'content' : { $regex: ?0, $options: 'i' }, 'userId' : ?1 }")
List<Memo> findByContentRegexAndUserId(String regex, String userId);

void deleteByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ public Memo updateMemo(Memo memo) {
public void deleteMemo(Memo memo) {
memoRepository.delete(memo);
}

public void deleteAllUserData(String userId) {
memoRepository.deleteByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface MemoTagRelationRepository extends MongoRepository<MemoTagRelati
void deleteByTagId(String tagId);

Integer countByTagId(String tagId);

void deleteByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class MemoTagRelationService {

private final MemoTagRelationRepository memoTagRelationRepository;

public void createRelation(String memoId, String tagId, boolean isLinked) {
MemoTagRelation memoTagRelation = new MemoTagRelation(memoId, tagId, isLinked);
public void createRelation(String memoId, String tagId, boolean isLinked, String userId) {
MemoTagRelation memoTagRelation = new MemoTagRelation(memoId, tagId, isLinked, userId);
memoTagRelationRepository.save(memoTagRelation);
}

Expand Down Expand Up @@ -48,4 +48,8 @@ public void deleteRelationsByTagId(String tagId) {
public Integer countMemos(String tagId) {
return memoTagRelationRepository.countByTagId(tagId);
}

public void deleteAllUserData(String userId) {
memoTagRelationRepository.deleteByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ public class MemoTagRelation {
@Field("isL")
private boolean isLinked;

public MemoTagRelation(String memoId, String tagId, boolean isLinked) {
@Indexed
@Field("uId")
private String userId;

public MemoTagRelation(String memoId, String tagId, boolean isLinked, String userId) {
this.id = UUID.randomUUID().toString();
this.memoId = memoId;
this.tagId = tagId;
this.isLinked = isLinked;
this.userId = userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
Expand All @@ -15,7 +16,9 @@ public interface TagRepository extends MongoRepository<Tag, String> {

Optional<Tag> findByIdAndUserId(String tagId, String userId);

Page<Tag> findByIdInAndUserId(List<String> tagsIds, PageRequest pageRequest, String userId);
Page<Tag> findByIdInAndUserId(List<String> tagsIds, Pageable pageable, String userId);

List<Tag> findByIdInAndUserId(List<String> tagIds, String userId, Sort sort);
List<Tag> findByIdInAndUserId(List<String> tagIds, String userId);

void deleteByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Tag saveTag(Tag tag) {
}

public List<Tag> getTags(List<String> tagIds, String userId) {
return tagRepository.findByIdInAndUserId(tagIds, userId, Sort.by(Sort.Direction.ASC, "name"));
return tagRepository.findByIdInAndUserId(tagIds, userId);
}

public Page<Tag> getPagedTags(List<String> tagsIds, PageRequest pageRequest, String userId) {
Expand All @@ -49,14 +49,18 @@ public void createTagEdge(TagEdge tagEdge) {
tagEdgeService.createTagEdge(tagEdge);
}

public void createRelation(String parentTagId, String childTagId) {
tagsRelationService.createRelation(parentTagId, childTagId);
public void createRelation(String parentTagId, String childTagId, String userId) {
tagsRelationService.createRelation(parentTagId, childTagId, userId);
}

public List<String> getChildTagsIds(String parentTagId) {
return tagsRelationService.getChildTagsIds(parentTagId);
}

public List<Tag> getChildTags(String parentTagId, String userId) {
return getTags(getChildTagsIds(parentTagId), userId);
}

public List<String> getParentTagsIds(String childTagId) {
return tagsRelationService.getParentTagsIds(childTagId);
}
Expand All @@ -65,7 +69,9 @@ public void deleteRelation(String parentTagId, String childTagId) {
tagsRelationService.deleteRelation(parentTagId, childTagId);
}

public List<Tag> getChildTags(String parentTagId, String userId) {
return getTags(getChildTagsIds(parentTagId), userId);
public void deleteAllUserData(String userId) {
tagEdgeService.deleteAllUserData(userId);
tagsRelationService.deleteAllUserData(userId);
tagRepository.deleteByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

@Component
@RequiredArgsConstructor
public class CreateRootTagListener {
public class UserRegistrationListener {

private final TagService tagService;

@EventListener
public void handleUserRegisteredEvent(UserRegisteredEvent event) {
public void handleUserRegistrationEvent(UserRegisteredEvent event) {
createRootTag(event.userId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public void createTagEdge(TagEdge tagEdge) {
}
tagEdgeRepository.insert(tagEdge);
}

public void deleteAllUserData(String userId) {
tagEdgeRepository.deleteByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface TagsRelationRepository extends MongoRepository<TagsRelation, St
List<TagsRelation> findByParentTagId(String parentTagId);

List<TagsRelation> findByChildTagId(String parentTagId);

void deleteByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class TagsRelationService {

private final TagsRelationRepository tagsRelationRepository;

public void createRelation(String parentTagId, String childTagId) {
TagsRelation tagsRelation = new TagsRelation(parentTagId, childTagId);
public void createRelation(String parentTagId, String childTagId, String userId) {
TagsRelation tagsRelation = new TagsRelation(parentTagId, childTagId, userId);
tagsRelationRepository.insert(tagsRelation);
}

Expand All @@ -34,4 +34,8 @@ public List<String> getChildTagsIds(String parentTagId) {
.map(TagsRelation::getChildTagId)
.toList();
}

public void deleteAllUserData(String userId) {
tagsRelationRepository.deleteByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ public class TagsRelation {
@Field("cTId")
private String childTagId;

public TagsRelation(String parentTagId, String childTagId) {
@Indexed
@Field("uId")
private String userId;

public TagsRelation(String parentTagId, String childTagId, String userId) {
this.id = UUID.randomUUID().toString();
this.parentTagId = parentTagId;
this.childTagId = childTagId;
this.userId = userId;
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/example/oatnote/user/UserApiDoc.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.example.oatnote.user;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.example.oatnote.user.dto.CheckEmailRequest;
import com.example.oatnote.user.dto.SendCodeRequest;
import com.example.oatnote.user.dto.FindPasswordRequest;
import com.example.oatnote.user.dto.LoginUserRequest;
import com.example.oatnote.user.dto.LoginUserResponse;
import com.example.oatnote.user.dto.RefreshUserRequest;
import com.example.oatnote.user.dto.RefreshUserResponse;
import com.example.oatnote.user.dto.RegisterUserRequest;
import com.example.oatnote.user.dto.VerifyCodeRequest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -52,4 +58,58 @@ ResponseEntity<LoginUserResponse> login(
ResponseEntity<RefreshUserResponse> refreshAccessToken(
@RequestBody @Valid RefreshUserRequest refreshUserRequest
);

@Operation(summary = "์ด๋ฉ”์ผ ์ค‘๋ณต ์ฒดํฌ")
@ApiResponses({
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
})
@PostMapping("/user/checkEmail")
ResponseEntity<Void> checkEmailDuplication(
@RequestBody @Valid CheckEmailRequest checkEmailRequest
);

@Operation(summary = "์ด๋ฉ”์ผ ์ธ์ฆ ์ฝ”๋“œ ์ „์†ก")
@ApiResponses({
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
})
@PostMapping("/user/sendCode")
ResponseEntity<Void> sendCode(
@RequestBody @Valid SendCodeRequest sendCodeRequest
);

@Operation(summary = "์ด๋ฉ”์ผ ์ธ์ฆ ์ฝ”๋“œ ํ™•์ธ")
@ApiResponses({
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
})
@PostMapping("/user/verifyCode")
ResponseEntity<Void> verifyCode(
@RequestBody @Valid VerifyCodeRequest verifyCodeRequest
);

@Operation(summary = "๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ")
@ApiResponses({
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
})
@PostMapping("/user/findPassword")
ResponseEntity<Void> findPassword(
@RequestBody @Valid FindPasswordRequest findPasswordRequest
);

@Operation(summary = "ํšŒ์› ํƒˆํ‡ด")
@ApiResponses({
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))),
})
@DeleteMapping("/user")
ResponseEntity<Void> withdraw(
@AuthenticationPrincipal String userId
);
}
Loading
Loading