-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from tukcomCD2024/Backend#229/contribution
Backend#229/contribution
- Loading branch information
Showing
6 changed files
with
151 additions
and
34 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...om/Backend/shareNote/domain/Oraganization/DTOs/contributiondto/ContributionResultDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.Backend.shareNote.domain.Oraganization.DTOs.contributiondto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ContributionResultDTO { | ||
private String userId; | ||
private String nickname; | ||
private Integer quizScore; | ||
private Integer likeScore; | ||
} |
20 changes: 20 additions & 0 deletions
20
...main/java/com/Backend/shareNote/domain/Oraganization/controller/ContributeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.Backend.shareNote.domain.Oraganization.controller; | ||
|
||
import com.Backend.shareNote.domain.Oraganization.service.ContributionService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class ContributeController { | ||
private final ContributionService contributionService; | ||
@GetMapping("/contribute/{organizationId}") | ||
public ResponseEntity<?> getContribution(@PathVariable String organizationId){ | ||
return contributionService.getContribution(organizationId); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...src/main/java/com/Backend/shareNote/domain/Oraganization/service/ContributionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.Backend.shareNote.domain.Oraganization.service; | ||
|
||
import com.Backend.shareNote.domain.Oraganization.DTOs.contributiondto.ContributionResultDTO; | ||
import com.Backend.shareNote.domain.Oraganization.entity.Organization; | ||
import com.Backend.shareNote.domain.Oraganization.repository.OrganizationRepository; | ||
import com.Backend.shareNote.domain.User.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ContributionService { | ||
private final OrganizationRepository organizationRepository; | ||
|
||
private final UserRepository userRepository; | ||
|
||
public ResponseEntity<?> getContribution(String organizationId) { | ||
try { | ||
// organization 찾기 | ||
Organization organization = organizationRepository.findById(organizationId) | ||
.orElseThrow(() -> new IllegalArgumentException("해당하는 organization이 없습니다.")); | ||
|
||
|
||
// 우선 organization의 멤버들의 우선 quiz 맞춘게 있으면 +1을 하자 | ||
List<ContributionResultDTO> resultlist = new ArrayList<>(); | ||
|
||
HashMap<String, Integer> quizMap = new HashMap<>(); | ||
HashMap<String, Integer> likeMap = new HashMap<>(); | ||
|
||
// quizMap 초기화 | ||
organization.getMembers().forEach(member -> { | ||
quizMap.put(member, 0); | ||
}); | ||
|
||
// 노트 조회 하면서 퀴즈의 맞춘 목록을 뒤지면서 quizMap 완성하기 | ||
organization.getNotes().forEach(note -> { | ||
//note의 like 정보를 갖고 있는 맵 | ||
Map<String, Set<Organization.BlockLike>> userLikes = note.getLikesInfo().getUserLikes(); | ||
|
||
for (String uuid :note.getLikesInfo().getUserLikes().keySet()) { | ||
likeMap.put(uuid, likeMap.getOrDefault(uuid,0) + userLikes.get(uuid).size() ); | ||
} | ||
|
||
|
||
note.getQuiz().forEach(quiz -> { | ||
for (String key : quiz.getCorrectUser()) { | ||
quizMap.put(key, quizMap.get(key) + 1); | ||
} | ||
// 퀴즈 출제자도 1점 추가 | ||
quizMap.put(quiz.getUserId(), quizMap.get(quiz.getUserId()) + 1); | ||
}); | ||
}); | ||
|
||
organization.getMembers().forEach(member -> { | ||
// 모든 유저에 대해서 닉네임, id, quizScore, (likeScore)를 넣어주자 | ||
ContributionResultDTO contributionResultDTO = new ContributionResultDTO(); | ||
contributionResultDTO.setUserId(member); | ||
|
||
// 닉네임 추가하기 | ||
userRepository.findById(member).ifPresent(user -> { | ||
contributionResultDTO.setNickname(user.getNickname()); | ||
}); | ||
|
||
// quiz 점수 추가 | ||
contributionResultDTO.setQuizScore(quizMap.get(member)); | ||
|
||
// like 점수 추가 (추후에 추가 예정) | ||
contributionResultDTO.setLikeScore(likeMap.getOrDefault(member,0)); | ||
|
||
resultlist.add(contributionResultDTO); | ||
}); | ||
|
||
return ResponseEntity.ok().body(resultlist); | ||
} catch (Exception e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters