Skip to content

Commit

Permalink
[BE] 주소 ID 반환기능 추가 (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvalentine6 committed Jul 28, 2023
2 parents efccd0a + 05b2c80 commit 74d3c6a
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 2,039 deletions.
4 changes: 2 additions & 2 deletions be/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ dependencies {
implementation 'mysql:mysql-connector-java:8.0.32'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.github.javafaker:javafaker:1.0.2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.projectlombok:lombok:1.18.26'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.464'


implementation 'org.yaml:snakeyaml:1.29'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import codesquad.secondhand.dto.ResponseListDto;
import codesquad.secondhand.dto.location.LocationDto;
import codesquad.secondhand.dto.location.LocationListDto;
import codesquad.secondhand.entity.Location;
import codesquad.secondhand.service.LocationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -29,4 +32,10 @@ public ResponseListDto<LocationDto> showLocations() {
return ResponseListDto.of(RESPONSE_SUCCESS, locationDtos);
}

@PostMapping
public ResponseListDto<Location> searchLocationId(LocationListDto locationListDto) {
List<Location> list = locationService.findLocationId(locationListDto);
return ResponseListDto.of(RESPONSE_SUCCESS, list);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public ResponseDto<?> signUp(@ModelAttribute SignUpRequestDto signUpRequestDto)
}

@PostMapping("/login")
public ResponseDto<TokenResponse> login(@RequestBody LoginRequestDto loginRequestDto, HttpServletRequest httpServletRequest) {
public ResponseDto<TokenResponse> login(@RequestBody LoginRequestDto loginRequestDto,
HttpServletRequest httpServletRequest) {
MemberIdxTokenDto memberIdxTokenDto = memberService.login(loginRequestDto);
MemberIdxLoginIdImageDto memberIdxLoginIdImage = memberService.getMemberIdxLoginIdImage(
memberIdxTokenDto.getMemberIdx());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package codesquad.secondhand.dto.item;

import java.sql.Date;
import java.time.LocalDateTime;
import java.util.List;

import org.joda.time.DateTime;

import codesquad.secondhand.dto.category.CategoryWithoutImageDto;
import codesquad.secondhand.entity.Item;
import lombok.Getter;
Expand Down Expand Up @@ -34,7 +31,8 @@ public static ItemDetailReturnDto of(Item item, SellerDto sellerDto,
int chat, int interest, boolean interestChecked, List<String> itemImage) {
return new ItemDetailReturnDto(item.getItemIdx(), item.getName(), sellerDto, item.getStatus(),
categoryWithoutImageDto,
item.getDescription(), item.getPrice(), chat, interest, item.getView(), interestChecked, item.getLastModifiedAt(),
item.getDescription(), item.getPrice(), chat, interest, item.getView(), interestChecked,
item.getLastModifiedAt(),
itemImage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package codesquad.secondhand.dto.location;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class LocationListDto {

private List<String> locationString;

@Override
public String toString() {
return "LocationListDto{" +
"locationString=" + locationString +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class MemberProfile {
private final String name;
private final String imageUrl;


@Builder
public MemberProfile(String oauthId, String email, String name, String imageUrl) {
this.oauthId = oauthId;
Expand Down
5 changes: 3 additions & 2 deletions be/src/main/java/codesquad/secondhand/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public Item(Member seller, Category category, Location location, ItemImage itemI
this.lastModifiedAt = LocalDateTime.now();
}

public void updateItem(Member seller, Category category, Location location, String name, String description, Integer price, String status) {
public void updateItem(Member seller, Category category, Location location, String name, String description,
Integer price, String status) {
this.seller = seller;
if (category != null) {
this.category = category;
Expand All @@ -124,11 +125,11 @@ public void updateItem(Member seller, Category category, Location location, Stri
this.status = status;
}
}

public void updateView(Integer view) {
this.view = view;
}


@Override
public String toString() {
return "Item{" +
Expand Down
22 changes: 22 additions & 0 deletions be/src/main/java/codesquad/secondhand/entity/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Location {
@Column(name = "location_idx")
private Long locationIdx;

@Column(name = "location_Id")
private Long locationId;

@Column(name = "city", nullable = false)
private String city;

Expand All @@ -36,4 +39,23 @@ public Location(Long locationIdx, String city, String district, String town) {
this.district = district;
this.town = town;
}

public Location(Long locationIdx, Long locationId, String city, String district, String town) {
this.locationIdx = locationIdx;
this.locationId = locationId;
this.city = city;
this.district = district;
this.town = town;
}

@Override
public String toString() {
return "Location{" +
"locationIdx=" + locationIdx +
", locationId=" + locationId +
", city='" + city + '\'' +
", district='" + district + '\'' +
", town='" + town + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public interface ItemRepository extends JpaRepository<Item, Long> {

Slice<Item> findByLocationLocationIdx(Long locationIdx, Pageable pageable);

Slice<Item> findItemByCategoryCategoryIdxAndLocationLocationIdx(Long categoryIdx, Long locationIdx, Pageable pageable);
Slice<Item> findItemByCategoryCategoryIdxAndLocationLocationIdx(Long categoryIdx, Long locationIdx,
Pageable pageable);

@Query("SELECT i FROM Item i WHERE i.seller.memberIdx = :sellerIdx AND ("
+ "(i.status = '판매중' OR i.status = '예약중') AND :status = 'sell' "
Expand All @@ -33,6 +34,7 @@ Slice<Item> findBySellerIdxAndStatus(@Param("sellerIdx") Long sellerIdx, @Param(
// @Param("categoryIdx") Long categoryIdx, Pageable pageable);

@Query("SELECT i FROM Item i JOIN i.interests interest WHERE interest.member.memberIdx = :memberIdx AND i.category.categoryIdx = :categoryIdx")
Slice<Item> findItemAndCategoryByMemberAndCategory(@Param("memberIdx") Long memberIdx, @Param("categoryIdx") Long categoryIdx, Pageable pageable);
Slice<Item> findItemAndCategoryByMemberAndCategory(@Param("memberIdx") Long memberIdx,
@Param("categoryIdx") Long categoryIdx, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package codesquad.secondhand.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import codesquad.secondhand.entity.Location;

public interface LocationRepository extends JpaRepository<Location, Long> {
Optional<Location> findLocationByCityAndDistrictAndTown(String city, String district, String town);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static codesquad.secondhand.exception.code.ItemErrorCode.*;
import static codesquad.secondhand.exception.code.MemberErrorCode.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand Down
13 changes: 13 additions & 0 deletions be/src/main/java/codesquad/secondhand/service/LocationService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package codesquad.secondhand.service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import codesquad.secondhand.dto.location.LocationDto;
import codesquad.secondhand.dto.location.LocationListDto;
import codesquad.secondhand.entity.Location;
import codesquad.secondhand.repository.LocationRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,4 +30,15 @@ public List<LocationDto> showAllLocations() {
.collect(Collectors.toList());
}

public List<Location> findLocationId(LocationListDto locationListDto) {
List<Location> list = new ArrayList<>();

for (String s : locationListDto.getLocationString()) {
String[] locationString = s.split(" ");
Location location = locationRepository.findLocationByCityAndDistrictAndTown(locationString[0],
locationString[1], locationString[2]).orElseThrow();
list.add(location);
}
return list;
}
}
4 changes: 2 additions & 2 deletions be/src/main/java/codesquad/secondhand/util/IpSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static String getClientIP(HttpServletRequest request) {
}
if (ip == null) {
ip = request.getRemoteAddr();
log.info("> getRemoteAddr : "+ip);
log.info("> getRemoteAddr : " + ip);
}
log.info("> Result : IP Address : "+ip);
log.info("> Result : IP Address : " + ip);

return ip;
}
Expand Down

0 comments on commit 74d3c6a

Please sign in to comment.