This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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
a89ec20
commit e49283b
Showing
13 changed files
with
309 additions
and
4 deletions.
There are no files selected for viewing
27 changes: 25 additions & 2 deletions
27
src/main/java/com/uiseongcome/controller/GuideInfoController.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 |
---|---|---|
@@ -1,11 +1,34 @@ | ||
package com.uiseongcome.controller; | ||
|
||
import com.uiseongcome.dto.GuideDto; | ||
import com.uiseongcome.dto.GuideListRes; | ||
import com.uiseongcome.dto.GuideWithIdRes; | ||
import com.uiseongcome.service.GuideService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Validated | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/guide") | ||
public class GuideInfoController { | ||
private final GuideService guideService; | ||
|
||
@PostMapping | ||
public void write(@RequestBody GuideDto guideDto){ | ||
guideService.append(guideDto); | ||
} | ||
|
||
@GetMapping("/list") | ||
public List<GuideListRes> getList(){ | ||
return guideService.getList(); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public GuideWithIdRes get(@PathVariable Long id){ | ||
return guideService.get(id); | ||
} | ||
} |
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
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,8 @@ | ||
package com.uiseongcome.domain; | ||
|
||
public enum GuideKind { | ||
NATURE, | ||
FOOD, | ||
REST, | ||
EXPERIENCE | ||
} |
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
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,16 @@ | ||
package com.uiseongcome.dto; | ||
|
||
import com.uiseongcome.domain.File; | ||
import com.uiseongcome.domain.GuideInfo; | ||
|
||
public record FileDto( | ||
String path | ||
) { | ||
public File toEntity(GuideInfo guideInfo){ | ||
return File.builder() | ||
.path(path) | ||
.guideInfo(guideInfo) | ||
.build(); | ||
} | ||
|
||
} |
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,55 @@ | ||
package com.uiseongcome.dto; | ||
|
||
import com.uiseongcome.domain.File; | ||
import com.uiseongcome.domain.GuideInfo; | ||
import com.uiseongcome.domain.GuideKind; | ||
import com.uiseongcome.domain.User; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public record GuideDto( | ||
String title, | ||
LocalDate startAt, | ||
LocalDate endAt, | ||
Long limitPeople, | ||
Long price, | ||
String description, | ||
Boolean wifi, | ||
Boolean tv, | ||
Boolean kitchen, | ||
Boolean washingMachine, | ||
Boolean airConditioner, | ||
Boolean parking, | ||
Long bedCnt, | ||
Long bathroomCnt, | ||
Long roomCnt, | ||
String address, | ||
GuideKind guideKind, | ||
List<PlaceDto> places, | ||
List<FileDto> files, | ||
String userId | ||
) { | ||
public GuideInfo toEntity(User user){ | ||
return GuideInfo.builder() | ||
.title(title) | ||
.startAt(startAt) | ||
.endAt(endAt) | ||
.limitPeople(limitPeople) | ||
.price(price) | ||
.description(description) | ||
.wifi(wifi) | ||
.tv(tv) | ||
.kitchen(kitchen) | ||
.washingMachine(washingMachine) | ||
.airConditioner(airConditioner) | ||
.parking(parking) | ||
.bedCnt(bedCnt) | ||
.bathroomCnt(bathroomCnt) | ||
.roomCnt(roomCnt) | ||
.address(address) | ||
.guideKind(guideKind) | ||
.user(user) | ||
.build(); | ||
} | ||
} |
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,21 @@ | ||
package com.uiseongcome.dto; | ||
|
||
import com.uiseongcome.domain.GuideInfo; | ||
import com.uiseongcome.domain.Place; | ||
|
||
import java.util.List; | ||
|
||
public record GuideListRes( | ||
String title, | ||
List<String> places, | ||
Long price, | ||
String name | ||
) { | ||
public static GuideListRes of(GuideInfo guideInfo, List<Place> places){ | ||
return new GuideListRes( | ||
guideInfo.getTitle(), | ||
places.stream().map(Place::getName).toList(), | ||
guideInfo.getPrice(), | ||
guideInfo.getUser().getName()); | ||
} | ||
} |
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,58 @@ | ||
package com.uiseongcome.dto; | ||
|
||
import com.uiseongcome.domain.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public record GuideWithIdRes( | ||
Long guideId, | ||
String title, | ||
LocalDate startAt, | ||
LocalDate endAt, | ||
Long limitPeople, | ||
Long price, | ||
String description, | ||
Boolean wifi, | ||
Boolean tv, | ||
Boolean kitchen, | ||
Boolean washingMachine, | ||
Boolean airConditioner, | ||
Boolean parking, | ||
Long bedCnt, | ||
Long bathroomCnt, | ||
Long roomCnt, | ||
String address, | ||
GuideKind guideKind, | ||
List<PlaceDto> places, | ||
List<String> files, | ||
String userId, | ||
String userName | ||
) { | ||
public static GuideWithIdRes of(GuideInfo guideInfo, List<Place> places, List<File> files){ | ||
return new GuideWithIdRes( | ||
guideInfo.getGuideInfoId(), | ||
guideInfo.getTitle(), | ||
guideInfo.getStartAt(), | ||
guideInfo.getEndAt(), | ||
guideInfo.getLimitPeople(), | ||
guideInfo.getPrice(), | ||
guideInfo.getDescription(), | ||
guideInfo.getWifi(), | ||
guideInfo.getTv(), | ||
guideInfo.getKitchen(), | ||
guideInfo.getWashingMachine(), | ||
guideInfo.getAirConditioner(), | ||
guideInfo.getParking(), | ||
guideInfo.getBedCnt(), | ||
guideInfo.getBathroomCnt(), | ||
guideInfo.getRoomCnt(), | ||
guideInfo.getAddress(), | ||
guideInfo.getGuideKind(), | ||
places.stream().map(PlaceDto::of).toList(), | ||
files.stream().map(File::getPath).toList(), | ||
guideInfo.getUser().getUserId(), | ||
guideInfo.getUser().getName() | ||
); | ||
} | ||
} |
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,28 @@ | ||
package com.uiseongcome.dto; | ||
|
||
import com.uiseongcome.domain.Place; | ||
|
||
public record PlaceDto( | ||
String latitude, | ||
String longitude, | ||
String name, | ||
String seq | ||
) { | ||
public Place toEntity(){ | ||
return Place.builder() | ||
.latitude(latitude) | ||
.longitude(longitude) | ||
.name(name) | ||
.seq(seq) | ||
.build(); | ||
} | ||
|
||
public static PlaceDto of(Place place){ | ||
return new PlaceDto( | ||
place.getLatitude(), | ||
place.getLongitude(), | ||
place.getName(), | ||
place.getSeq() | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/uiseongcome/repository/FileRepository.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,11 @@ | ||
package com.uiseongcome.repository; | ||
|
||
import com.uiseongcome.domain.File; | ||
import com.uiseongcome.domain.GuideInfo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface FileRepository extends JpaRepository<File, Long> { | ||
List<File> findByGuideInfo(GuideInfo guideInfo); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/uiseongcome/repository/PlaceRepository.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,11 @@ | ||
package com.uiseongcome.repository; | ||
|
||
import com.uiseongcome.domain.GuideInfo; | ||
import com.uiseongcome.domain.Place; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface PlaceRepository extends JpaRepository<Place, Long> { | ||
List<Place> findByGuideInfo(GuideInfo guideInfo); | ||
} |
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,8 @@ | ||
package com.uiseongcome.repository; | ||
|
||
import com.uiseongcome.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, String> { | ||
User findById(); | ||
} |
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 |
---|---|---|
@@ -1,12 +1,56 @@ | ||
package com.uiseongcome.service; | ||
|
||
import com.uiseongcome.domain.File; | ||
import com.uiseongcome.domain.GuideInfo; | ||
import com.uiseongcome.domain.Place; | ||
import com.uiseongcome.domain.User; | ||
import com.uiseongcome.dto.GuideDto; | ||
import com.uiseongcome.dto.GuideListRes; | ||
import com.uiseongcome.dto.GuideWithIdRes; | ||
import com.uiseongcome.dto.PlaceDto; | ||
import com.uiseongcome.repository.FileRepository; | ||
import com.uiseongcome.repository.GuideInfoRepository; | ||
import com.uiseongcome.repository.PlaceRepository; | ||
import com.uiseongcome.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GuideService { | ||
private final GuideInfoRepository guideInfoRepository; | ||
private final UserRepository userRepository; | ||
private final PlaceRepository placeRepository; | ||
private final FileRepository fileRepository; | ||
|
||
@Transactional(rollbackFor = Exception.class) | ||
public void append(GuideDto guideDto){ | ||
User user = userRepository.findById(guideDto.userId()).get(); | ||
GuideInfo guideInfo = guideInfoRepository.save(guideDto.toEntity(user)); | ||
placeRepository.saveAll(guideDto.places().stream() | ||
.map(PlaceDto::toEntity) | ||
.toList()); | ||
fileRepository.saveAll(guideDto.files().stream().map(f -> f.toEntity(guideInfo)).toList()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<GuideListRes> getList(){ | ||
List<GuideInfo> guideInfos = guideInfoRepository.findAll(); | ||
return guideInfos.stream() | ||
.map(g -> GuideListRes.of( | ||
g, placeRepository.findByGuideInfo(g))) | ||
.toList(); | ||
|
||
} | ||
|
||
@Transactional(readOnly = true) | ||
public GuideWithIdRes get(Long id){ | ||
GuideInfo guideInfo = guideInfoRepository.findById(id).get(); | ||
List<Place> places = placeRepository.findByGuideInfo(guideInfo); | ||
List<File> files = fileRepository.findByGuideInfo(guideInfo); | ||
return GuideWithIdRes.of(guideInfo, places, files); | ||
} | ||
} |