Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.gtable.global.api.ApiUtils;
Expand All @@ -18,12 +17,9 @@
import com.example.gtable.store.dto.StoreUpdateRequest;
import com.example.gtable.store.service.StoreService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
@Tag(name = "Store API", description = "주점 API")

@RestController
@RequestMapping("/stores")
@RequiredArgsConstructor
Expand All @@ -32,8 +28,6 @@ public class StoreController {
private final StoreService storeService;

@PostMapping
@Operation(summary = "주점 등록", description = "관리자의 주점 등록")
@ApiResponse(responseCode = "201", description = "주점 생성/등록")
public ResponseEntity<?> createStore(@Valid @RequestBody StoreCreateRequest request) {
StoreCreateResponse response = storeService.createStore(request);

Expand All @@ -47,8 +41,6 @@ public ResponseEntity<?> createStore(@Valid @RequestBody StoreCreateRequest requ
}

@GetMapping("/all-stores")
@Operation(summary = "모든 주점 리스트 조회", description = "등록된 모든 주점 리스트 조회")
@ApiResponse(responseCode = "200", description = "전체 주점 리스트 조회")
public ResponseEntity<?> getAllStores() {
return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -60,8 +52,6 @@ public ResponseEntity<?> getAllStores() {
}

@GetMapping("/{storeId}")
@Operation(summary = "특정 주점 조회", description = "특정 주점 정보 개별 조회")
@ApiResponse(responseCode = "200", description = "주점 조회")
public ResponseEntity<?> getStoreById(@PathVariable Long storeId) {
return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -72,9 +62,18 @@ public ResponseEntity<?> getStoreById(@PathVariable Long storeId) {
);
}

@GetMapping("/search")
public ResponseEntity<?> searchStores(@RequestParam("name") String name) {
return ResponseEntity
.ok()
.body(
ApiUtils.success(
storeService.searchStoresByName(name)
)
);
}

@PatchMapping("/{storeId}")
@Operation(summary = "주점 수정", description = "관리자의 주점 정보 수정")
@ApiResponse(responseCode = "200", description = "주점 수정")
public ResponseEntity<?> updateStore(
@PathVariable Long storeId,
@Valid @RequestBody StoreUpdateRequest request
Expand All @@ -89,8 +88,6 @@ public ResponseEntity<?> updateStore(
}

@DeleteMapping("/{storeId}")
@Operation(summary = "주점 삭제", description = "관리자의 주점 삭제")
@ApiResponse(responseCode = "200", description = "주점 삭제")
public ResponseEntity<?> deleteStore(@PathVariable Long storeId) {
return ResponseEntity
.ok()
Expand All @@ -100,17 +97,4 @@ public ResponseEntity<?> deleteStore(@PathVariable Long storeId) {
)
);
}

@GetMapping("/search")
@Operation(summary = "주점 검색", description = "등록된 주점 중 검색")
@ApiResponse(responseCode = "200", description = "주점 검색")
public ResponseEntity<?> searchStores(@RequestParam("name") String name) {
return ResponseEntity
.ok()
.body(
ApiUtils.success(
storeService.searchStoresByName(name)
)
);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/gtable/store/model/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand All @@ -36,9 +37,11 @@ public class Store extends BaseTimeEntity {

private String description;

@Builder.Default
@Column(name = "is_active", nullable = false)
private Boolean isActive = false;

@Builder.Default
@Column
private Boolean deleted = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface StoreRepository extends JpaRepository<Store, Long> {
List<Store> findAllByDeletedFalse();

Optional<Store> findByStoreIdAndDeletedFalse(Long storeId);

List<Store> findByNameContainingIgnoreCaseAndDeletedFalse(String name);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.gtable.store.service;

import java.util.List;

import com.example.gtable.store.dto.StoreCreateRequest;
import com.example.gtable.store.dto.StoreCreateResponse;
import com.example.gtable.store.dto.StoreReadDto;
Expand All @@ -18,4 +20,6 @@ public interface StoreService {

String deleteStore(Long storeId);

List<StoreReadDto> searchStoresByName(String name);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.gtable.store.service;

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

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -103,4 +105,19 @@ public String deleteStore(Long storeId) {

return "Store ID " + storeId + " 삭제되었습니다.";
}

@Override
public List<StoreReadDto> searchStoresByName(String name) {
List<Store> stores = storeRepository.findByNameContainingIgnoreCaseAndDeletedFalse(name);
return stores.stream()
.map(store -> {
List<StoreImage> images = storeImageRepository.findByStore(store);
List<StoreImageUploadResponse> imageDto = images.stream()
.map(StoreImageUploadResponse::fromEntity)
.toList();
return StoreReadDto.fromEntity(store, imageDto);
})
.toList();
}

}
Loading