-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5b1f0b
commit 68d1b2e
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
YAPP-BE/src/main/java/yapp/domain/townMap/converter/PlaceConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package yapp.domain.townMap.converter; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import yapp.domain.townMap.dto.ThemePlaceDto; | ||
import yapp.domain.townMap.dto.response.ThemePlaceResponse; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class PlaceConverter { | ||
|
||
public ThemePlaceResponse toThemePlace( | ||
ThemePlaceDto themePlaceDto | ||
) { | ||
|
||
String[] placeInfo = getPlaceInfo(themePlaceDto.getName()); | ||
|
||
return ThemePlaceResponse.builder() | ||
.name(placeInfo[0]) | ||
.address(themePlaceDto.getAddress()) | ||
.x(themePlaceDto.getX()) | ||
.y(themePlaceDto.getY()) | ||
.subCategory((themePlaceDto.getTheme().getSubCategoryName())) | ||
.foodCategory(placeInfo[1]) | ||
.build(); | ||
} | ||
|
||
private String[] getPlaceInfo (String str) { | ||
Pattern pattern = Pattern.compile("\\[(.*?)\\]"); | ||
Matcher matcher = pattern.matcher(str); | ||
if(matcher.find()){ | ||
return new String[] { str.split("\\[")[0], matcher.group(1).trim() }; | ||
} | ||
return new String[] { str, null }; | ||
} | ||
|
||
} |