-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from Map-Pin/dev
Dev
- Loading branch information
Showing
9 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/server/mappin/controller/ShopController.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,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); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,6 +6,5 @@ | |
@Data | ||
public class MemberLoginDto { | ||
private String email; | ||
private Role role; | ||
private String name; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/server/mappin/dto/ShopRegisterRequestDto.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,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
20
src/main/java/com/server/mappin/dto/ShopRegisterResponseDto.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,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; | ||
} |
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
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,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(); | ||
} | ||
} |