Skip to content

Commit

Permalink
fix: 자바스크립트에서 64비트 식별자를 정상적으로 수신하지 못하는 문제 해결
Browse files Browse the repository at this point in the history
64비트 TSID 식별자를 문자열로 인코딩하여 전달하는 방식으로 해결
  • Loading branch information
csct3434 committed Nov 21, 2023
1 parent 69c04a5 commit dbe3f73
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/alzzaipo/common/TsidUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.alzzaipo.common;

import com.github.f4b6a3.tsid.Tsid;

public class TsidUtil {

public static String toString(Long id) {
return Tsid.from(id).encode(62);
}

public static Long toLong(String id) {
return Tsid.decode(id, 62).toLong();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alzzaipo.notification.adapter.in.web.criterion;

import com.alzzaipo.common.MemberPrincipal;
import com.alzzaipo.common.TsidUtil;
import com.alzzaipo.common.Uid;
import com.alzzaipo.notification.adapter.in.web.criterion.dto.RegisterNotificationCriterionWebRequest;
import com.alzzaipo.notification.adapter.in.web.criterion.dto.UpdateNotificationCriterionWebRequest;
Expand Down Expand Up @@ -57,7 +58,7 @@ public ResponseEntity<String> updateNotificationCriterion(@AuthenticationPrincip
@RequestBody UpdateNotificationCriterionWebRequest dto) {
UpdateNotificationCriterionCommand command = new UpdateNotificationCriterionCommand(
principal.getMemberUID(),
new Uid(dto.getUid()),
new Uid(TsidUtil.toLong(dto.getUid())),
dto.getCompetitionRate(),
dto.getLockupRate());

Expand All @@ -68,10 +69,10 @@ public ResponseEntity<String> updateNotificationCriterion(@AuthenticationPrincip

@DeleteMapping("/delete")
public ResponseEntity<String> deleteNotificationCriterion(@AuthenticationPrincipal MemberPrincipal principal,
@RequestParam("uid") Long notificationCriterionUID) {
@RequestParam("uid") String uid) {
DeleteNotificationCriterionCommand command = new DeleteNotificationCriterionCommand(
principal.getMemberUID(),
new Uid(notificationCriterionUID));
new Uid(TsidUtil.toLong(uid)));

deleteNotificationCriterionUseCase.deleteNotificationCriterion(command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@NoArgsConstructor
public class UpdateNotificationCriterionWebRequest {

private Long uid;
private String uid;
private int competitionRate;
private int lockupRate;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.alzzaipo.notification.application.port.dto;

import com.alzzaipo.common.TsidUtil;
import lombok.Getter;

@Getter
public class NotificationCriterionView {

private Long uid;
private int competitionRate;
private int lockupRate;
private final String uid;
private final int competitionRate;
private final int lockupRate;

public NotificationCriterionView(Long uid, int competitionRate, int lockupRate) {
this.uid = uid;
this.uid = TsidUtil.toString(uid);
this.competitionRate = competitionRate;
this.lockupRate = lockupRate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alzzaipo.portfolio.adapter.in.web;

import com.alzzaipo.common.MemberPrincipal;
import com.alzzaipo.common.TsidUtil;
import com.alzzaipo.common.Uid;
import com.alzzaipo.portfolio.adapter.in.web.dto.RegisterPortfolioWebRequest;
import com.alzzaipo.portfolio.adapter.in.web.dto.UpdatePortfolioWebRequest;
Expand Down Expand Up @@ -64,10 +65,10 @@ public ResponseEntity<String> updateMemberPortfolio(@AuthenticationPrincipal Mem

@DeleteMapping("/delete")
public ResponseEntity<String> delete(@AuthenticationPrincipal MemberPrincipal principal,
@RequestParam("uid") Long portfolioUID) {
@RequestParam("uid") String uid) {
DeletePortfolioCommand command = new DeletePortfolioCommand(
principal.getMemberUID(),
new Uid(portfolioUID));
new Uid(TsidUtil.toLong(uid)));

deletePortfolioUseCase.deletePortfolio(command);

Expand All @@ -86,7 +87,7 @@ private RegisterPortfolioCommand toRegisterPortfolioCommand(MemberPrincipal prin

private UpdatePortfolioCommand toUpdateMemberPortfolioCommand(MemberPrincipal principal, UpdatePortfolioWebRequest dto) {
return new UpdatePortfolioCommand(
new Uid(dto.getUid()),
new Uid(TsidUtil.toLong(dto.getUid())),
principal.getMemberUID(),
dto.getStockCode(),
dto.getSharesCnt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@NoArgsConstructor
public class UpdatePortfolioWebRequest {

private Long uid;
private String uid;
private int stockCode;
private int sharesCnt;
private Long profit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.alzzaipo.portfolio.application.dto;

import com.alzzaipo.common.TsidUtil;
import lombok.Getter;

@Getter
public class PortfolioView {

private final Long uid;
private final String uid;

private final String stockName;

Expand All @@ -22,7 +23,7 @@ public class PortfolioView {
private final String memo;

public PortfolioView(Long uid, String stockName, int stockCode, int sharesCnt, Long profit, Long profitRate, String agents, String memo) {
this.uid = uid;
this.uid = TsidUtil.toString(uid);
this.stockName = stockName;
this.stockCode = stockCode;
this.sharesCnt = sharesCnt;
Expand Down

0 comments on commit dbe3f73

Please sign in to comment.