Skip to content

Commit

Permalink
Merge pull request #56 from kakao-tech-campus-2nd-step3/weekly/6
Browse files Browse the repository at this point in the history
[Weekly] 6주차 과제 PR
  • Loading branch information
sanghee0820 authored Oct 11, 2024
2 parents 84bdf32 + 348f9b9 commit b2950b9
Show file tree
Hide file tree
Showing 52 changed files with 694 additions and 178 deletions.
22 changes: 19 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,37 @@ repositories {
}

dependencies {

//Spring
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

//Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
testImplementation 'org.springframework.security:spring-security-test'

//JWT
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.3'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
//Database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.h2database:h2'

//QueryDSL
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"


testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/team7/inplace/InplaceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import team7.inplace.token.persistence.RefreshTokenRepository;

@SpringBootApplication
@ConfigurationPropertiesScan
@EnableJpaRepositories(
basePackages = "team7.inplace",
excludeFilters = @ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
classes = {RefreshTokenRepository.class}
)
)
public class InplaceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = PRIVATE)
public class AddressUtil {
private static final String ADDRESS_REGEX = "[가-힣0-9]+(?:도|시|구|군|읍|면|동|리|로|길)[^#,\\n()]+(?:동|읍|면|리|로|길|호|층|번지)[^#,\\n()]+";
public final class AddressUtil {
private static final String ADDRESS_REGEX = "[가-힣0-9]+(?:도|시|구|군|읍|면|동|리|로|길)\\s*[0-9]*(?:동|읍|면|리|로|길)?\\s*[0-9]+";

public static String extractAddress(JsonNode snippet) {
public static String extractAddressFromJsonNode(JsonNode snippet) {

String videoDescription = snippet.path("description").asText();

return extractAddressFromString(videoDescription);
}

public static String extractAddressFromString(String string) {
Pattern pattern = Pattern.compile(ADDRESS_REGEX);
Matcher matcher = pattern.matcher(videoDescription);
Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
return matcher.group();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<CrawlingInfo> crawlAllVideos() {
var videoSnippets = youtubeClient.getVideos(channel.getPlayListUUID(), channel.getLastVideoUUID());

var videoAddresses = videoSnippets.stream()
.map(AddressUtil::extractAddress)
.map(AddressUtil::extractAddressFromJsonNode)
.toList();

var placeNodes = videoAddresses.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import java.util.List;
import java.util.Objects;
import team7.inplace.crawling.client.dto.PlaceNode;
import team7.inplace.place.application.command.PlacesCommand;
import team7.inplace.video.application.command.VideoCommand;
Expand All @@ -19,7 +20,12 @@ public List<VideoCommand.Create> toVideoCommands() {

public List<PlacesCommand.Create> toPlacesCommands() {
return placeNodes.stream()
.map(placeNode -> PlacesCommand.Create.from(placeNode.locationNode(), placeNode.placeNode()))
.map(placeNode -> {
if (Objects.isNull(placeNode)) {
return null;
}
return PlacesCommand.Create.from(placeNode.locationNode(), placeNode.placeNode());
})
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public class KakaoMapClient {
private final RestTemplate restTemplate;

public PlaceNode search(String address, String category) {
log.info("KakaoMapClient search address: {}, category: {}", address, category);
var locationInfo = getLocateInfo(address, category);
var placeId = locationInfo.has("documents") ?
var placeId = locationInfo.has("documents") && locationInfo.get("documents").hasNonNull(1) ?
locationInfo.get("documents").get(0).get("id").asText() : null;
if (Objects.isNull(placeId)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package team7.inplace.crawling.domain;

import static jakarta.persistence.EnumType.STRING;

import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -22,6 +25,7 @@ public class YoutubeChannel {
private String playListUUID;
private String lastVideoUUID;

@Enumerated(value = STRING)
private ChannelType channelType;

public String getChannelTypeCode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package team7.inplace.userFavoriteInfluencer.domain;
package team7.inplace.favoriteInfluencer.domain;

import jakarta.persistence.*;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import team7.inplace.influencer.domain.Influencer;
import team7.inplace.user.domain.User;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Getter
@RequiredArgsConstructor
@NoArgsConstructor(access = PROTECTED)
@Entity
public class UserFavoriteInfluencer {
public class FavoriteInfluencer {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team7.inplace.favoriteInfluencer.persistent;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import team7.inplace.favoriteInfluencer.domain.FavoriteInfluencer;

public interface FavoriteInfluencerRepository extends JpaRepository<FavoriteInfluencer, Long> {
List<FavoriteInfluencer> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package team7.inplace.global.exception.code;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;


@AllArgsConstructor
@Getter
public enum PlaceErrorCode implements ErrorCode{
NOT_FOUND(HttpStatus.NOT_FOUND, "P001", "Can't find such place info");

private final HttpStatus httpStatus;
private final String errorCode;
private final String message;

@Override
public HttpStatus httpStatus() {
return httpStatus;
}

@Override
public String code() {
return errorCode;
}

@Override
public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package team7.inplace.global.exception.code;

import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;

@AllArgsConstructor
public enum UserErroCode implements ErrorCode {
NOT_FOUND(HttpStatus.NOT_FOUND, "U001", "User is not found");

private final HttpStatus status;
private final String code;
private final String message;

@Override
public HttpStatus httpStatus() {
return status;
}

@Override
public String code() {
return code;
}

@Override
public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@AllArgsConstructor
@Getter
public enum VideoErrorCode implements ErrorCode{
NO_SUCH_VIDEO(HttpStatus.NOT_FOUND, "V001", "Can't find such video info");
NOT_FOUND(HttpStatus.NOT_FOUND, "V001", "Can't find such video info");

private final HttpStatus httpStatus;
private final String errorCode;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/team7/inplace/global/queryDsl/QueryDslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package team7.inplace.global.queryDsl;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QueryDslConfig {

@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import team7.inplace.favoriteInfluencer.domain.FavoriteInfluencer;
import team7.inplace.favoriteInfluencer.persistent.FavoriteInfluencerRepository;
import team7.inplace.global.exception.InplaceException;
import team7.inplace.global.exception.code.AuthorizationErrorCode;
import team7.inplace.influencer.application.dto.InfluencerCommand;
Expand All @@ -15,22 +17,20 @@
import team7.inplace.security.util.AuthorizationUtil;
import team7.inplace.user.domain.User;
import team7.inplace.user.persistence.UserRepository;
import team7.inplace.userFavoriteInfluencer.domain.UserFavoriteInfluencer;
import team7.inplace.userFavoriteInfluencer.persistent.UserFavoriteInfluencerRepository;

@RequiredArgsConstructor
@Service
public class InfluencerService {

private final InfluencerRepository influencerRepository;
private final UserFavoriteInfluencerRepository favoriteRepository;
private final FavoriteInfluencerRepository favoriteRepository;
private final UserRepository userRepository;

@Transactional(readOnly = true)
public List<InfluencerInfo> getAllInfluencers() {
return influencerRepository.findAll().stream()
.map(InfluencerInfo::from)
.toList();
.map(InfluencerInfo::from)
.toList();
}

@Transactional
Expand All @@ -43,7 +43,7 @@ public Long createInfluencer(InfluencerCommand command) {
public Long updateInfluencer(Long id, InfluencerCommand command) {
Influencer influencer = influencerRepository.findById(id).orElseThrow();
influencer.update(command.influencerName(), command.influencerImgUrl(),
command.influencerJob());
command.influencerJob());

return influencer.getId();
}
Expand All @@ -55,6 +55,7 @@ public void deleteInfluencer(Long id) {
influencerRepository.delete(influencer);
}

@Transactional
public void likeToInfluencer(InfluencerRequestParam param) {
String username = AuthorizationUtil.getUsername();
if (StringUtils.hasText(username)) {
Expand All @@ -64,7 +65,7 @@ public void likeToInfluencer(InfluencerRequestParam param) {
User user = userRepository.findByUsername(username).orElseThrow();
Influencer influencer = influencerRepository.findById(param.influencerId()).orElseThrow();

UserFavoriteInfluencer favorite = new UserFavoriteInfluencer(user, influencer);
FavoriteInfluencer favorite = new FavoriteInfluencer(user, influencer);
favorite.check(param.likes());
favoriteRepository.save(favorite);
}
Expand Down
Loading

0 comments on commit b2950b9

Please sign in to comment.