-
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.
Browse files
Browse the repository at this point in the history
[Feat]:aboutsopt 조회 기능 v2 API 마이그레이션 작업
- Loading branch information
Showing
11 changed files
with
268 additions
and
5 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/sopt/org/homepage/aboutsopt/AboutSoptController.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,30 @@ | ||
package sopt.org.homepage.aboutsopt; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import sopt.org.homepage.aboutsopt.dto.GetAboutSoptResponseDto; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("aboutsopt") | ||
@Tag(name = "AboutSopt") | ||
public class AboutSoptController { | ||
private final AboutSoptService aboutSoptService; | ||
|
||
@GetMapping("") | ||
@Operation(summary = "사용자용 AboutSopt 조회를 조회합니다, Query값이 null이면 최근 기수를 불러옵니다. 해당 기수의 AboutSOPT가 없으면 not found error" | ||
) | ||
public ResponseEntity<GetAboutSoptResponseDto> getAboutSopt( | ||
@Parameter(description = "기수") | ||
@RequestParam(required = false) Integer generation | ||
) { | ||
return ResponseEntity.ok(aboutSoptService.getAboutSopt(generation)); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/sopt/org/homepage/aboutsopt/AboutSoptService.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,76 @@ | ||
package sopt.org.homepage.aboutsopt; | ||
|
||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sopt.org.homepage.aboutsopt.dto.AboutSoptResponseDto; | ||
import sopt.org.homepage.aboutsopt.dto.CoreValueResponseDto; | ||
import sopt.org.homepage.aboutsopt.dto.GetAboutSoptResponseDto; | ||
import sopt.org.homepage.aboutsopt.entity.AboutSoptEntity; | ||
import sopt.org.homepage.aboutsopt.entity.CoreValueEntity; | ||
import sopt.org.homepage.aboutsopt.repository.AboutSoptRepository; | ||
import sopt.org.homepage.exception.NotFoundException; | ||
import sopt.org.homepage.internal.crew.CrewService; | ||
import sopt.org.homepage.internal.playground.PlaygroundService; | ||
import sopt.org.homepage.project.ProjectService; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AboutSoptService { | ||
private final AboutSoptRepository aboutSoptRepository; | ||
private final CrewService crewService; | ||
private final PlaygroundService playgroundService; | ||
private final ProjectService projectService; | ||
|
||
public GetAboutSoptResponseDto getAboutSopt(Integer generation) { | ||
AboutSoptEntity aboutSopt = generation != null ? | ||
aboutSoptRepository.findByIdAndIsPublishedTrue(Long.valueOf(generation)) | ||
.orElseThrow(() -> new NotFoundException("Not found Published about sopt with id: " + generation)) | ||
: aboutSoptRepository.findTopByIsPublishedTrueOrderByIdDesc() | ||
.orElseThrow(() -> new NotFoundException("Not found any published AboutSopt")); | ||
int targetGeneration = 33; // TODO: 현재 34기 데이터가 모이지 않은 관계로 추후 돌려놓아야 함 | ||
|
||
var members = playgroundService.getAllMembers(targetGeneration); | ||
var projects = projectService.findByGeneration(targetGeneration); | ||
var studyCount = crewService.getStudyCount(targetGeneration); | ||
|
||
return GetAboutSoptResponseDto.builder() | ||
.aboutSopt(convertToResponseDto(aboutSopt)) | ||
.activitiesRecords(GetAboutSoptResponseDto.ActivitiesRecords.builder() | ||
.activitiesMemberCount(members.numberOfMembersAtGeneration()) | ||
.projectCounts(projects.size()) | ||
.studyCounts(studyCount) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
private AboutSoptResponseDto convertToResponseDto(AboutSoptEntity entity) { | ||
return AboutSoptResponseDto.builder() | ||
.id((long) entity.getId()) | ||
.isPublished(entity.isPublished()) | ||
.title(entity.getTitle()) | ||
.bannerImage(entity.getBannerImage()) | ||
.coreDescription(entity.getCoreDescription()) | ||
.planCurriculum(entity.getPlanCurriculum()) | ||
.designCurriculum(entity.getDesignCurriculum()) | ||
.androidCurriculum(entity.getAndroidCurriculum()) | ||
.iosCurriculum(entity.getIosCurriculum()) | ||
.webCurriculum(entity.getWebCurriculum()) | ||
.serverCurriculum(entity.getServerCurriculum()) | ||
.coreValues(entity.getCoreValues().stream() | ||
.map(this::convertToCoreValueDto) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
|
||
private CoreValueResponseDto convertToCoreValueDto(CoreValueEntity coreValue) { | ||
return CoreValueResponseDto.builder() | ||
.id((long) coreValue.getId()) | ||
.title(coreValue.getTitle()) | ||
.subTitle(coreValue.getSubTitle()) | ||
.imageUrl(coreValue.getImageUrl()) | ||
.build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/sopt/org/homepage/aboutsopt/dto/AboutSoptResponseDto.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,48 @@ | ||
package sopt.org.homepage.aboutsopt.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Schema(description = "AboutSopt 상세 정보") | ||
public record AboutSoptResponseDto( | ||
@Schema(description = "기수", nullable = false, example = "33") | ||
Long id, | ||
|
||
@Schema(description = "배포 여부", nullable = false, example = "true") | ||
boolean isPublished, | ||
|
||
@Schema(description = "AboutTab 상단 타이틀", nullable = false, example = "SOPT 33기") | ||
String title, | ||
|
||
@Schema(description = "배너 이미지 주소", nullable = false, example = "https://example.com/banner.jpg") | ||
String bannerImage, | ||
|
||
@Schema(description = "핵심가치 설명", nullable = false, example = "SOPT는 혁신과 협업을 추구합니다.") | ||
String coreDescription, | ||
|
||
@Schema(description = "기획파트 커리큘럼", nullable = false, example = "기획 과정 내용") | ||
String planCurriculum, | ||
|
||
@Schema(description = "디자인파트 커리큘럼", nullable = false, example = "디자인 과정 내용") | ||
String designCurriculum, | ||
|
||
@Schema(description = "안드로이드 파트 커리큘럼", nullable = false, example = "안드로이드 과정 내용") | ||
String androidCurriculum, | ||
|
||
@Schema(description = "iOS 파트 커리큘럼", nullable = false, example = "iOS 과정 내용") | ||
String iosCurriculum, | ||
|
||
@Schema(description = "웹 파트 커리큘럼", nullable = false, example = "웹 과정 내용") | ||
String webCurriculum, | ||
|
||
@Schema(description = "서버 파트 커리큘럼", nullable = false, example = "서버 과정 내용") | ||
String serverCurriculum, | ||
|
||
@Schema(description = "코어밸류 리스트", nullable = false) | ||
List<CoreValueResponseDto> coreValues | ||
) { | ||
@Builder | ||
public AboutSoptResponseDto {} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/sopt/org/homepage/aboutsopt/dto/CoreValueResponseDto.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,31 @@ | ||
package sopt.org.homepage.aboutsopt.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Schema(description = "Core Value 응답") | ||
public record CoreValueResponseDto( | ||
@Schema(description = "코어밸류 id") | ||
Long id, | ||
|
||
@Schema(description = "코어밸류", nullable = false) | ||
String title, | ||
|
||
@Schema(description = "코어밸루 설명", nullable = false) | ||
String subTitle, | ||
|
||
@Schema(description = "핵심가치 이미지 주소", nullable = false) | ||
String imageUrl, | ||
|
||
@Schema(description = "생성일자", nullable = false, example = "2024-12-16T12:00:00") | ||
LocalDateTime createdAt, | ||
|
||
@Schema(description = "수정일자", nullable = false, example = "2024-12-16T15:00:00") | ||
LocalDateTime updatedAt | ||
|
||
) { | ||
@Builder | ||
public CoreValueResponseDto {} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/sopt/org/homepage/aboutsopt/dto/GetAboutSoptResponseDto.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,31 @@ | ||
package sopt.org.homepage.aboutsopt.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Schema(description = "AboutSopt 응답") | ||
public record GetAboutSoptResponseDto( | ||
@Schema(description = "AboutSopt 정보") | ||
AboutSoptResponseDto aboutSopt, | ||
|
||
@Schema(description = "활동 기록") | ||
ActivitiesRecords activitiesRecords | ||
) { | ||
@Builder | ||
public GetAboutSoptResponseDto {} | ||
|
||
public record ActivitiesRecords( | ||
@Schema(description = "활동 멤버 수") | ||
int activitiesMemberCount, | ||
|
||
@Schema(description = "프로젝트 수") | ||
int projectCounts, | ||
|
||
@Schema(description = "스터디 수") | ||
Integer studyCounts | ||
) { | ||
@Builder | ||
public ActivitiesRecords {} | ||
} | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
src/main/java/sopt/org/homepage/aboutsopt/repository/AboutSoptRepository.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,13 @@ | ||
package sopt.org.homepage.aboutsopt.repository; | ||
|
||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import sopt.org.homepage.aboutsopt.entity.AboutSoptEntity; | ||
|
||
@Repository | ||
public interface AboutSoptRepository extends JpaRepository<AboutSoptEntity, Long> { | ||
Optional<AboutSoptEntity> findTopByIsPublishedTrueOrderByIdDesc(); | ||
Optional<AboutSoptEntity> findByIdAndIsPublishedTrue(Long id); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/sopt/org/homepage/exception/NotFoundException.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,11 @@ | ||
package sopt.org.homepage.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
public class NotFoundException extends RuntimeException { | ||
public NotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
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
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