Skip to content

Commit

Permalink
Merge pull request #22 from kakao-tech-campus-2nd-step3/weekly/2
Browse files Browse the repository at this point in the history
[Weekly] 2주차 과제 PR
  • Loading branch information
sanghee0820 authored Sep 27, 2024
2 parents 8bd1d65 + d99e3d8 commit d436972
Show file tree
Hide file tree
Showing 65 changed files with 1,447 additions and 309 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,7 @@ gradle-app.setting
*.hprof
*.yaml

# CommandLineRunner for loading dummy data
src/main/java/team7/inplace/place/config/DataLoader.java

# End of https://www.toptal.com/developers/gitignore/api/macos,java,intellij,gradle
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/main/resources/InplaceSecurity"]
path = src/main/resources/InplaceSecurity
url = https://github.com/suhyeon7497/InplaceSecurity.git
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Team7_BE

## Project Version
- Spring Boots 3.3.3
- Java 17 LTS

---
## 리뷰 요청
### PlaceControllerTest
- Mock을 사용하여 테스트를 진행했는데, 적절히 사용했는지 잘 모르겠습니다.
- PlaceService를 mock, PlaceController를 InjectedMocks로 지정했는데 블로그 찾아보니 사람마다 조금씩 달라 적절한지 궁금합니다.
- Spring Boots 3.3.3
- Java 17 LTS
46 changes: 25 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'inplace'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
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'


testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.h2database:h2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
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'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.h2database:h2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
8 changes: 5 additions & 3 deletions src/main/java/team7/inplace/InplaceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;

@SpringBootApplication
@ConfigurationPropertiesScan
public class InplaceApplication {

public static void main(String[] args) {
SpringApplication.run(InplaceApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(InplaceApplication.class, args);
}

}
34 changes: 34 additions & 0 deletions src/main/java/team7/inplace/influencer/domain/Influencer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package team7.inplace.influencer.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@RequiredArgsConstructor // 테스팅을 위한 부분 추가, 협의 하에 다른 방식 채택 가능
public class Influencer {
/*
* 더미 데이터 입니다 !!!
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
@NonNull
private String name;
@Column
@NonNull
private String job;
@Column
@NonNull
private String imgUrl;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package team7.inplace.video.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import team7.inplace.video.entity.Influencer;
package team7.inplace.influencer.persistence;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import team7.inplace.influencer.domain.Influencer;

public interface InfluencerRepository extends JpaRepository<Influencer, Long> {
// 더미 데이터 입니다!!
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/team7/inplace/place/application/CategoryService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package team7.inplace.place.application;

import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import team7.inplace.place.application.dto.CategoryInfo;
import team7.inplace.place.domain.Category;
import team7.inplace.place.persistence.PlaceRepository;

@Service
@RequiredArgsConstructor
public class CategoryService {

private final PlaceRepository placeRepository;

public List<CategoryInfo> getCategories() {
return Arrays.stream(Category.values()).map(category -> new CategoryInfo(category.name()))
.toList();
}
}
33 changes: 33 additions & 0 deletions src/main/java/team7/inplace/place/application/PlaceService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package team7.inplace.place.application;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import team7.inplace.place.application.command.PlacesCommand.PlacesCoordinateCommand;
import team7.inplace.place.application.dto.PlaceInfo;
import team7.inplace.place.domain.Place;
import team7.inplace.place.persistence.PlaceRepository;

@Service
@RequiredArgsConstructor
public class PlaceService {

private final PlaceRepository placeRepository;

public Page<PlaceInfo> getPlacesWithinRadius(
PlacesCoordinateCommand placesCoordinateCommand) {

// 주어진 좌표로 장소를 찾고, 해당 페이지의 결과를 가져옵니다.
Page<Place> placesPage = getPlacesByDistance(placesCoordinateCommand);

return placesPage.map(PlaceInfo::of);
}

private Page<Place> getPlacesByDistance(PlacesCoordinateCommand comm) {
return placeRepository.getPlacesByDistance(
comm.latitude(),
comm.longitude(),
comm.pageable());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package team7.inplace.place.application.command;

import org.springframework.data.domain.Pageable;

public record PlacesCommand() {

public record PlacesCoordinateCommand(
String longitude,
String latitude,
Pageable pageable
) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team7.inplace.place.application.dto;

public record CategoryInfo(String name) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team7.inplace.place.application.dto;

public record PlaceForVideo(
Long placeId,
String placeName
) {
public static PlaceForVideo of(Long placeId, String placeName) {
return new PlaceForVideo(
placeId,
placeName
);
}
}
47 changes: 47 additions & 0 deletions src/main/java/team7/inplace/place/application/dto/PlaceInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package team7.inplace.place.application.dto;


import team7.inplace.place.domain.Address;
import team7.inplace.place.domain.Place;

public record PlaceInfo(
Long placeId,
String placeName,
AddressInfo address,
String category,
String influencerName,
String longitude,
String latitude,
Boolean likes
) {


// influencer, likes 추가 예정
public record AddressInfo(
String address1,
String address2,
String address3
) {

public static AddressInfo of(Address address) {
return new PlaceInfo.AddressInfo(
address.getAddress1(),
address.getAddress2(),
address.getAddress3()
);
}
}

public static PlaceInfo of(Place place) {
return new PlaceInfo(
place.getId(),
place.getName(),
AddressInfo.of(place.getAddress()),
place.getCategory().toString(),
null,
place.getCoordinate().getLongitude(),
place.getCoordinate().getLatitude(),
null
);
}
}
97 changes: 97 additions & 0 deletions src/main/java/team7/inplace/place/config/DataLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package team7.inplace.place.config;

import java.util.Arrays;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import team7.inplace.place.domain.Address;
import team7.inplace.place.domain.Category;
import team7.inplace.place.domain.Coordinate;
import team7.inplace.place.domain.Menu;
import team7.inplace.place.domain.Place;
import team7.inplace.place.domain.PlaceTime;
import team7.inplace.place.persistence.PlaceRepository;

@Component
public class DataLoader implements CommandLineRunner {

private final PlaceRepository placeRepository;

public DataLoader(PlaceRepository placeRepository) {
this.placeRepository = placeRepository;
}

@Override
public void run(String... args) throws Exception {
// 더미 데이터 생성
Place place1 = Place.builder()
.name("Place 1")
.pet(false)
.wifi(true)
.parking(false)
.fordisabled(true)
.nursery(false)
.smokingroom(false)
.address(new Address("Address 1", "Address 2", "Address 3"))
.menuImgUrl("menu.jpg")
.category(Category.CAFE)
.coordinate(new Coordinate("127.0", "37.0"))
.timeList(Arrays.asList(
new PlaceTime("Opening Hours", "9:00 AM", "Monday"),
new PlaceTime("Closing Hours", "10:00 PM", "Monday")
))
.menuList(Arrays.asList(
new Menu(5000L, true, "Coffee"),
new Menu(7000L, false, "Cake")
))
.build();

Place place2 = Place.builder()
.name("Place 2")
.pet(false)
.wifi(true)
.parking(false)
.fordisabled(true)
.nursery(false)
.smokingroom(false)
.address(new Address("Address 1", "Address 2", "Address 3"))
.menuImgUrl("menu.jpg")
.category(Category.CAFE)
.coordinate(new Coordinate("137.0", "10.0"))
.timeList(Arrays.asList(
new PlaceTime("Opening Hours", "9:00 AM", "Monday"),
new PlaceTime("Closing Hours", "10:00 PM", "Monday")
))
.menuList(Arrays.asList(
new Menu(5000L, true, "Coffee"),
new Menu(7000L, false, "Cake")
))
.build();

Place place3 = Place.builder()
.name("Place 3")
.pet(false)
.wifi(true)
.parking(false)
.fordisabled(true)
.nursery(false)
.smokingroom(false)
.address(new Address("Address 1", "Address 2", "Address 3"))
.menuImgUrl("menu.jpg")
.category(Category.CAFE)
.coordinate(new Coordinate("126.0", "30.0"))
.timeList(Arrays.asList(
new PlaceTime("Opening Hours", "9:00 AM", "Monday"),
new PlaceTime("Closing Hours", "10:00 PM", "Monday")
))
.menuList(Arrays.asList(
new Menu(5000L, true, "Coffee"),
new Menu(7000L, false, "Cake")
))
.build();

// 저장
placeRepository.save(place1);
placeRepository.save(place2);
placeRepository.save(place3);
}
}
Loading

0 comments on commit d436972

Please sign in to comment.