Skip to content

Commit

Permalink
[#70] feat(OldestCursor): 장르용 커서 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerinhwang-sailin committed Jan 18, 2025
1 parent 2ca7ee9 commit cbc107e
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.napzak.domain.genre.api.dto.request.cursor;

import com.napzak.global.common.exception.NapzakException;
import com.napzak.global.common.exception.code.ErrorCode;

public class OldestCursor {
private final Long id;

public OldestCursor(Long id) {
this.id = id;
}

public Long getId() {
return id;
}

// O-{id}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder();
return stringBuilder
.append("O-")
.append(id)
.toString();
}

public static OldestCursor fromString(String cursor) {
if (!cursor.startsWith("O-")) {
throw new NapzakException(ErrorCode.INVALID_CURSOR_FORMAT);
}
String[] split = cursor.split("-");

if (split.length != 2) {
throw new NapzakException(ErrorCode.INVALID_CURSOR_FORMAT);
}
final long id;

try{
id = Long.parseLong(split[1]);
} catch (NumberFormatException e) {
throw new NapzakException(ErrorCode.INVALID_CURSOR_FORMAT);
}
return new OldestCursor(id);
}
}

0 comments on commit cbc107e

Please sign in to comment.