Skip to content

Commit 14cb2bb

Browse files
committed
#111 fix: 모든 엔티티 대체키 반영
- 기존 string type id -> **token - id type -> long
1 parent 1398d97 commit 14cb2bb

File tree

30 files changed

+174
-104
lines changed

30 files changed

+174
-104
lines changed

src/main/java/com/seoultech/synergybe/domain/apply/controller/ApplyController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public class ApplyController {
2121
private final ApplyService applyService;
2222

2323
@Operation(summary = "프로젝트 지원 생성", description = "프로젝트와 user가 매핑되어 지원됩니다.")
24-
@PostMapping(value = "/{projectId}")
25-
public ResponseEntity<GetApplyResponse> createApply(@PathVariable("projectId") String projectId, @LoginUser String userId) {
24+
@PostMapping(value = "/{projectToken}")
25+
public ResponseEntity<GetApplyResponse> createApply(@PathVariable("projectToken") String projectToken, @LoginUser String userToken) {
2626

27-
return ResponseEntity.status(HttpStatus.CREATED).body(applyService.createApply(userId, projectId));
27+
return ResponseEntity.status(HttpStatus.CREATED).body(applyService.createApply(userToken, projectToken));
2828
}
2929

3030
@Operation(summary = "프로젝트 지원 삭제", description = "지원이 삭제됩니다.")

src/main/java/com/seoultech/synergybe/domain/apply/dto/response/GetApplyResponse.java

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

77
@Builder
88
public record GetApplyResponse(
9-
String applyId,
9+
String applyToken,
1010
String status
1111
) {
1212
@QueryProjection

src/main/java/com/seoultech/synergybe/domain/apply/service/ApplyService.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ public class ApplyService {
3636
private final TokenGenerator tokenGenerator;
3737

3838
@Transactional
39-
public GetApplyResponse createApply(String userId, String projectId) {
40-
Project project = projectService.findProjectById(projectId);
41-
User user = userService.getUser(userId);
39+
public GetApplyResponse createApply(String userToken, String projectToken) {
40+
Project project = projectService.findProjectById(projectToken);
41+
User user = userService.getUser(userToken);
4242
Long applyId = idGenerator.generateId();
4343
String applyToken = tokenGenerator.generateToken(IdPrefix.APPLY);
4444

4545
Apply apply = Apply.builder()
46-
.id(applyId).user(user).project(project)
46+
.id(applyId)
47+
.applyToken(applyToken)
48+
.user(user)
49+
.project(project)
4750
.build();
4851
Apply savedApply = applyRepository.save(apply);
4952

@@ -52,7 +55,7 @@ public GetApplyResponse createApply(String userId, String projectId) {
5255
// notificationService.send(leader, NotificationType.PROJECT_APPLY, "프로젝트 신청이 완료되었습니다.", projectId);
5356

5457
return GetApplyResponse.builder()
55-
.applyId(savedApply.getId())
58+
.applyToken(savedApply.getApplyToken())
5659
.build();
5760
}
5861

@@ -85,8 +88,9 @@ public void updateApplyStatusToAccept(String leaderId, String applyUserId, Strin
8588

8689

8790
// projectUser 추가
88-
String projectUserId = idGenerator.generateId(IdPrefix.PROJECT_USER);
89-
ProjectUser projectUser = new ProjectUser(projectUserId, project, user);
91+
Long projectUserId = idGenerator.generateId();
92+
String projectUserToken = tokenGenerator.generateToken(IdPrefix.PROJECT_USER);
93+
ProjectUser projectUser = new ProjectUser(projectUserId, projectUserToken, project, user);
9094
project.getProjectUsers().add(projectUser);
9195
projectUserRepository.save(projectUser);
9296
// User applyUser = userService.getUser(userId);
@@ -122,7 +126,7 @@ public void updateApplyStatusToReject(String leaderId, String applyUserId, Strin
122126

123127
public GetListApplyResponse getMyApplyList(String userId) {
124128
User user = userService.getUser(userId);
125-
List<Apply> applies = applyRepository.findAllProcessByUserId(user.getId());
129+
List<Apply> applies = applyRepository.findAllProcessByUserId(user.getUserToken());
126130

127131
return ApplyMapperEntityToDto.applyListToResponse(applies);
128132
}

src/main/java/com/seoultech/synergybe/domain/comment/Comment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ public class Comment extends BaseTime {
5555
private IsDeleted isDeleted = new IsDeleted(IS_DELETED_DEFAULT);
5656

5757
@Builder
58-
public Comment(String id, String comment, User user, Post post, Comment parentComment, int depth, int orderNumber,
58+
public Comment(Long id, String commentToken, String comment, User user, Post post, Comment parentComment, int depth, int orderNumber,
5959
boolean isChildComment) {
6060
this.id = id;
61+
this.commentToken = commentToken;
6162
this.comment = new CommentContent(comment);
6263
this.user = user;
6364
this.post = post;

src/main/java/com/seoultech/synergybe/domain/comment/controller/CommentController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public class CommentController {
2727

2828
@Operation(summary = "Comment 생성", description = "게시글에 댓글이 생성되며, 사용자와 시간이 포함됩니다.")
2929
@PostMapping
30-
public ResponseEntity<GetCommentResponse> createComment(@Valid @RequestBody CreateCommentRequest request, @LoginUser String userId) {
30+
public ResponseEntity<GetCommentResponse> createComment(@Valid @RequestBody CreateCommentRequest request, @LoginUser String userToken) {
3131

32-
return ResponseEntity.status(HttpStatus.CREATED).body(commentService.createComment(userId, request));
32+
return ResponseEntity.status(HttpStatus.CREATED).body(commentService.createComment(userToken, request));
3333
}
3434

3535
@Operation(summary = "Comment 수정", description = "댓글이 요청에 대해 수정됩니다.")

src/main/java/com/seoultech/synergybe/domain/comment/service/CommentService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.seoultech.synergybe.domain.comment.repository.CommentRepository;
99
import com.seoultech.synergybe.domain.common.generator.IdGenerator;
1010
import com.seoultech.synergybe.domain.common.generator.IdPrefix;
11+
import com.seoultech.synergybe.domain.common.generator.TokenGenerator;
1112
import com.seoultech.synergybe.domain.common.paging.ListResponse;
1213
import com.seoultech.synergybe.domain.notification.service.NotificationService;
1314
import com.seoultech.synergybe.domain.post.Post;
@@ -25,31 +26,31 @@
2526
@RequiredArgsConstructor
2627
public class CommentService {
2728
private final CommentRepository commentRepository;
28-
2929
private final PostReader postReader;
3030
private final UserService userService;
31-
3231
private final NotificationService notificationService;
3332
private final IdGenerator idGenerator;
33+
private final TokenGenerator tokenGenerator;
3434

3535
public GetCommentResponse createComment(String userId, CreateCommentRequest request) {
3636
Post post = postReader.read(request.postId());
3737
User user = userService.getUser(userId);
38-
String commentId = idGenerator.generateId(IdPrefix.COMMENT);
38+
Long commentId = idGenerator.generateId();
39+
String commentToken = tokenGenerator.generateToken(IdPrefix.COMMENT);
3940

4041
Comment comment = Comment.builder()
4142
.id(commentId)
43+
.commentToken(commentToken)
4244
.comment(request.comment())
4345
.post(post).user(user)
4446
.build();
4547

46-
4748
Comment savedComment = commentRepository.save(comment);
4849
savedComment.addPost(post);
4950
// User postUser = post.getUser();
5051
// notificationService.send(postUser, NotificationType.COMMENT, "댓글이 생성되었습니다", post.getId());
5152
return GetCommentResponse.builder()
52-
.commentId(savedComment.getId())
53+
.commentId(savedComment.getCommentToken())
5354
.build();
5455
}
5556

src/main/java/com/seoultech/synergybe/domain/follow/Follow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public class Follow extends BaseTime {
3232
private FollowStatus status;
3333

3434
@Builder
35-
public Follow(Long id, User follower, User following) {
35+
public Follow(Long id, String followToken, User follower, User following) {
3636
this.id = id;
37+
this.followToken = followToken;
3738
this.follower = follower;
3839
this.following = following;
3940
this.status = FollowStatus.FOLLOW;

src/main/java/com/seoultech/synergybe/domain/follow/controller/FollowController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class FollowController {
2424
private final UserService userService;
2525

2626
@Operation(summary = "follow 신청, 취소", description = "팔로우를 신청 및 취소하며 팔로우 타입에 따라 팔로우 상태가 변화하므로 PUT 메서드 하나로 관리됩니다.")
27-
@PutMapping(value = "/{followingId}")
28-
public ResponseEntity<GetFollowResponse> updateFollow(@PathVariable("followingId") String followingId, @RequestBody CreateFollowRequest type, @LoginUser String userId) {
27+
@PutMapping(value = "/{followingToken}")
28+
public ResponseEntity<GetFollowResponse> updateFollow(@PathVariable("followingToken") String followingToken, @RequestBody CreateFollowRequest type, @LoginUser String userId) {
2929
User user = userService.getUser(userId);
3030

31-
return ResponseEntity.status(HttpStatus.OK).body(followService.updateFollow(user, followingId, type));
31+
return ResponseEntity.status(HttpStatus.OK).body(followService.updateFollow(user, followingToken, type));
3232

3333
}
3434

src/main/java/com/seoultech/synergybe/domain/follow/service/FollowService.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.seoultech.synergybe.domain.common.generator.IdGenerator;
44
import com.seoultech.synergybe.domain.common.generator.IdPrefix;
5+
import com.seoultech.synergybe.domain.common.generator.TokenGenerator;
56
import com.seoultech.synergybe.domain.common.paging.ListResponse;
67
import com.seoultech.synergybe.domain.follow.Follow;
78
import com.seoultech.synergybe.domain.follow.FollowStatus;
@@ -27,6 +28,7 @@ public class FollowService {
2728
private final UserService userService;
2829
private final NotificationService notificationService;
2930
private final IdGenerator idGenerator;
31+
private final TokenGenerator tokenGenerator;
3032

3133
public List<String> findFollowingIdsByUserId(String userId) {
3234
return followRepository.findFollowingIdsByFollowerId(userId);
@@ -35,12 +37,12 @@ public List<String> findFollowingIdsByUserId(String userId) {
3537
/**
3638
*
3739
* @param user 신청한 유저
38-
* @param followingId 신청 받은 유저
40+
* @param followingToken 신청 받은 유저
3941
* @param type
4042
* @return
4143
*/
4244
@Transactional
43-
public GetFollowResponse updateFollow(User user, String followingId, CreateFollowRequest type) {
45+
public GetFollowResponse updateFollow(User user, String followingToken, CreateFollowRequest type) {
4446
FollowStatus status;
4547
if (type.followType().equals("follow")) {
4648
status = FollowStatus.FOLLOW;
@@ -49,7 +51,7 @@ public GetFollowResponse updateFollow(User user, String followingId, CreateFollo
4951
}
5052

5153
try {
52-
Follow updatedFollow = update(user, followingId, status);
54+
Follow updatedFollow = update(user, followingToken, status);
5355
GetFollowResponse getFollowResponse = GetFollowResponse.builder().build();
5456

5557
return getFollowResponse;
@@ -62,7 +64,7 @@ public GetFollowResponse updateFollow(User user, String followingId, CreateFollo
6264
}
6365

6466
public synchronized Follow update(User user, String followingId, FollowStatus status) {
65-
Optional<Follow> followOptional = followRepository.findByFollowerIdAndFollowingId(user.getId(), followingId);
67+
Optional<Follow> followOptional = followRepository.findByFollowerIdAndFollowingId(user.getUserToken(), followingId);
6668

6769
if (followOptional.isPresent()) {
6870
followOptional.get().updateStatus(status);
@@ -72,9 +74,11 @@ public synchronized Follow update(User user, String followingId, FollowStatus st
7274
return followOptional.get();
7375
} else {
7476
User following = userService.getUser(followingId);
75-
String followId = idGenerator.generateId(IdPrefix.FOLLOW);
77+
Long followId = idGenerator.generateId();
78+
String followToken = tokenGenerator.generateToken(IdPrefix.FOLLOW);
7679
Follow follow = Follow.builder()
7780
.id(followId)
81+
.followToken(followToken)
7882
.follower(user)
7983
.following(following)
8084
.build();

src/main/java/com/seoultech/synergybe/domain/library/scheduler/PublicLibraryScheduler.java

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

33
import com.seoultech.synergybe.domain.common.generator.IdGenerator;
44
import com.seoultech.synergybe.domain.common.generator.IdPrefix;
5+
import com.seoultech.synergybe.domain.common.generator.TokenGenerator;
56
import com.seoultech.synergybe.domain.library.domain.PublicLibrary;
67
import com.seoultech.synergybe.domain.library.domain.RawPublicLibrary;
78
import com.seoultech.synergybe.domain.library.repository.PublicLibraryRepository;
@@ -21,6 +22,7 @@ public class PublicLibraryScheduler {
2122
private final PublicLibraryRepository publicLibraryRepository;
2223
private final RawPublicLibraryRepository rawPublicLibraryRepository;
2324
private final IdGenerator idGenerator;
25+
private final TokenGenerator tokenGenerator;
2426

2527
@Scheduled(cron = "0 0 4 * * 6", zone = "Asia/Seoul")
2628
public void updatePublicLibrary() {
@@ -30,7 +32,8 @@ public void updatePublicLibrary() {
3032

3133
List<PublicLibrary> publicLibraries = rawPublicLibraryList.stream().map(
3234
rawPublicLibrary -> PublicLibrary.builder()
33-
.id(idGenerator.generateId(IdPrefix.PUBLIC_LIBRARY))
35+
.id(idGenerator.generateId())
36+
.publicLibraryToken(tokenGenerator.generateToken(IdPrefix.PUBLIC_LIBRARY))
3437
.name(rawPublicLibrary.getName())
3538
.address(rawPublicLibrary.getAddress())
3639
.telNumber(rawPublicLibrary.getTelNumber())

0 commit comments

Comments
 (0)