-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
110 additions
and
19 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/couphoneserver/controller/StoreController.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,16 +1,39 @@ | ||
package com.example.couphoneserver.controller; | ||
|
||
import com.example.couphoneserver.common.exception.StoreException; | ||
import com.example.couphoneserver.common.response.BaseResponse; | ||
import com.example.couphoneserver.dto.store.PostStoreRequest; | ||
import com.example.couphoneserver.dto.store.PostStoreResponse; | ||
import com.example.couphoneserver.service.StoreService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.example.couphoneserver.common.response.status.BaseExceptionResponseStatus.INVALID_STORE_VALUE; | ||
import static com.example.couphoneserver.utils.BindingResultUtils.getErrorMessages; | ||
|
||
@Tag(name = "store", description = "가게 관련 API 입니다.") | ||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/stores") | ||
public class StoreController { | ||
private final StoreService storeService; | ||
|
||
@PostMapping("") | ||
@Operation(summary = "가게 등록", description = "Request Body에 브랜드 아이디, 매장명, 위도, 경도, 주소를 담아서 보내주세요!") | ||
public BaseResponse<PostStoreResponse> postBrand(@Validated @RequestBody PostStoreRequest request, | ||
BindingResult bindingResult){ | ||
if (bindingResult.hasErrors()){ | ||
throw new StoreException(INVALID_STORE_VALUE,getErrorMessages(bindingResult)); | ||
} | ||
return new BaseResponse<>(storeService.save(request)); | ||
} | ||
} |
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
39 changes: 25 additions & 14 deletions
39
src/main/java/com/example/couphoneserver/dto/store/PostStoreRequest.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,37 +1,48 @@ | ||
package com.example.couphoneserver.dto.store; | ||
|
||
import com.example.couphoneserver.domain.StoreStatus; | ||
import com.example.couphoneserver.domain.entity.Brand; | ||
import com.example.couphoneserver.domain.entity.Store; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.annotation.Nullable; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.validator.constraints.Range; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PostStoreRequest { | ||
@NotNull | ||
@Range(min=1,message="bid: 브랜드 아이디는 {min} 이상부터 가능합니다.") | ||
@NotNull(message = "bid: {NotNull}") | ||
@Range(min=1,message="bid: 브랜드 아이디는 {min} 이상부터 가능합니다") | ||
@Schema(example="1", description = "브랜드 등록 후 응답값으로 받은 브랜드 아이디를 넣어주세요.") | ||
private Long bid; | ||
@NotNull | ||
@Size(min=1,max=100,message = "name: 가게 이름의 길이는 {min} 이상, {max} 이하 가능합니다.") | ||
|
||
@NotBlank(message = "name: {NotBlank}") | ||
@Size(min=1,max=100,message = "name: 가게 이름의 길이는 {min} 이상, {max} 이하 가능합니다") | ||
@Schema(example="건국대학교 서울캠퍼스",description = "브랜드 이름+공백+지점명으로 보내주세요.") | ||
private String name; | ||
@NotNull | ||
@NotBlank(message = "address: {NotBlank}") | ||
@Schema(example = "서울특별시 광진구 능동로 120") | ||
private String address; | ||
@NotNull | ||
@NotNull(message = "longitude: {NotNull}") | ||
@Schema(example = "123456.111111") | ||
private Double longitude; | ||
@NotNull | ||
@NotNull(message = "latitude: {NotNull}") | ||
@Schema(example = "123456.111111") | ||
private Double latitude; | ||
@Nullable | ||
@Enumerated(EnumType.STRING) | ||
private StoreStatus status = StoreStatus.ACTIVE; | ||
|
||
|
||
public Store toEntity(Brand brand) { | ||
return Store.builder() | ||
.name(name) | ||
.address(address) | ||
.longitude(longitude) | ||
.latitude(latitude) | ||
.status(StoreStatus.ACTIVE) | ||
.brand(brand) | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/couphoneserver/dto/store/PostStoreResponse.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,4 +1,16 @@ | ||
package com.example.couphoneserver.dto.store; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Data; | ||
|
||
|
||
|
||
@Data | ||
public class PostStoreResponse { | ||
@Schema(example = "1", description = "회원 아이디") | ||
private Long id; | ||
|
||
public PostStoreResponse(Long id) { | ||
this.id = 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
34 changes: 32 additions & 2 deletions
34
src/main/java/com/example/couphoneserver/service/StoreService.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