Search in sources :

Example 1 with Report

use of wooteco.prolog.report.domain.Report in project prolog by woowacourse.

the class ReportService method findReportById.

public ReportResponse findReportById(Long reportId) {
    Report persistReport = reportRepository.findById(reportId).orElseThrow(IllegalArgumentException::new);
    List<ReportAbility> persistReportAbilities = reportAbilityRepository.findByReportId(persistReport.getId());
    List<ReportStudylog> persistReportStudylogs = reportStudylogRepository.findByReportId(persistReport.getId());
    return ReportResponse.of(persistReport, persistReportAbilities, persistReportStudylogs);
}
Also used : Report(wooteco.prolog.report.domain.Report) ReportAbility(wooteco.prolog.report.domain.ReportAbility) ReportStudylog(wooteco.prolog.report.domain.ReportStudylog)

Example 2 with Report

use of wooteco.prolog.report.domain.Report in project prolog by woowacourse.

the class ReportService method deleteReport.

@Transactional
public void deleteReport(LoginMember loginMember, Long reportId) {
    Report report = reportRepository.findById(reportId).orElseThrow(IllegalArgumentException::new);
    if (!report.isBelongTo(loginMember.getId())) {
        throw new RuntimeException("내 리포트만 삭제가 가능합니다.");
    }
    reportRepository.deleteById(reportId);
}
Also used : Report(wooteco.prolog.report.domain.Report) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Report

use of wooteco.prolog.report.domain.Report in project prolog by woowacourse.

the class ReportService method createReport.

@Transactional
public ReportResponse createReport(LoginMember loginMember, ReportRequest reportRequest) {
    Report report = reportRepository.save(new Report(reportRequest.getTitle(), reportRequest.getDescription(), loginMember.getId(), LocalDate.parse(reportRequest.getStartDate()), LocalDate.parse(reportRequest.getEndDate())));
    List<HierarchyAbilityResponse> abilities = abilityService.findParentAbilitiesByMemberId(loginMember.getId());
    List<ReportAbility> reportAbilities = reportAbilityRepository.saveAll(abilities.stream().map(it -> new ReportAbility(it.getName(), it.getDescription(), it.getColor(), reportRequest.findWeight(it.getId()), it.getId(), report.getId())).collect(Collectors.toList()));
    List<StudylogAbility> studylogAbilities = studylogAbilityService.findStudylogAbilitiesInPeriod(loginMember.getId(), LocalDate.parse(reportRequest.getStartDate()), LocalDate.parse(reportRequest.getEndDate()));
    List<ReportStudylog> reportStudylogs = reportStudylogRepository.saveAll(studylogAbilities.stream().map(it -> new ReportStudylog(report.getId(), findReportAbilityByAbility(it.getAbility(), reportAbilities), it.getStudylog(), it.getAbility().getName(), it.getAbility().getColor())).collect(Collectors.toList()));
    return ReportResponse.of(report, reportAbilities, reportStudylogs);
}
Also used : StudylogAbility(wooteco.prolog.ability.domain.StudylogAbility) Report(wooteco.prolog.report.domain.Report) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) ReportAbility(wooteco.prolog.report.domain.ReportAbility) ReportStudylog(wooteco.prolog.report.domain.ReportStudylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Report

use of wooteco.prolog.report.domain.Report in project prolog by woowacourse.

the class ReportService method updateReport.

@Transactional
public void updateReport(LoginMember loginMember, Long reportId, ReportUpdateRequest reportUpdateRequest) {
    Report report = reportRepository.findById(reportId).orElseThrow(IllegalArgumentException::new);
    if (!report.isBelongTo(loginMember.getId())) {
        throw new RuntimeException("내 리포트만 수정이 가능합니다.");
    }
    report.update(reportUpdateRequest.getTitle(), reportUpdateRequest.getDescription());
}
Also used : Report(wooteco.prolog.report.domain.Report) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Report

use of wooteco.prolog.report.domain.Report in project prolog by woowacourse.

the class ReportService method findReportsByUsername.

public PageableResponse<ReportResponse> findReportsByUsername(String username, Pageable pageable) {
    Member member = memberService.findByUsername(username);
    Page<Report> reports = reportRepository.findByMemberId(member.getId(), pageable);
    List<ReportResponse> reportResponses = ReportResponse.listOf(reports);
    return PageableResponse.of(reportResponses, reports);
}
Also used : ReportResponse(wooteco.prolog.report.application.dto.ReportResponse) Report(wooteco.prolog.report.domain.Report) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member)

Aggregations

Report (wooteco.prolog.report.domain.Report)5 Transactional (org.springframework.transaction.annotation.Transactional)3 ReportAbility (wooteco.prolog.report.domain.ReportAbility)2 ReportStudylog (wooteco.prolog.report.domain.ReportStudylog)2 HierarchyAbilityResponse (wooteco.prolog.ability.application.dto.HierarchyAbilityResponse)1 StudylogAbility (wooteco.prolog.ability.domain.StudylogAbility)1 LoginMember (wooteco.prolog.login.ui.LoginMember)1 Member (wooteco.prolog.member.domain.Member)1 ReportResponse (wooteco.prolog.report.application.dto.ReportResponse)1