Skip to content

Commit

Permalink
Merge pull request #30 from 29sungdong/feat/walk
Browse files Browse the repository at this point in the history
[feat] 산책 경로 생성 API 구현
  • Loading branch information
suhhyun524 authored Feb 22, 2024
2 parents 2791f2b + 5bcc4fb commit 53d7930
Show file tree
Hide file tree
Showing 25 changed files with 315 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

# Gradle build
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew build -x test

- name: Docker meta
id: docker_meta
Expand Down
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.mysql:mysql-connector-j'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -37,6 +38,11 @@ dependencies {
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'
implementation 'org.modelmapper:modelmapper:3.1.1'

implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

implementation group: 'org.json', name: 'json', version: '20231013'

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.0.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Badge {
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@Entity
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UserBadge {
@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package sungdong29.backend.domain.badge.service;

import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import sungdong29.backend.domain.badge.domain.Badge;
import sungdong29.backend.domain.badge.domain.UserBadge;
import sungdong29.backend.domain.badge.dto.response.BadgeResponseDTO;
import sungdong29.backend.domain.badge.dto.response.BadgesResponseDTO;
import sungdong29.backend.domain.badge.dto.response.UserBadgeResponseDTO;
import sungdong29.backend.domain.badge.repository.BadgeRepository;
import sungdong29.backend.domain.badge.repository.UserBadgeRepository;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sungdong29.backend.domain.event.domain.Category;
import sungdong29.backend.domain.event.dto.response.EventListResponseDTO;
import sungdong29.backend.domain.event.enums.SortCategoryType;
import sungdong29.backend.domain.event.service.EventService;

import java.util.List;
Expand All @@ -26,7 +26,7 @@ public class EventController {
@Operation(summary = "행사 리스트 조회")
@GetMapping
public EventListResponseDTO getEvents(
@RequestParam(value = "category", required = false) List<SortCategoryType> category,
@RequestParam(value = "category", required = false) List<Category> category,
@RequestParam(value = "place_id", required = false) Long placeId) {
log.info("행사 리스트 조회");
return eventService.getEventList(category, placeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ public class EventHelper {

private final EventRepository eventRepository;

public List<Event> getEventList(List<SortCategoryType> sortCategoryList, Long placeId) {
public List<Event> getEventList(List<Category> categoryList, Long placeId) {
List<Event> events;

if (sortCategoryList == null || sortCategoryList.isEmpty()) {
if (categoryList == null || categoryList.isEmpty()) {
events = eventRepository.findByFilter(null, placeId);
}
else {
List<Category> categoryList = toCategoryList(sortCategoryList);
events = eventRepository.findByFilter(categoryList, placeId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EventMapper {
public EventListResponseDTO toEventListDTO(List<Event> events) {
List<SimpleEventVo> mapEvents =
events.stream()
.map(SimpleEventVo::of)
.map(SimpleEventVo::from)
.toList();
return EventListResponseDTO.from(mapEvents);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sungdong29.backend.domain.event.domain.Category;
import sungdong29.backend.domain.event.domain.Event;
import sungdong29.backend.domain.event.dto.response.EventListResponseDTO;
import sungdong29.backend.domain.event.enums.SortCategoryType;
import sungdong29.backend.domain.event.helper.EventHelper;
import sungdong29.backend.domain.event.mapper.EventMapper;

Expand All @@ -19,7 +19,7 @@ public class EventService {
private final EventMapper eventMapper;
private final EventHelper eventHelper;

public EventListResponseDTO getEventList(List<SortCategoryType> category, Long placeId) {
public EventListResponseDTO getEventList(List<Category> category, Long placeId) {
List<Event> events = eventHelper.getEventList(category, placeId);
return eventMapper.toEventListDTO(events);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private SimpleEventVo(Long placeId, String placeName, String name, LocalDateTime
this.url = url;
}

public static SimpleEventVo of(Event event) {
public static SimpleEventVo from(Event event) {
return SimpleEventVo.builder()
.placeId(event.getPlace().getId())
.placeName(event.getPlace().getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sungdong29.backend.domain.subPlace.domain.SubPlace;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class Mission {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import sungdong29.backend.domain.mission.repository.MissionRepository;
import sungdong29.backend.domain.mission.repository.UserMissionRepository;
import sungdong29.backend.domain.user.domain.User;
import sungdong29.backend.domain.walk.repository.WalkRepository;
import sungdong29.backend.domain.walk.repository.WalkHistoryRepository;

@Component
@RequiredArgsConstructor
public class UserHelper {

private final WalkRepository walkRepository;
private final WalkHistoryRepository walkRepository;
private final PlaceRepository placeRepository;
private final UserMissionRepository userMissionRepository;
private final MissionRepository missionRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import sungdong29.backend.domain.user.exception.UserNotFound;
import sungdong29.backend.domain.user.helper.UserHelper;
import sungdong29.backend.domain.user.repository.UserRepository;
import sungdong29.backend.domain.walk.repository.WalkRepository;
import sungdong29.backend.domain.walk.repository.WalkHistoryRepository;
import sungdong29.backend.global.config.jwt.TokenProvider;
import sungdong29.backend.global.config.user.UserDetails;

Expand All @@ -36,7 +36,7 @@ public class UserService {
private final UserHelper userHelper;
private final UserRepository userRepository;
private final PlaceRepository placeRepository;
private final WalkRepository walkRepository;
private final WalkHistoryRepository walkHistoryRepository;
private final PasswordEncoder passwordEncoder;
private final TokenProvider tokenProvider;

Expand Down Expand Up @@ -97,7 +97,7 @@ public UserResponseDTO updateUserNickname(Long userId, NicknameUpdateRequestDTO
public PlacesResponseDTO findVisitedPlaces(Long userId) {
List<Place> places = placeRepository.findAll();
List<PlaceResponseDTO> placeResponseDTOS = places.stream()
.map(place -> PlaceResponseDTO.of(place, walkRepository.existsByUserIdAndPlaceId(userId, place.getId())))
.map(place -> PlaceResponseDTO.of(place, walkHistoryRepository.existsByUserIdAndPlaceId(userId, place.getId())))
.collect(Collectors.toList());

return PlacesResponseDTO.from(placeResponseDTOS);
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/sungdong29/backend/domain/walk/WalkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import sungdong29.backend.domain.walk.dto.response.WalkPathResponseDTO;
import sungdong29.backend.domain.walk.service.WalkService;
import sungdong29.backend.global.config.user.UserDetails;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping
@RequestMapping(value = "/walk")
@Tag(name = "Walk")
public class WalkController {
private final WalkService walkService;

@Operation(summary = "산책로 경로 반환")
@GetMapping("places/{placeId}")
public WalkPathResponseDTO getWalkPath(
@RequestParam String xCoordinate,
@RequestParam String yCoordinate,
@PathVariable Long placeId
) {
return walkService.getWalkPath(xCoordinate, yCoordinate, placeId);
}

@Operation(summary = "산책 기록 저장")
@GetMapping(value = "places/{placeId}/walk")
@PostMapping(value = "places/{placeId}")
public ResponseEntity<Void> createWalkRecord(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long placeId) {
Expand Down
42 changes: 13 additions & 29 deletions src/main/java/sungdong29/backend/domain/walk/domain/Walk.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
package sungdong29.backend.domain.walk.domain;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import sungdong29.backend.domain.place.domain.Place;
import sungdong29.backend.domain.user.domain.User;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Walk {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "walk_id")
private Long id;

@ManyToOne
@JoinColumn(name="user_id")
private User user;

@ManyToOne
@JoinColumn(name="place_id")
private Place place;

@CreatedDate
private LocalDateTime createdAt;
@NotNull
@Size(max = 20)
private String name;

@Builder
private Walk(User user, Place place) {
this.user=user;
this.place=place;
}
@NotNull
@Size(max = 50)
private String xCoordinate;

public static Walk of(User user, Place place) {
return Walk.builder()
.user(user)
.place(place)
.build();
}
@NotNull
@Size(max = 50)
private String yCoordinate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package sungdong29.backend.domain.walk.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import sungdong29.backend.domain.place.domain.Place;
import sungdong29.backend.domain.user.domain.User;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@EntityListeners(AuditingEntityListener.class)
public class WalkHistory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name="user_id")
private User user;

@ManyToOne
@JoinColumn(name="place_id")
private Place place;

@CreatedDate
private LocalDateTime createdAt;

@Builder
private WalkHistory(User user, Place place) {
this.user=user;
this.place=place;
}

public static WalkHistory of(User user, Place place) {
return WalkHistory.builder()
.user(user)
.place(place)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sungdong29.backend.domain.walk.dto.response;

import lombok.Builder;
import sungdong29.backend.domain.walk.vo.WalkPathVo;

import java.util.List;

public class WalkPathListResponseDTO {

List<WalkPathVo> walkPathList;

@Builder
private WalkPathListResponseDTO(List<WalkPathVo> walkPathList) {
this.walkPathList = walkPathList;
}

public static WalkPathListResponseDTO from(List<WalkPathVo> walkPathList) {
return WalkPathListResponseDTO.builder()
.walkPathList(walkPathList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package sungdong29.backend.domain.walk.dto.response;

import lombok.Builder;
import lombok.Getter;
import sungdong29.backend.domain.walk.domain.Walk;

import java.util.List;

@Getter
public class WalkPathResponseDTO {

private Long id;
private String name;
private List<String> lineString;

@Builder
private WalkPathResponseDTO(
Long id,
String name,
List<String> lineString) {
this.id = id;
this.name = name;
this.lineString = lineString;
}

public static WalkPathResponseDTO of(Walk walk, List<String> lineString) {
return WalkPathResponseDTO.builder()
.id(walk.getId())
.name(walk.getName())
.lineString(lineString)
.build();
}
}
Loading

0 comments on commit 53d7930

Please sign in to comment.