Skip to content

Commit

Permalink
Merge pull request #283 from MOONSHOT-Team/feature/#282
Browse files Browse the repository at this point in the history
[Feat] #282 - 소셜 API 구현
  • Loading branch information
0lynny authored May 31, 2024
2 parents ecc0005 + c769667 commit 5db61dd
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 13 deletions.
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())
.limit(10)
.fetch();
}

}

0 comments on commit 5db61dd

Please sign in to comment.