Skip to content

Commit

Permalink
Merge pull request #9 from sopt-makers/feat/#2-project-api
Browse files Browse the repository at this point in the history
[Feat]: Notification 모집알림 기능 v2 API 마이그레이션 작업
  • Loading branch information
softmoca authored Dec 1, 2024
2 parents 9e41c43 + 7064c89 commit e929e76
Show file tree
Hide file tree
Showing 27 changed files with 407 additions and 218 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ bin/
.env

### Some additional ignores
*.DS_Store
*.DS_Store


### Application Properties ###
src/main/resources/application.yml

2 changes: 2 additions & 0 deletions src/main/java/sopt/org/homepage/cache/CacheService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package sopt.org.homepage.cache;

import com.fasterxml.jackson.core.type.TypeReference;
import sopt.org.homepage.common.constants.CacheType;

public interface CacheService {
void put(CacheType cacheType, String key, Object value);
<T> T get(CacheType cacheType, String key, Class<T> type);
<T> T get(CacheType cacheType, String key, TypeReference<T> type);
void evict(CacheType cacheType, String key);
void clearCache(CacheType cacheType);
}
23 changes: 23 additions & 0 deletions src/main/java/sopt/org/homepage/cache/CacheServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sopt.org.homepage.cache;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
Expand All @@ -12,6 +14,7 @@
@Slf4j
public class CacheServiceImpl implements CacheService {
private final CacheManager cacheManager;
private final ObjectMapper objectMapper;

@Override
public void put(CacheType cacheType, String key, Object value) {
Expand All @@ -34,6 +37,26 @@ public <T> T get(CacheType cacheType, String key, Class<T> type) {
return null;
}

@Override
public <T> T get(CacheType cacheType, String key, TypeReference<T> type) {
Cache cache = cacheManager.getCache(cacheType.getCacheName());
if (cache != null) {
Cache.ValueWrapper wrapper = cache.get(key);
if (wrapper != null) {
log.info("Cache HIT: {}", key);
Object value = wrapper.get();
try {
return objectMapper.convertValue(value, type);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Failed to convert cache value", e);
}
}
}
log.info("Cache MISS: {}", key);
return null;
}


@Override
public void evict(CacheType cacheType, String key) {
Cache cache = cacheManager.getCache(cacheType.getCacheName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
@Getter
@RequiredArgsConstructor
public enum CacheType {
MAIN_ENTITY("mainEntityCache", 10, 5);
MAIN_ENTITY("mainEntityCache", 10, 5),
PROJECT_LIST("projectListCache", 100, 24 * 60); // 24시간 캐시


private final String cacheName;
private final int maxSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public abstract class PaginateRequest {

public PaginateRequest(@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer limit) {
this.pageNo = pageNo;
this.limit = limit;
this.pageNo = (pageNo != null) ? pageNo : 1;
this.limit = (limit != null) ? limit : 10;
}

public void setPageNo(Integer pageNo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@

import java.util.List;

@Schema(name = "PaginateResponseDto", description = "페이지네이션 응답")
@Getter
public class PaginateResponse<T> {

private final List<T> data;

@Schema(description = "다음 페이지가 있는지 여부를 나타냄.", requiredMode = Schema.RequiredMode.REQUIRED)
private final Boolean hasNextPage;

@Schema(description = "이전 페이지가 있는지 여부를 나타냄.", requiredMode = Schema.RequiredMode.REQUIRED)
private final Boolean hasPrevPage;
public class PaginateResponseDto<T> {
@Schema(description = "item을 몇개까지 가져올지에 대한 카운트", requiredMode = Schema.RequiredMode.REQUIRED)
private final Integer limit;

@Schema(description = "총 data 들의 갯수", requiredMode = Schema.RequiredMode.REQUIRED)
private final Integer totalCount;
Expand All @@ -25,10 +20,16 @@ public class PaginateResponse<T> {
@Schema(description = "현재 페이지", requiredMode = Schema.RequiredMode.REQUIRED)
private final Integer currentPage;

@Schema(description = "item을 몇개까지 가져올지에 대한 카운트", requiredMode = Schema.RequiredMode.REQUIRED)
private final Integer limit;
private final List<T> data;

@Schema(description = "다음 페이지가 있는지 여부를 나타냄.", requiredMode = Schema.RequiredMode.REQUIRED)
private final Boolean hasNextPage;

@Schema(description = "이전 페이지가 있는지 여부를 나타냄.", requiredMode = Schema.RequiredMode.REQUIRED)
private final Boolean hasPrevPage;


public PaginateResponse(List<T> data, Integer totalCount, Integer limit, int currentPage) {
public PaginateResponseDto(List<T> data, Integer totalCount, Integer limit, int currentPage) {
this.limit = limit;
this.totalCount = totalCount;
this.totalPage = (int) Math.ceil((double) totalCount / limit);
Expand Down
103 changes: 59 additions & 44 deletions src/main/java/sopt/org/homepage/common/mapper/ResponseMapper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package sopt.org.homepage.common.mapper;

import lombok.val;
import org.springframework.stereotype.Component;
import sopt.org.homepage.internal.crew.dto.CrewMeetingVo;
import sopt.org.homepage.internal.crew.dto.StudyResponse;
import sopt.org.homepage.internal.playground.dto.PlaygroundProjectDetailResponse;
import sopt.org.homepage.internal.playground.dto.PlaygroundProjectResponse;
import sopt.org.homepage.internal.playground.dto.PlaygroundProjectResponseDto;
import sopt.org.homepage.internal.playground.dto.Role;
import sopt.org.homepage.project.dto.*;
import sopt.org.homepage.project.dto.record.Category;
import sopt.org.homepage.project.dto.record.Link;
import sopt.org.homepage.project.dto.record.Member;
import sopt.org.homepage.project.dto.response.ProjectDetailResponseDto;
import sopt.org.homepage.project.dto.response.ProjectsResponseDto;
import sopt.org.homepage.project.dto.type.LinkType;
import sopt.org.homepage.semester.dto.SemesterDao;
import sopt.org.homepage.semester.dto.SemestersListResponse;

Expand Down Expand Up @@ -35,52 +39,63 @@ public StudyResponse toStudyResponse(CrewMeetingVo meeting) {
);
}

public ProjectResponse toProjectResponse(PlaygroundProjectResponse project) {
List<Link> links = project.links().stream().map(link -> new Link(LinkType.fromValue(link.linkTitle()), link.linkUrl())).toList();

public ProjectsResponseDto toProjectResponse(PlaygroundProjectResponseDto project) {
List<Link> links = project.links().stream()
.map(link -> new Link(LinkType.fromValue(link.linkTitle()), link.linkUrl()))
.toList();
Category category = new Category(project.category());

return new ProjectResponse(
project.id(),
project.name(),
project.generation(),
category,
project.serviceType(),
project.summary(),
project.detail(),
project.logoImage(),
project.thumbnailImage(),
project.isAvailable(),
project.isFounding(),
links
);
return ProjectsResponseDto.builder()
.id(project.id())
.name(project.name())
.generation(project.generation())
.category(category)
.serviceType(project.serviceType())
.summary(project.summary())
.detail(project.detail())
.logoImage(project.logoImage())
.thumbnailImage(project.thumbnailImage())
.isAvailable(project.isAvailable())
.isFounding(project.isFounding())
.links(links)
.build();
}

public ProjectDetailResponse toProjectDetailResponse(PlaygroundProjectDetailResponse project) {
List<Link> links = project.links().stream().map(link -> new Link(LinkType.fromValue(link.linkTitle()), link.linkUrl())).toList();

public ProjectDetailResponseDto toProjectDetailResponse(PlaygroundProjectDetailResponse project) {
List<Link> links = project.links().stream()
.map(link -> new Link(LinkType.fromValue(link.linkTitle()), link.linkUrl()))
.toList();
Category category = new Category(project.category());
List<Member> members = project.members().stream().map(member -> new Member(
member.memberName(), Role.fromValue(member.memberRole()), member.memberDescription()
)).toList();
List<Member> members = project.members().stream()
.map(member -> new Member(
member.memberName(),
Role.fromValue(member.memberRole()),
member.memberDescription()
))
.toList();
String projectImage = project.images().isEmpty() ? null : project.images().get(0);

return new ProjectDetailResponse(
project.id(),
project.name(),
project.generation(),
category,
project.images().isEmpty() ? "" : project.images().get(0),
project.serviceType(),
project.summary(),
project.detail(),
project.logoImage(),
project.thumbnailImage(),
project.isAvailable(),
project.isFounding(),
links,
project.startAt(),
project.endAt(),
project.createdAt(),
project.updatedAt(),
members
);
return ProjectDetailResponseDto.builder()
.id(project.id())
.name(project.name())
.generation(project.generation())
.category(category)
.projectImage(projectImage)
.serviceType(project.serviceType())
.summary(project.summary())
.detail(project.detail())
.logoImage(project.logoImage())
.thumbnailImage(project.thumbnailImage())
.isAvailable(project.isAvailable())
.isFounding(project.isFounding())
.links(links)
.startAt(project.startAt())
.endAt(project.endAt())
.uploadedAt(project.createdAt())
.updatedAt(project.updatedAt())
.members(members)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ PlaygroundUserResponse getPlaygroundUser(
@RequestHeader("Authorization") String authToken
);

@GetMapping("/internal/api/v1/projects")
List<PlaygroundProjectResponse> getAllProjects(
@RequestHeader("Authorization") String playgroundToken
@GetMapping("/api/v1/projects")
PlaygroundProjectAxiosResponseDto getAllProjects(
@RequestHeader("Authorization") String playgroundToken,
@RequestParam("limit") Integer limit,
@RequestParam("cursor") Integer cursor
);

@GetMapping("/internal/api/v1/projects/{projectId}")
Expand All @@ -35,4 +37,8 @@ PlaygroundMemberListResponse getAllMembers(
);






}
Loading

0 comments on commit e929e76

Please sign in to comment.