-
Notifications
You must be signed in to change notification settings - Fork 1
[fix]DTO 수정 및 SQL 변경, CocktailShareController 리펙토링#203 #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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: 14 additions & 20 deletions
34
src/main/java/com/back/domain/cocktail/controller/CocktailShareController.java
This file contains hidden or 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,42 +1,36 @@ | ||
| package com.back.domain.cocktail.controller; | ||
|
|
||
| import com.back.domain.cocktail.repository.CocktailRepository; | ||
| import com.back.domain.cocktail.dto.CocktailShareResponseDto; | ||
| import com.back.domain.cocktail.entity.Cocktail; | ||
| import com.back.domain.cocktail.service.CocktailService; | ||
| import com.back.global.rsData.RsData; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| 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 java.util.Map; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/cocktails") | ||
| @RequiredArgsConstructor | ||
| public class CocktailShareController { | ||
| private final CocktailRepository cocktailRepository; | ||
| private final CocktailService cocktailService; | ||
|
|
||
| @Value("${custom.prod.frontUrl}") | ||
| private String frontUrl; | ||
|
|
||
| @GetMapping("/{id}/share") | ||
| public ResponseEntity<RsData<Map<String, String>>> getShareLink(@PathVariable Long id) { | ||
| return cocktailRepository.findById(id) | ||
| .map(cocktail -> { | ||
| Map<String, String> response = Map.of( | ||
| // 공유 URL | ||
| "url", frontUrl +"/cocktails/" + cocktail.getId(), | ||
| // 공유 제목 | ||
| "title", cocktail.getCocktailName(), | ||
| // 공유 이미지 (선택) | ||
| "imageUrl", cocktail.getCocktailImgUrl() | ||
| ); | ||
| return ResponseEntity.ok(RsData.successOf(response)); | ||
| }) | ||
| .orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND) | ||
| .body(RsData.failOf("칵테일을 찾을 수 없습니다."))); | ||
| public ResponseEntity<RsData<CocktailShareResponseDto>> getShareLink(@PathVariable Long id) { | ||
| Cocktail cocktail = cocktailService.getCocktailById(id); | ||
|
|
||
| CocktailShareResponseDto responseDto = new CocktailShareResponseDto( | ||
| frontUrl + "/cocktails/" + cocktail.getId(), | ||
| cocktail.getCocktailNameKo(), | ||
| cocktail.getCocktailImgUrl() | ||
| ); | ||
|
|
||
| return ResponseEntity.ok(RsData.successOf(responseDto)); | ||
| } | ||
| } | ||
61 changes: 12 additions & 49 deletions
61
src/main/java/com/back/domain/cocktail/dto/CocktailDetailResponseDto.java
This file contains hidden or 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,52 +1,15 @@ | ||
| package com.back.domain.cocktail.dto; | ||
|
|
||
| import com.back.domain.cocktail.entity.Cocktail; | ||
| import com.back.domain.cocktail.enums.AlcoholBaseType; | ||
| import com.back.domain.cocktail.enums.AlcoholStrength; | ||
| import com.back.domain.cocktail.enums.CocktailType; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class CocktailDetailResponseDto { | ||
| private Long cocktailId; | ||
| private String cocktailName; | ||
| private AlcoholStrength alcoholStrength; | ||
| private CocktailType cocktailType; | ||
| private AlcoholBaseType alcoholBaseType; | ||
| private String cocktailImgUrl; | ||
| private String cocktailStory; | ||
| private String ingredient; | ||
| private String recipe; | ||
|
|
||
| public CocktailDetailResponseDto( | ||
| long cocktailId, String cocktailName, | ||
| AlcoholStrength alcoholStrength, CocktailType cocktailType, | ||
| AlcoholBaseType alcoholBaseType, String cocktailImgUrl, | ||
| String cocktailStory, String ingredient, | ||
| String recipe | ||
| ) { | ||
| this.cocktailId = cocktailId; | ||
| this.cocktailName = cocktailName; | ||
| this.alcoholStrength = alcoholStrength; | ||
| this.cocktailType = cocktailType; | ||
| this.alcoholBaseType = alcoholBaseType; | ||
| this.cocktailImgUrl = cocktailImgUrl; | ||
| this.cocktailStory = cocktailStory; | ||
| this.ingredient = ingredient; | ||
| this.recipe = recipe; | ||
| } | ||
|
|
||
| public CocktailDetailResponseDto(Cocktail cocktail) { | ||
| this.cocktailId = cocktail.getId(); | ||
| this.cocktailName = cocktail.getCocktailName(); | ||
| this.alcoholStrength = cocktail.getAlcoholStrength(); | ||
| this.cocktailType = cocktail.getCocktailType(); | ||
| this.alcoholBaseType = cocktail.getAlcoholBaseType(); | ||
| this.cocktailImgUrl = cocktail.getCocktailImgUrl(); | ||
| this.cocktailStory = cocktail.getCocktailStory(); | ||
| this.ingredient = cocktail.getIngredient(); | ||
| this.recipe = cocktail.getRecipe(); | ||
| } | ||
| public record CocktailDetailResponseDto( | ||
| Long cocktailId, | ||
| String cocktailName, | ||
| String cocktailNameKo, | ||
| String alcoholStrength, | ||
| String cocktailType, | ||
| String alcoholBaseType, | ||
| String cocktailImgUrl, | ||
| String cocktailStory, | ||
| String ingredient, | ||
| String recipe | ||
| ) { | ||
| } |
23 changes: 9 additions & 14 deletions
23
src/main/java/com/back/domain/cocktail/dto/CocktailSearchResponseDto.java
This file contains hidden or 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,39 +1,34 @@ | ||
| package com.back.domain.cocktail.dto; | ||
|
|
||
| import com.back.domain.cocktail.enums.AlcoholBaseType; | ||
| import com.back.domain.cocktail.enums.AlcoholStrength; | ||
| import com.back.domain.cocktail.enums.CocktailType; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| public class CocktailSearchResponseDto { | ||
|
|
||
| private long cocktailId; | ||
| private String cocktailName; | ||
| private AlcoholStrength alcoholStrength; | ||
| private CocktailType cocktailType; | ||
| private AlcoholBaseType alcoholBaseType; | ||
| private String cocktailNameKo; | ||
| private String alcoholStrength; | ||
| private String cocktailType; | ||
| private String alcoholBaseType; | ||
| private String cocktailImgUrl; | ||
| private String cocktailStory; | ||
| private LocalDateTime createdAt; | ||
|
|
||
| public CocktailSearchResponseDto(long cocktailId, String cocktailName, | ||
| AlcoholStrength alcoholStrength, CocktailType cocktailType, | ||
| AlcoholBaseType alcoholBaseType, String cocktailImgUrl, | ||
| String cocktailStory, LocalDateTime createdAt) { | ||
| public CocktailSearchResponseDto(long cocktailId, String cocktailName, String cocktailNameKo, | ||
| String alcoholStrength, String cocktailType, | ||
| String alcoholBaseType, String cocktailImgUrl, | ||
| String cocktailStory) { | ||
| this.cocktailId = cocktailId; | ||
| this.cocktailName = cocktailName; | ||
| this.cocktailNameKo = cocktailNameKo; | ||
| this.alcoholStrength = alcoholStrength; | ||
| this.cocktailType = cocktailType; | ||
| this.alcoholBaseType = alcoholBaseType; | ||
| this.cocktailImgUrl = cocktailImgUrl; | ||
| this.cocktailStory = cocktailStory; | ||
| this.createdAt = createdAt; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/back/domain/cocktail/dto/CocktailShareResponseDto.java
This file contains hidden or 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,14 @@ | ||
| package com.back.domain.cocktail.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class CocktailShareResponseDto { | ||
| private String url; | ||
| private String title; | ||
| private String imageUrl; | ||
| } |
32 changes: 17 additions & 15 deletions
32
src/main/java/com/back/domain/cocktail/dto/CocktailSummaryResponseDto.java
This file contains hidden or 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,19 +1,21 @@ | ||
| package com.back.domain.cocktail.dto; | ||
|
|
||
| import com.back.domain.cocktail.enums.AlcoholStrength; | ||
| import lombok.Getter; | ||
| import com.back.domain.cocktail.entity.Cocktail; | ||
|
|
||
| @Getter | ||
| public class CocktailSummaryResponseDto { | ||
| private Long cocktailId; | ||
| private String cocktailName; | ||
| private String cocktailImgUrl; | ||
| private AlcoholStrength alcoholStrength; | ||
|
|
||
| public CocktailSummaryResponseDto(Long id, String name, String imageUrl, AlcoholStrength alcoholStrength) { | ||
| this.cocktailId = id; | ||
| this.cocktailName = name; | ||
| this.cocktailImgUrl = imageUrl; | ||
| this.alcoholStrength = alcoholStrength; | ||
| public record CocktailSummaryResponseDto( | ||
| Long cocktailId, | ||
| String cocktailName, | ||
| String cocktailNameKo, | ||
| String cocktailImgUrl, | ||
| String alcoholStrength // Enum 대신 String | ||
| ) { | ||
| public CocktailSummaryResponseDto(Cocktail cocktail) { | ||
| this( | ||
| cocktail.getId(), | ||
| cocktail.getCocktailName(), | ||
| cocktail.getCocktailNameKo(), | ||
| cocktail.getCocktailImgUrl(), | ||
| cocktail.getAlcoholStrength().getDescription() // 설명으로 변환 | ||
| ); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
칵테일이 없는 경우는 없을 거라서 예외 발생이 필요없어진 거죵?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orElseGet()을 제거한 이유는 Service에서 칵테일이 없으면 orElseThrow예외를 던지도록 구조를 바꾸었기 때문입니당.