Skip to content

Commit

Permalink
Merge pull request #14 from sopt-makers/feat/#13-aboutsopt-api
Browse files Browse the repository at this point in the history
[Feat]:aboutsopt 조회 기능 v2 API 마이그레이션 작업
  • Loading branch information
softmoca authored Dec 19, 2024
2 parents 8947860 + 210d894 commit 7a32a57
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 5 deletions.
30 changes: 30 additions & 0 deletions src/main/java/sopt/org/homepage/aboutsopt/AboutSoptController.java
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 src/main/java/sopt/org/homepage/aboutsopt/AboutSoptService.java
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();
}
}
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 {}
}
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 {}
}
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 {}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package sopt.org.homepage.entity;
package sopt.org.homepage.aboutsopt.entity;

import jakarta.persistence.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "\"AboutSopt\"")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AboutSoptEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
Expand Down Expand Up @@ -49,4 +55,7 @@ public class AboutSoptEntity {
@Column(name = "\"updatedAt\"", nullable = false)
private Timestamp updatedAt;

@OneToMany(mappedBy = "aboutSopt", fetch = FetchType.LAZY)
private List<CoreValueEntity> coreValues;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package sopt.org.homepage.entity;
package sopt.org.homepage.aboutsopt.entity;

import jakarta.persistence.*;

import java.sql.Timestamp;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "\"CoreValue\"")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CoreValueEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
Expand All @@ -31,4 +36,8 @@ public class CoreValueEntity {
@Column(name = "\"aboutSoptId\"", nullable = true)
private Integer aboutSoptId;

@ManyToOne
@JoinColumn(name = "\"aboutSoptId\"", insertable = false, updatable = false)
private AboutSoptEntity aboutSopt;

}
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 src/main/java/sopt/org/homepage/exception/NotFoundException.java
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public ProjectDetailResponseDto getProjectDetail(Long projectId){
return responseMapper.toProjectDetailResponse(projectResponse);
}

public PlaygroundMemberListResponse getAllMembers(String part, Integer generation) {
public PlaygroundMemberListResponse getAllMembers(Integer generation) {
return playgroundClient.getAllMembers(authConfig.getPlaygroundToken(), null, generation);
}
}
9 changes: 7 additions & 2 deletions src/main/java/sopt/org/homepage/project/ProjectService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sopt.org.homepage.project;

import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -38,6 +39,10 @@ public ProjectDetailResponseDto findOne(Long projectId) {
return playgroundService.getProjectDetail(projectId);
}



public List<ProjectsResponseDto> findByGeneration(Integer generation) {
var allProjects = findAll(new GetProjectsRequestDto(1, Integer.MAX_VALUE, null, null));
return allProjects.stream()
.filter(project -> project.getGeneration() != null && project.getGeneration().equals(generation))
.collect(Collectors.toList());
}
}

0 comments on commit 7a32a57

Please sign in to comment.