Skip to content

Commit

Permalink
Merge pull request #72 from Map-Pin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
seungheon123 authored Nov 9, 2023
2 parents 5d1ba50 + febab91 commit 243fd99
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<?> searchByCategory(@RequestParam(value = "category") Stri
}

@Operation(summary = "동 검색", description = "분실물을 동 별로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByDongResponseDto.class)))
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByDongListResponseDto.class)))
@GetMapping("lost/search/dong")
public ResponseEntity<?> searchByDong(@RequestParam(value = "name") String dongName) {
try {
Expand All @@ -89,7 +89,7 @@ public ResponseEntity<?> searchByDong(@RequestParam(value = "name") String dongN
}

@Operation(summary = "가게 검색", description = "분실물을 가게이름 별로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByShopResponseDto.class)))
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByShopListResponseDto.class)))
@GetMapping("lost/search/shop")
public ResponseEntity<?> searchByShop(@RequestParam(value = "name") String shopName) {
try {
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/server/mappin/controller/ShopController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.server.mappin.controller;

import com.server.mappin.dto.LostRegisterRequestDto;
import com.server.mappin.dto.LostRegisterResponseDto;
import com.server.mappin.dto.ShopRegisterRequestDto;
import com.server.mappin.dto.ShopRegisterResponseDto;
import com.server.mappin.service.ShopService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Tag(name = "Shop API", description = "가게 관련 API 명세서")
@RestController
@Slf4j
@RequiredArgsConstructor
public class ShopController {
private final ShopService shopService;

@Operation(summary = "가게 등록", description = "application/json입니다")
@ApiResponse(content = @Content(schema = @Schema(implementation = ShopRegisterResponseDto.class)))
@PutMapping(value = "/shop/register")
public ResponseEntity<?> registerLost(
@RequestBody ShopRegisterRequestDto shopRegisterRequestDto,
Authentication authentication) throws IOException {
try {
ShopRegisterResponseDto shopRegisterResponseDto = shopService.shopRegister(shopRegisterRequestDto, authentication.getName());
return new ResponseEntity<>(shopRegisterResponseDto, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/server/mappin/domain/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class Shop {
@Column(name = "address")
private String address;

@Column(name = "companyNumber")
private String companyNumber;

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;
Expand All @@ -36,11 +39,12 @@ public class Shop {
private Location location;

@Builder
public Shop(String name, Integer point, String address, Member member, Location location) {
public Shop(String name, Integer point, String address, Member member, Location location, String companyNumber) {
this.name = name;
this.point = point;
this.address = address;
this.member = member;
this.location = location;
this.companyNumber = companyNumber;
}
}
1 change: 0 additions & 1 deletion src/main/java/com/server/mappin/dto/MemberLoginDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
@Data
public class MemberLoginDto {
private String email;
private Role role;
private String name;
}
13 changes: 13 additions & 0 deletions src/main/java/com/server/mappin/dto/ShopRegisterRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.server.mappin.dto;

import lombok.Builder;
import lombok.Data;
import lombok.Getter;

@Getter
public class ShopRegisterRequestDto {
private String name;
private String address;
private String companyNumber;

}
20 changes: 20 additions & 0 deletions src/main/java/com/server/mappin/dto/ShopRegisterResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.server.mappin.dto;

import lombok.Builder;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Builder
public class ShopRegisterResponseDto {
private int statusCode;
private String isSuccess;
private Long memberId;
private Long shopId;
private String dong;
private String name;
private String address;
private String companyNumber;
}
20 changes: 19 additions & 1 deletion src/main/java/com/server/mappin/service/LostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public FindByShopListResponseDto findByShop(String shopName) {
.build();
}

public FindByDongListResponseDto findByCurrentLocation(Double x, Double y) {
/*public FindByDongListResponseDto findByCurrentLocation(Double x, Double y) {
String dong = mapService.getDong(x, y);
Optional<Location> locationByDong = locationRepository.findLocationByDong(dong);
if (locationByDong.isPresent()) {
Expand All @@ -84,6 +84,24 @@ public FindByDongListResponseDto findByCurrentLocation(Double x, Double y) {
}
return null;
}
*/

public FindByDongListResponseDto findByCurrentLocation(Double x, Double y) {
List<Lost> locationByDong = lostRepository.findAll();
return FindByDongListResponseDto.builder()
.statusCode(200)
.isSuccess("true")
.losts(locationByDong.stream().map(lost -> FindByDongResponseDto.builder()
.id(lost.getId())
.title(lost.getTitle())
.createdAt(lost.getCreatedAt())
.imageUrl(lost.getImageUrl())
.build())
.collect(Collectors.toList()))
.build();
}



@Transactional
public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterRequestDto, MultipartFile image, String email) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/server/mappin/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public LoginResponseDto login(MemberLoginDto memberCreateDto) {
} else {
Member member = new Member();
member.setEmail(memberCreateDto.getEmail());
member.setRole(memberCreateDto.getRole());
member.setRole(Role.USER);
member.setName(memberCreateDto.getName());
member.setCreatedAt(LocalDate.now());
member.setProviderType(ProviderType.KAKAO);
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/server/mappin/service/ShopService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
package com.server.mappin.service;

import com.server.mappin.domain.Location;
import com.server.mappin.domain.Member;
import com.server.mappin.domain.Shop;
import com.server.mappin.domain.enums.Role;
import com.server.mappin.dto.ShopRegisterRequestDto;
import com.server.mappin.dto.ShopRegisterResponseDto;
import com.server.mappin.repository.LocationRepository;
import com.server.mappin.repository.MemberRepository;
import com.server.mappin.repository.ShopRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.geo.Point;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.Optional;

@Service
@Slf4j
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ShopService {
private final ShopRepository shopRepository;
private final MemberRepository memberRepository;
private final LocationRepository locationRepository;
private final MapService mapService;

@Transactional
public ShopRegisterResponseDto shopRegister(ShopRegisterRequestDto shopRegisterRequestDto, String email) {
Optional<Member> memberByEmail = memberRepository.findByEmail(email);
Point point = mapService.GetLocalInfo(shopRegisterRequestDto.getAddress());
String dong = mapService.getDong(point.getX(), point.getY());
Optional<Location> locationByDong = locationRepository.findLocationByDong(dong);

if (memberByEmail.isPresent() && locationByDong.isPresent()) {
Member member = memberByEmail.get();
member.setRole(Role.OWNER);
Shop shop = Shop.builder()
.member(member)
.name(shopRegisterRequestDto.getName())
.address(shopRegisterRequestDto.getAddress())
.location(locationByDong.get())
.point(50)
.companyNumber(shopRegisterRequestDto.getCompanyNumber())
.build();
Member save1 = memberRepository.save(member);
Shop save = shopRepository.save(shop);
return ShopRegisterResponseDto.builder()
.shopId(save.getId())
.memberId(save1.getId())
.name(save.getName())
.address(save.getAddress())
.dong(dong)
.companyNumber(save.getCompanyNumber())
.isSuccess("true")
.statusCode(200)
.build();
}
return ShopRegisterResponseDto.builder()
.isSuccess("false")
.statusCode(400)
.build();
}
}

0 comments on commit 243fd99

Please sign in to comment.