|
| 1 | +package com.back.domain.cocktail.controller; |
| 2 | + |
| 3 | +import com.back.domain.cocktail.repository.CocktailRepository; |
| 4 | +import com.back.global.rsData.RsData; |
| 5 | +import lombok.RequiredArgsConstructor; |
| 6 | +import org.springframework.http.HttpStatus; |
| 7 | +import org.springframework.http.ResponseEntity; |
| 8 | +import org.springframework.web.bind.annotation.GetMapping; |
| 9 | +import org.springframework.web.bind.annotation.PathVariable; |
| 10 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 11 | +import org.springframework.web.bind.annotation.RestController; |
| 12 | + |
| 13 | +import java.util.Map; |
| 14 | + |
| 15 | +@RestController |
| 16 | +@RequestMapping("/api/cocktails") |
| 17 | +@RequiredArgsConstructor |
| 18 | +public class CocktailShareController { |
| 19 | + private final CocktailRepository cocktailRepository; |
| 20 | + |
| 21 | + @GetMapping("/{id}/share") |
| 22 | + public ResponseEntity<RsData<Map<String, String>>> getShareLink(@PathVariable Long id) { |
| 23 | + return cocktailRepository.findById(id) |
| 24 | + .map(cocktail -> { |
| 25 | + Map<String, String> response = Map.of( |
| 26 | + // 공유 URL |
| 27 | + "url", "https://www.ssoul.or/cocktails/" + cocktail.getCocktailId(), |
| 28 | + // 공유 제목 |
| 29 | + "title", cocktail.getCocktailName(), |
| 30 | + // 공유 이미지 (선택) |
| 31 | + "imageUrl", cocktail.getCocktailImgUrl() |
| 32 | + ); |
| 33 | + return ResponseEntity.ok(RsData.successOf(response)); |
| 34 | + }) |
| 35 | + .orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND) |
| 36 | + .body(RsData.failOf("칵테일을 찾을 수 없습니다."))); |
| 37 | + } |
| 38 | +} |
0 commit comments