Skip to content
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

[Feat] #282 - 소셜 API 구현 #283

Merged
merged 9 commits into from
May 31, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import org.moonshot.objective.dto.request.ModifyObjectiveRequestDto;
import org.moonshot.objective.dto.request.OKRCreateRequestDto;
import org.moonshot.objective.dto.response.DashboardResponseDto;
import org.moonshot.objective.dto.response.HistoryResponseDto;
import org.moonshot.objective.dto.response.history.HistoryResponseDto;
import org.moonshot.objective.dto.response.social.SocialOKRResponseDto;
import org.moonshot.objective.model.Category;
import org.moonshot.objective.model.Criteria;
import org.moonshot.response.MoonshotResponse;
Expand All @@ -21,6 +22,8 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Tag(name = "Objective", description = "Objective 관련 API")
interface ObjectiveApi {

Expand Down Expand Up @@ -71,4 +74,11 @@ ResponseEntity<MoonshotResponse<HistoryResponseDto>> getObjectiveHistory(@LoginU
@RequestParam(required = false) final Category category,
@RequestParam(required = false) final Criteria criteria);

@ApiResponses(value = {
@ApiResponse(responseCode = "2012", description = "소셜 조회에 성공하였습니다."),
@ApiResponse(responseCode = "4100", description = "인증토큰이 존재하지 않습니다.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "소셜 목록 조회")
ResponseEntity<MoonshotResponse<List<SocialOKRResponseDto>>> getObjectiveSocial();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import org.moonshot.objective.dto.request.ModifyObjectiveRequestDto;
import org.moonshot.objective.dto.request.OKRCreateRequestDto;
import org.moonshot.objective.dto.response.DashboardResponseDto;
import org.moonshot.objective.dto.response.HistoryResponseDto;
import org.moonshot.objective.dto.response.history.HistoryResponseDto;
import org.moonshot.objective.dto.response.social.SocialOKRResponseDto;
import org.moonshot.objective.model.Category;
import org.moonshot.objective.model.Criteria;
import org.moonshot.objective.service.ObjectiveService;
Expand All @@ -27,6 +28,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -69,7 +72,14 @@ public ResponseEntity<MoonshotResponse<HistoryResponseDto>> getObjectiveHistory(
@RequestParam(required = false, name = "category") final Category category,
@RequestParam(required = false, name = "criteria") final Criteria criteria) {
HistoryResponseDto response = objectiveService.getObjectiveHistory(userId, year, category, criteria);
return ResponseEntity.ok(MoonshotResponse.success(SuccessType.OK, response));
return ResponseEntity.ok(MoonshotResponse.success(SuccessType.GET_HISTORY_SUCCESS, response));
}

@GetMapping("/social")
@Logging(item = "Social", action = "Get")
public ResponseEntity<MoonshotResponse<List<SocialOKRResponseDto>>> getObjectiveSocial() {
List<SocialOKRResponseDto> response = objectiveService.getObjectiveSocial();
return ResponseEntity.ok(MoonshotResponse.success(SuccessType.GET_SOCIAL_SUCCESS, response));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.moonshot.objective.dto.response;
package org.moonshot.objective.dto.response.history;

import java.util.List;
import org.moonshot.keyresult.model.KeyResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.moonshot.objective.dto.response;
package org.moonshot.objective.dto.response.history;

import java.time.format.DateTimeFormatter;
import java.util.List;

import org.moonshot.objective.model.Objective;

public record HistoryObjectiveListDto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.moonshot.objective.dto.response;
package org.moonshot.objective.dto.response.history;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.moonshot.objective.dto.response;
package org.moonshot.objective.dto.response.history;

import org.moonshot.task.model.Task;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.moonshot.objective.dto.response;
package org.moonshot.objective.dto.response.history;

import java.util.List;

import org.moonshot.objective.model.Objective;

public record ObjectiveGroupByYearDto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.moonshot.objective.dto.response;
package org.moonshot.objective.dto.response.history;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.moonshot.objective.dto.response.social;

import org.moonshot.keyresult.model.KeyResult;

import java.time.format.DateTimeFormatter;
import java.util.List;

public record SocialKeyResultDto(
String krTitle,
String krStartAt,
String krExpireAt,
Long keyResultId,
Integer krIdx,
Long krTarget,
String krMetric,
List<SocialTaskDto> taskList
) {
public static SocialKeyResultDto of(KeyResult keyResult) {
return getSocialKeyResultDto(keyResult);
}

private static SocialKeyResultDto getSocialKeyResultDto(KeyResult keyResult) {
return new SocialKeyResultDto(
keyResult.getTitle(),
keyResult.getPeriod().getStartAt().format(DateTimeFormatter.ISO_LOCAL_DATE),
keyResult.getPeriod().getExpireAt().format(DateTimeFormatter.ISO_LOCAL_DATE),
keyResult.getId(),
keyResult.getIdx(),
keyResult.getTarget(),
keyResult.getMetric(),
keyResult.getTaskList().stream().map(SocialTaskDto::of).toList()
);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.moonshot.objective.dto.response.social;

import org.moonshot.objective.model.Objective;
import org.moonshot.user.model.User;

public record SocialOKRResponseDto(
String category,
String userName,
String userImg,
Long like,
String userIntro,
SocialObjectiveDto okrTreeData
) {
public static SocialOKRResponseDto of(Objective objective) {
return new SocialOKRResponseDto(
objective.getCategory().getValue(),
objective.getUser().getNickname(),
objective.getUser().getImageUrl(),
objective.getHeartCount(),
objective.getUser().getDescription(),
SocialObjectiveDto.of(objective)
);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.moonshot.objective.dto.response.social;

import org.moonshot.objective.model.Objective;

import java.time.format.DateTimeFormatter;
import java.util.List;

public record SocialObjectiveDto(
String objTitle,
String objCategory,
String objContent,
String objStartAt,
String objExpireAt,
List<SocialKeyResultDto> krList
) {
public static SocialObjectiveDto of(Objective objective) {
return new SocialObjectiveDto(
objective.getTitle(),
objective.getCategory().getValue(),
objective.getContent(),
objective.getPeriod().getStartAt().format(DateTimeFormatter.ISO_LOCAL_DATE),
objective.getPeriod().getExpireAt().format(DateTimeFormatter.ISO_LOCAL_DATE),
objective.getKeyResultList().stream().map(SocialKeyResultDto::of).toList()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.moonshot.objective.dto.response.social;

import org.moonshot.task.model.Task;

public record SocialTaskDto(
String taskTitle,
Integer taskIdx
) {
public static SocialTaskDto of(Task task) {
return new SocialTaskDto(
task.getTitle(),
task.getIdx()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import org.moonshot.exception.BadRequestException;
import org.moonshot.exception.NotFoundException;
import org.moonshot.keyresult.service.KeyResultService;
import org.moonshot.log.dto.response.LogResponseDto;
import org.moonshot.objective.dto.request.ModifyIndexRequestDto;
import org.moonshot.objective.dto.request.ModifyObjectiveRequestDto;
import org.moonshot.objective.dto.request.OKRCreateRequestDto;
import org.moonshot.objective.dto.response.DashboardResponseDto;
import org.moonshot.objective.dto.response.HistoryResponseDto;
import org.moonshot.objective.dto.response.ObjectiveGroupByYearDto;
import org.moonshot.objective.dto.response.history.HistoryResponseDto;
import org.moonshot.objective.dto.response.history.ObjectiveGroupByYearDto;
import org.moonshot.objective.dto.response.social.SocialOKRResponseDto;
import org.moonshot.objective.model.Category;
import org.moonshot.objective.model.Criteria;
import org.moonshot.objective.model.IndexService;
Expand Down Expand Up @@ -139,6 +141,14 @@ public HistoryResponseDto getObjectiveHistory(final Long userId, final Integer y
return HistoryResponseDto.of(groupsSortedByCriteria, categories);
}

@Transactional(readOnly = true)
public List<SocialOKRResponseDto> getObjectiveSocial() {
List<Objective> objectives = objectiveRepository.findSocialObjectives();
return objectives.stream()
.map(SocialOKRResponseDto::of)
.toList();
}

@Override
public void modifyIdx(final ModifyIndexRequestDto request, final Long userId) {
Long objectiveCount = objectiveRepository.countAllByUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.moonshot.objective.dto.request.ModifyObjectiveRequestDto;
import org.moonshot.objective.dto.request.OKRCreateRequestDto;
import org.moonshot.objective.dto.response.DashboardResponseDto;
import org.moonshot.objective.dto.response.HistoryResponseDto;
import org.moonshot.objective.dto.response.ObjectiveGroupByYearDto;
import org.moonshot.objective.dto.response.history.HistoryResponseDto;
import org.moonshot.objective.dto.response.history.ObjectiveGroupByYearDto;
import org.moonshot.objective.model.Category;
import org.moonshot.objective.model.Criteria;
import org.moonshot.objective.model.Objective;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum SuccessType {
PATCH_KR_ACHIEVE_SUCCESS(HttpStatus.OK, 2009, "KeyResult 수정 후 목표를 달성하였습니다."),
POST_LOG_ACHIEVE_SUCCESS(HttpStatus.OK, 2010, "체크인 Log 생성 후 목표를 달성하였습니다."),
DELETE_OBJECTIVE_SUCCESS(HttpStatus.OK, 2011, "Objective 삭제를 성공하였습니다."),
GET_SOCIAL_SUCCESS(HttpStatus.OK, 2012,"소셜 조회에 성공하였습니다."),

/**
* 201 CREATED (2100 ~ 2199)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface ObjectiveCustomRepository {

List<Objective> findObjectives(Long userId, Integer year, Category category, Criteria criteria);

List<Objective> findSocialObjectives();

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ private OrderSpecifier<?> order(Criteria criteria) {
return orderSpecifier;
}

@Override
public List<Objective> findSocialObjectives() {
return queryFactory.selectFrom(objective).distinct()
.join(objective.user).fetchJoin()
.join(objective.keyResultList, keyResult).fetchJoin()
.join(keyResult.taskList, task)
.where(objective.isPublic.eq(true))
.orderBy(objective.heartCount.desc(), objective.id.desc())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p4;
이러면 만약 특정 Objective가 인기가 좋아서 하트를 많이 받았다는 상황을 가정해보겠습니다.
그러면 하트를 많이 받았던 Objective는 지속적으로 상단에 노출되는 문제가 있는데요.
이부분에 대해서는 어떻게 생각하실까요?
지금은 임시적이지만 답변 부탁드립니다 :)
저는 개인적으로 heartCount가 중요 factor라는 것에는 동의하지만 aging을 통해 우선순위를 낮춰줄 필요도 있다고 생각합니다 !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요 ... 그 부분까지는 고려못했던 것 같습니다.. 일단 최신순 정렬로 다시 수정해두겠습니다 !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

192c895

수정하였습니다 ~

.limit(10)
.fetch();
}

}
Loading