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

Add ability API overall average calculation function #153

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dnd.spaced.domain.skill.domain.Skill;
import com.dnd.spaced.domain.skill.domain.repository.SkillRepository;
import com.dnd.spaced.domain.skill.presentation.dto.request.SkillRequest;
import com.dnd.spaced.domain.skill.presentation.dto.response.SkillTotalResponse;
import com.dnd.spaced.domain.skill.presentation.dto.response.SkillTotalScoreResponse;
import com.dnd.spaced.global.resolver.auth.AuthAccountInfo;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -46,16 +47,26 @@ public void addSkill(AuthAccountInfo info, SkillRequest skillRequest) {
* @param info ์œ ์ € ์ •๋ณด
* @return ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์Šคํ‚ฌ ์ ์ˆ˜ ์‘๋‹ต
*/
public Map<Category, SkillTotalScoreResponse> getSkillTotalScore(AuthAccountInfo info) {
public SkillTotalResponse getSkillTotalScore(AuthAccountInfo info) {
List<Skill> skills = skillRepository.findByEmail(info.email());
Map<Category, SkillTotalScoreResponse> response = new HashMap<>();

int sum=0;

for (Skill skill : skills) {
Long totalCount = calculateTotalScore(skill);
sum+=totalCount;
response.put(skill.getCategory(), createSkillTotalScoreResponse(skill, totalCount));
}

return response;
sum/=3;

SkillTotalResponse totalResponse= SkillTotalResponse.builder()
.totalAvgResponse(sum)
.skillTotalScoreResponse(response)
.build();

return totalResponse;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.dnd.spaced.domain.skill.presentation;

import com.dnd.spaced.domain.skill.application.SkillService;
import com.dnd.spaced.domain.skill.domain.Category;
import com.dnd.spaced.domain.skill.presentation.dto.request.SkillRequest;
import com.dnd.spaced.domain.skill.presentation.dto.response.SkillTotalScoreResponse;
import com.dnd.spaced.domain.skill.presentation.dto.response.SkillTotalResponse;
import com.dnd.spaced.global.resolver.auth.AuthAccount;
import com.dnd.spaced.global.resolver.auth.AuthAccountInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/skill")
Expand All @@ -29,7 +26,7 @@ public ResponseEntity<Void> addSkill(
}

@GetMapping("/ability")
public ResponseEntity<Map<Category, SkillTotalScoreResponse>> getAllAbility(@AuthAccount AuthAccountInfo accountInfo) {
public ResponseEntity<SkillTotalResponse> getAllAbility(@AuthAccount AuthAccountInfo accountInfo) {
return ResponseEntity.ok(skillService.getSkillTotalScore(accountInfo));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.dnd.spaced.domain.skill.presentation;

import com.dnd.spaced.domain.skill.domain.Category;
import com.dnd.spaced.domain.skill.presentation.dto.request.SkillRequest;
import com.dnd.spaced.domain.skill.presentation.dto.response.SkillTotalScoreResponse;
import com.dnd.spaced.domain.skill.presentation.dto.response.SkillTotalResponse;
import com.dnd.spaced.global.resolver.auth.AuthAccount;
import com.dnd.spaced.global.resolver.auth.AuthAccountInfo;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -12,8 +11,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;

import java.util.Map;

@Tag(name = "๋Šฅ๋ ฅ์น˜ ๊ด€๋ จ API", description = "ํ€ด์ฆˆ ๊ฒฐ๊ณผ ์ €์žฅ, ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ๋Šฅ๋ ฅ์น˜ ์กฐํšŒ, ์ƒ์œ„ ํผ์„ผํŠธ ์กฐํšŒ")
public interface SwaggerSkillController {

Expand All @@ -24,9 +21,9 @@ ResponseEntity<Void> addSkill(
@RequestBody SkillRequest request
);

@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ๋Šฅ๋ ฅ์น˜ ์กฐํšŒ", description = "์œ ์ €์˜ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ๋Šฅ๋ ฅ์น˜ ์ ์ˆ˜๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. (์ด์ , ๋งž์ถ˜ ๋ฌธ์ œ ์ˆ˜, ์ด ๋ฌธ์ œ ์ˆ˜)")
@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ๋Šฅ๋ ฅ์น˜ ์กฐํšŒ", description = "์œ ์ €์˜ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ๋Šฅ๋ ฅ์น˜ ์ ์ˆ˜ ๋ฐ ์ „์ฒด ํ‰๊ท ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. (์ด์ , ๋งž์ถ˜ ๋ฌธ์ œ ์ˆ˜, ์ด ๋ฌธ์ œ ์ˆ˜, ์ „์ฒด ํ‰๊ท )")
@ApiResponse(responseCode = "200", description = "OK")
ResponseEntity<Map<Category, SkillTotalScoreResponse>> getAllAbility(
ResponseEntity<SkillTotalResponse> getAllAbility(
@Parameter(hidden = true) @AuthAccount AuthAccountInfo accountInfo
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dnd.spaced.domain.skill.presentation.dto.response;

import com.dnd.spaced.domain.skill.domain.Category;
import lombok.Builder;

import java.util.Map;

@Builder
public record SkillTotalResponse(
int totalAvgResponse,
Map<Category,SkillTotalScoreResponse> skillTotalScoreResponse
) {
}
Loading