-
Notifications
You must be signed in to change notification settings - Fork 5
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 #13 from marinesnow34/store
Feat: 가게 상세 정보 구현
- Loading branch information
Showing
13 changed files
with
208 additions
and
3 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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/readyvery/readyverydemo/domain/StoreImg.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,36 @@ | ||
package com.readyvery.readyverydemo.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Table(name = "STORES_IMG") | ||
@AllArgsConstructor | ||
@Slf4j | ||
public class StoreImg { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "store_img_idx") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "store_idx") | ||
private Store store; | ||
|
||
private String imgUrl; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/readyvery/readyverydemo/domain/repository/StoreRepository.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,9 @@ | ||
package com.readyvery.readyverydemo.domain.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.readyvery.readyverydemo.domain.Store; | ||
|
||
public interface StoreRepository extends JpaRepository<Store, Long> { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/readyvery/readyverydemo/global/exception/BusinessLogicException.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.readyvery.readyverydemo.global.exception; | ||
|
||
import lombok.Getter; | ||
|
||
public class BusinessLogicException extends RuntimeException { | ||
@Getter | ||
private ExceptionCode exceptionCode; | ||
|
||
public BusinessLogicException(ExceptionCode exceptionCode) { | ||
super(exceptionCode.getMessage()); | ||
this.exceptionCode = exceptionCode; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/readyvery/readyverydemo/global/exception/ErrorResponse.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,22 @@ | ||
package com.readyvery.readyverydemo.global.exception; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
public class ErrorResponse { | ||
// 비즈니스로직 예외: 지정된 Code로 생성할 경우 | ||
public static ErrorResponse.Default of(ExceptionCode exceptionCode) { | ||
return new ErrorResponse.Default(exceptionCode.getStatus(), exceptionCode.getMessage()); | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public static class Default { | ||
private Integer status; | ||
private String message; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.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,16 @@ | ||
package com.readyvery.readyverydemo.global.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum ExceptionCode { | ||
STORE_NOT_FOUND(404, "Store does not exists."); | ||
|
||
private int status; | ||
private String message; | ||
|
||
ExceptionCode(int status, String message) { | ||
this.status = status; | ||
this.message = message; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/readyvery/readyverydemo/global/exception/GlobalExceptionAdvice.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,15 @@ | ||
package com.readyvery.readyverydemo.global.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionAdvice { | ||
@ExceptionHandler(BusinessLogicException.class) | ||
public ResponseEntity<ErrorResponse.Default> handleException(BusinessLogicException exception) { | ||
final ErrorResponse.Default response = ErrorResponse.of(exception.getExceptionCode()); | ||
return new ResponseEntity<>(response, HttpStatus.valueOf(response.getStatus())); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/readyvery/readyverydemo/src/store/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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.readyvery.readyverydemo.src.store; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
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 com.readyvery.readyverydemo.src.store.dto.StoreDetailRes; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/store") | ||
public class StoreController { | ||
private final StoreService storeService; | ||
|
||
@GetMapping("/{storeId}") | ||
public ResponseEntity<StoreDetailRes> getStoreDetail(@PathVariable("storeId") Long storeId) { | ||
StoreDetailRes storeDetailRes = storeService.getStoreDetail(storeId); | ||
return new ResponseEntity<>(storeDetailRes, HttpStatus.OK); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/readyvery/readyverydemo/src/store/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.readyvery.readyverydemo.src.store; | ||
|
||
import com.readyvery.readyverydemo.src.store.dto.StoreDetailRes; | ||
|
||
public interface StoreService { | ||
StoreDetailRes getStoreDetail(Long storeId); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/readyvery/readyverydemo/src/store/StoreServiceImpl.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,26 @@ | ||
package com.readyvery.readyverydemo.src.store; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.readyvery.readyverydemo.domain.Store; | ||
import com.readyvery.readyverydemo.domain.repository.StoreRepository; | ||
import com.readyvery.readyverydemo.global.exception.BusinessLogicException; | ||
import com.readyvery.readyverydemo.global.exception.ExceptionCode; | ||
import com.readyvery.readyverydemo.src.store.dto.StoreDetailRes; | ||
import com.readyvery.readyverydemo.src.store.dto.StoreMapper; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StoreServiceImpl implements StoreService { | ||
private final StoreRepository storeRepository; | ||
private final StoreMapper storeMapper; | ||
|
||
@Override | ||
public StoreDetailRes getStoreDetail(Long storeId) { | ||
Store store = storeRepository.findById(storeId) | ||
.orElseThrow(() -> new BusinessLogicException(ExceptionCode.STORE_NOT_FOUND)); | ||
return storeMapper.storeToStoreDetailRes(store); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/readyvery/readyverydemo/src/store/dto/StoreDetailRes.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,16 @@ | ||
package com.readyvery.readyverydemo.src.store.dto; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class StoreDetailRes { | ||
private List<String> imgs; | ||
private String name; | ||
private String phone; | ||
private String address; | ||
private String openTime; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/readyvery/readyverydemo/src/store/dto/StoreMapper.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,19 @@ | ||
package com.readyvery.readyverydemo.src.store.dto; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.readyvery.readyverydemo.domain.Store; | ||
import com.readyvery.readyverydemo.domain.StoreImg; | ||
|
||
@Component | ||
public class StoreMapper { | ||
public StoreDetailRes storeToStoreDetailRes(Store store) { | ||
return StoreDetailRes.builder() | ||
.imgs(store.getImgs().stream().map(StoreImg::getImgUrl).toList()) | ||
.name(store.getName()) | ||
.phone(store.getPhone()) | ||
.address(store.getAddress()) | ||
.openTime(store.getTime()) | ||
.build(); | ||
} | ||
} |