Skip to content

Commit

Permalink
#87 feat: 대체키 생성기
Browse files Browse the repository at this point in the history
IdGenerator -> TokenGenerator

기존 Id 생성 역할을 Token 생성으로 변경
  • Loading branch information
rivkode committed Jun 10, 2024
1 parent e3a0d4d commit 11a491f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.seoultech.synergybe.domain.common.generator;

public interface TokenGenerator {
String generateToken(IdPrefix idPrefix);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.seoultech.synergybe.domain.common.idgenerator;
package com.seoultech.synergybe.domain.common.generator;

import com.fasterxml.uuid.Generators;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class IdGeneratorUUID {
public class TokenGeneratorUUID implements TokenGenerator {

public String generateId(IdPrefix idPrefix) {
public String generateToken(IdPrefix idPrefix) {
UUID originUuid = Generators.timeBasedGenerator().generate();
String[] uuidArr = originUuid.toString().split("-");
String uuidStr = uuidArr[2] + uuidArr[1] + uuidArr[0] + uuidArr[3] + uuidArr[4];
String uuid = idPrefix.getValue() + "-" + uuidStr;
String uuid = idPrefix.getValue() + "_" + uuidStr;
return uuid;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.seoultech.synergybe.domain.common.idgenerator;
package com.seoultech.synergybe.domain.common.generator;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
public class IdGeneratorUUIDTest {
public class TokenGeneratorUUIDTest {
@Autowired
IdGenerator idGenerator;

Expand All @@ -19,7 +16,7 @@ void generateUUID() {
// List<String> list = new ArrayList<>();

for (int i = 0; i < 100; i++) {
String postId = idGenerator.generateId(IdPrefix.POST);
Long postId = idGenerator.generateId();
System.out.println("postId : " + i + " 번째 : "+ postId);
// list.add(postId);
}
Expand Down

0 comments on commit 11a491f

Please sign in to comment.