-
Notifications
You must be signed in to change notification settings - Fork 2
feat : BCSD Lab 활동 api구현 #207
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
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f29b6ea
feat: bcsd lab 활동 가져오기 1차 테스트 통과
seongjae6751 18f3284
refactor: 반환 값을 리스트에서 맵으로 변경
seongjae6751 178c631
refactor: activitiy api 반환값 맵으로 변경
seongjae6751 a28265d
refactor: controller가 ActivityApi를 구현하게 변경
seongjae6751 273e4ab
chore: 불필요한 문자 제거
seongjae6751 53e2a86
style: 서비스 로직 최적화
seongjae6751 a24b38b
chore: 불필요한 코드 삭제
seongjae6751 f8a9a03
chore: 충돌 해결
seongjae6751 9da0bbf
chore: 불필요한 문자 제거
seongjae6751 2a7e86d
chore: 1차 코드 리뷰 피드백 적용
seongjae6751 bbb83d1
chore: 테스트 정보 주정
seongjae6751 31bd612
style: 테스트에 param 적용
seongjae6751 c64f70c
chore: 줄 바꿈 수정
seongjae6751 76571ec
style: 반환 타입 을 dto로 변경
seongjae6751 47cc9ce
style: 컨트롤러 변수의 반환타입을 명시적으로 변경
seongjae6751 e596ab8
chore: 피드백 반영
seongjae6751 212d32d
chore: 테스트 코드 내용 추가
seongjae6751 a1806e5
chore: ActivitiesResponseList Dto이름 변경
seongjae6751 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
29 changes: 29 additions & 0 deletions
29
src/main/java/in/koreatech/koin/domain/activity/controller/ActivityApi.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,29 @@ | ||
| package in.koreatech.koin.domain.activity.controller; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import in.koreatech.koin.domain.activity.dto.ActivitiesResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
|
||
| @Tag(name = "(Normal) Activity", description = "BCSDLab 활동") | ||
| public interface ActivityApi { | ||
|
|
||
| @ApiResponses( | ||
| value = { | ||
| @ApiResponse(responseCode = "200", description = "성공적으로 활동 목록을 조회함"), | ||
| @ApiResponse(responseCode = "404", description = "해당하는 활동이 없음", content = @Content(schema = @Schema(hidden = true))), | ||
| } | ||
| ) | ||
| @Operation(summary = "BCSD Lab 활동 조회") | ||
| @GetMapping("/activities") | ||
| ResponseEntity<ActivitiesResponse> getActivities( | ||
| @RequestParam(required = false) String year | ||
| ); | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/in/koreatech/koin/domain/activity/controller/ActivityController.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,25 @@ | ||
| package in.koreatech.koin.domain.activity.controller; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import in.koreatech.koin.domain.activity.dto.ActivitiesResponse; | ||
| import in.koreatech.koin.domain.activity.service.ActivityService; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class ActivityController implements ActivityApi { | ||
|
|
||
| private final ActivityService activityService; | ||
|
|
||
| @GetMapping("/activities") | ||
| public ResponseEntity<ActivitiesResponse> getActivities( | ||
| @RequestParam(required = false) String year | ||
| ) { | ||
| ActivitiesResponse response = activityService.getActivities(year); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/in/koreatech/koin/domain/activity/dto/ActivitiesResponse.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,18 @@ | ||
| package in.koreatech.koin.domain.activity.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class ActivitiesResponse { | ||
|
|
||
| @JsonProperty("Activities") | ||
| private List<ActivityResponse> activities; | ||
|
|
||
| public ActivitiesResponse(List<ActivityResponse> activities) { | ||
| this.activities = activities; | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/in/koreatech/koin/domain/activity/dto/ActivityResponse.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,56 @@ | ||
| package in.koreatech.koin.domain.activity.dto; | ||
|
|
||
| import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import in.koreatech.koin.domain.activity.model.Activity; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(value = SnakeCaseStrategy.class) | ||
| public record ActivityResponse( | ||
| @Schema(description = "활동 날짜", example = "2019-07-29") | ||
| @JsonFormat(pattern = "yyyy-MM-dd") | ||
| LocalDate date, | ||
|
|
||
| @Schema(description = "삭제 여부", example = "false") | ||
| Boolean isDeleted, | ||
|
|
||
| @Schema(description = "최근 업데이트 일시", example = "2019-08-16 23:01:52") | ||
| @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
| LocalDateTime updatedAt, | ||
|
|
||
| @Schema(description = "초기 생성 일시", example = "2019-08-16 23:01:52") | ||
| @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
| LocalDateTime createdAt, | ||
|
|
||
| @Schema(description = "활동 설명", example = "더 편리한 서비스 제공을 위해 시간표 기능을 추가했습니다.") | ||
| String description, | ||
|
|
||
| @Schema(description = "이미지 URL 목록", example = "[\"https://test2.com.png\", \"https://test3.com.png]\"") | ||
| List<String> imageUrls, | ||
|
|
||
| @Schema(description = "고유 식별자", example = "1") | ||
| Long id, | ||
|
|
||
| @Schema(description = "제목", example = "코인 시간표 기능 추가") | ||
| String title | ||
| ) { | ||
| public static ActivityResponse of(Activity activity, List<String> imageUrls) { | ||
| return new ActivityResponse( | ||
| activity.getDate(), | ||
| activity.getIsDeleted(), | ||
| activity.getUpdatedAt(), | ||
| activity.getCreatedAt(), | ||
| activity.getDescription(), | ||
| imageUrls, | ||
| activity.getId(), | ||
| activity.getTitle() | ||
| ); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/main/java/in/koreatech/koin/domain/activity/model/Activity.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,51 @@ | ||
| package in.koreatech.koin.domain.activity.model; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| import in.koreatech.koin.global.domain.BaseEntity; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Entity | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "activities") | ||
| public class Activity extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id") | ||
| private Long id; | ||
|
|
||
| @Column(name = "title", nullable = false) | ||
| private String title; | ||
|
|
||
| @Column(name = "description") | ||
| private String description; | ||
|
|
||
| @Column(name = "image_urls") | ||
| private String imageUrls; | ||
|
|
||
| @Column(name = "date") | ||
| private LocalDate date; | ||
|
|
||
| @Column(name = "is_deleted") | ||
| private Boolean isDeleted; | ||
|
|
||
| @Builder | ||
| private Activity(Long id, String title, String description, String imageUrls, LocalDate date, Boolean isDeleted) { | ||
| this.id = id; | ||
| this.title = title; | ||
| this.description = description; | ||
| this.imageUrls = imageUrls; | ||
| this.date = date; | ||
| this.isDeleted = isDeleted; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/in/koreatech/koin/domain/activity/repository/ActivityRepository.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,19 @@ | ||
| package in.koreatech.koin.domain.activity.repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.Repository; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import in.koreatech.koin.domain.activity.model.Activity; | ||
|
|
||
| public interface ActivityRepository extends Repository<Activity, Long> { | ||
|
|
||
| @Query(value = "SELECT * FROM activities WHERE is_deleted = 0 AND YEAR(date) = :year", nativeQuery = true) | ||
| List<Activity> getActivitiesByYear(@Param("year") String year); | ||
|
|
||
| List<Activity> findAllByIsDeleted(boolean isDeleted); | ||
|
|
||
| Activity save(Activity activity); | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
src/main/java/in/koreatech/koin/domain/activity/service/ActivityService.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,53 @@ | ||
| package in.koreatech.koin.domain.activity.service; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import in.koreatech.koin.domain.activity.dto.ActivitiesResponse; | ||
| import in.koreatech.koin.domain.activity.dto.ActivityResponse; | ||
| import in.koreatech.koin.domain.activity.model.Activity; | ||
| import in.koreatech.koin.domain.activity.repository.ActivityRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class ActivityService { | ||
|
|
||
| private final ActivityRepository activityRepository; | ||
|
|
||
| public ActivitiesResponse getActivities(String year) { | ||
| List<Activity> activities; | ||
|
|
||
| if (year == null) { | ||
| activities = activityRepository.findAllByIsDeleted(false); | ||
| } else { | ||
| activities = activityRepository.getActivitiesByYear(year); | ||
| } | ||
|
|
||
| List<ActivityResponse> activityResponseList = activities.stream() | ||
| .map(activity -> { | ||
| List<String> imageUrlsList = parseImageUrls(activity.getImageUrls()); | ||
| return ActivityResponse.of(activity, imageUrlsList); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| return new ActivitiesResponse(activityResponseList); | ||
| } | ||
|
|
||
| private List<String> parseImageUrls(String imageUrls) { | ||
| if (imageUrls == null || imageUrls.trim().isEmpty()) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| return Arrays.stream(imageUrls.split(",")) | ||
| .map(String::trim) | ||
| .map(url -> url.replace("\n", "").replace("\r", "")) // 개행 문자 제거 | ||
| .collect(Collectors.toList()); | ||
| } | ||
| } |
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.
R
nativeQuery 없이도 namedQuery로 충분히 작성할 수 있어보이네요
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.
Activity 엔티티 필드에 year정보가 없어서 namedQuery로는 작성을 못할 것 같습니다..!