-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf73aa1
commit 2e8075f
Showing
10 changed files
with
169 additions
and
8 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
21 changes: 19 additions & 2 deletions
21
place/src/main/java/com/umc/place/exhibition/controller/ExhibitionController.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,11 +1,28 @@ | ||
package com.umc.place.exhibition.controller; | ||
|
||
import com.umc.place.common.BaseException; | ||
import com.umc.place.common.BaseResponse; | ||
import com.umc.place.exhibition.dto.GetExhibitionDetailRes; | ||
import com.umc.place.exhibition.service.ExhibitionService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/exhibitions") | ||
@RequiredArgsConstructor | ||
public class ExhibitionController { | ||
private final ExhibitionService exhibitionService; | ||
|
||
/** | ||
* [GET] 전시회 상세 조회 | ||
*/ | ||
@ResponseBody | ||
@GetMapping("/{exhibitionIdx}/{userIdx}") | ||
public BaseResponse<GetExhibitionDetailRes> getExhibitionDetail(@PathVariable("exhibitionIdx") Long exhibitionIdx, @PathVariable Long userIdx) { // TODO: authService 생성 후 userIdx 삭제 | ||
try { | ||
return new BaseResponse<>(exhibitionService.getExhibitionDetail(exhibitionIdx, userIdx)); // TODO: userIdx -> authService.getUserIdx() 수정 | ||
} catch (BaseException e) { | ||
return new BaseResponse<>(e.getStatus()); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
place/src/main/java/com/umc/place/exhibition/dto/GetExhibitionDetailRes.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.umc.place.exhibition.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class GetExhibitionDetailRes { | ||
private String exhibitionName; | ||
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime startDate; | ||
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDateTime endDate; | ||
private String exhibitionImg; | ||
private String operatingTime; | ||
private String location; | ||
private Integer fee; | ||
private String artist; | ||
private List<Story> stories; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class Story { | ||
private Long storyIdx; | ||
private String storyImg; | ||
private String nickname; | ||
private String userImg; | ||
private Boolean heart; | ||
} | ||
} |
17 changes: 16 additions & 1 deletion
17
place/src/main/java/com/umc/place/exhibition/entity/Category.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,5 +1,20 @@ | ||
package com.umc.place.exhibition.entity; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum Category { | ||
DESIGN, PHOTO | ||
DESIGN(1, "디자인"), | ||
INTERACTIVE(2, "체험형"), | ||
PHOTO(3, "사진"), | ||
INSTALLATION(4, "설치미술"), | ||
ETC(5, "기타"); | ||
|
||
private final int num; | ||
private final String category; | ||
|
||
Category(int num, String category) { | ||
this.num = num; | ||
this.category = category; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
place/src/main/java/com/umc/place/exhibition/service/ExhibitionService.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,10 +1,77 @@ | ||
package com.umc.place.exhibition.service; | ||
|
||
import com.umc.place.common.BaseException; | ||
import com.umc.place.exhibition.dto.GetExhibitionDetailRes; | ||
import com.umc.place.exhibition.entity.Exhibition; | ||
import com.umc.place.exhibition.repository.ExhibitionRepository; | ||
import com.umc.place.story.entity.Story; | ||
import com.umc.place.story.repository.StoryRepository; | ||
import com.umc.place.storyLike.repository.StoryLikeRepository; | ||
import com.umc.place.user.entity.User; | ||
import com.umc.place.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.umc.place.common.BaseResponseStatus.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ExhibitionService { | ||
private final ExhibitionRepository exhibitionRepository; | ||
private final StoryRepository storyRepository; | ||
private final StoryLikeRepository storyLikeRepository; | ||
private final UserRepository userRepository; | ||
|
||
/** | ||
* 전시회 상세 조회 | ||
* @param exhibitionIdx | ||
* @return GetExhibitionDetailRes | ||
* @throws BaseException | ||
*/ | ||
public GetExhibitionDetailRes getExhibitionDetail(Long exhibitionIdx, Long userIdx) throws BaseException{ | ||
try { | ||
Exhibition exhibition = exhibitionRepository.findById(exhibitionIdx).orElseThrow(() -> new BaseException(INVALID_EXHIBITION_IDX)); | ||
|
||
List<GetExhibitionDetailRes.Story> storyList; | ||
if (userRepository.existsById(userIdx)) { | ||
User user = userRepository.findById(userIdx).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); | ||
//List<GetExhibitionDetailRes.Story> storyList = getStoryList(exhibition, user); | ||
storyList = getStoryList(exhibition, user); | ||
} else { | ||
storyList = getStoryListAnonymous(exhibition); | ||
} | ||
|
||
// TODO: S3 설정 완료 후 이미지 가져오는 부분 수정 필요 | ||
return new GetExhibitionDetailRes(exhibition.getExhibitionName(), exhibition.getStartDate(), exhibition.getEndDate(), | ||
exhibition.getExhibitionImg(), exhibition.getOperatingTime(), exhibition.getLocation(), exhibition.getFee(), exhibition.getArtist(), storyList); | ||
} catch (BaseException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new BaseException(DATABASE_ERROR); | ||
} | ||
|
||
} | ||
|
||
// 회원) 스토리 조회 | ||
private List<GetExhibitionDetailRes.Story> getStoryList(Exhibition exhibition, User user) { | ||
return storyRepository.findFirst2ByExhibition(exhibition).stream() | ||
.map(story -> new GetExhibitionDetailRes.Story(story.getStoryIdx(), story.getStoryImg(), story.getUser().getNickname(), | ||
story.getUser().getUserImg(), getLike(user, story))).collect(Collectors.toList()); | ||
} | ||
|
||
private Boolean getLike(User user, Story story) { | ||
// 좋아요 눌렀으면 True 아니면 False | ||
return storyLikeRepository.existsByUserAndStory(user, story); | ||
} | ||
|
||
// 비회원) 스토리 조회 | ||
private List<GetExhibitionDetailRes.Story> getStoryListAnonymous(Exhibition exhibition) { | ||
return storyRepository.findFirst2ByExhibition(exhibition).stream() | ||
.map(story -> new GetExhibitionDetailRes.Story(story.getStoryIdx(), story.getStoryImg(), story.getUser().getNickname(), | ||
story.getUser().getUserImg(), Boolean.FALSE)).collect(Collectors.toList()); | ||
} | ||
|
||
} |
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
4 changes: 4 additions & 0 deletions
4
place/src/main/java/com/umc/place/story/repository/StoryRepository.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,9 +1,13 @@ | ||
package com.umc.place.story.repository; | ||
|
||
import com.umc.place.exhibition.entity.Exhibition; | ||
import com.umc.place.story.entity.Story; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface StoryRepository extends JpaRepository<Story, Long> { | ||
List<Story> findFirst2ByExhibition(Exhibition exhibition); | ||
} |
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
3 changes: 3 additions & 0 deletions
3
place/src/main/java/com/umc/place/storyLike/repository/StoryLikeRepository.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,9 +1,12 @@ | ||
package com.umc.place.storyLike.repository; | ||
|
||
import com.umc.place.story.entity.Story; | ||
import com.umc.place.storyLike.entity.StoryLike; | ||
import com.umc.place.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface StoryLikeRepository extends JpaRepository<StoryLike, Long> { | ||
Boolean existsByUserAndStory(User user, Story story); | ||
} |