Skip to content

Commit

Permalink
Merge pull request #83 from yomankum-project/refactor/80-loginuserinfo
Browse files Browse the repository at this point in the history
fix : develop 머지 충돌 해결
  • Loading branch information
hyungzin0309 authored Jun 3, 2024
2 parents 3a8e7f4 + ff52353 commit 5c0988b
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 171 deletions.
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.account.yomankum.accountBook.dto.response.AccountBookSimpleDto;
import com.account.yomankum.accountBook.service.AccountBookFinder;
import com.account.yomankum.accountBook.service.AccountBookService;
import com.account.yomankum.auth.common.Auth;
import com.account.yomankum.auth.common.LoginUser;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand All @@ -21,28 +23,28 @@ public class AccountBookController {
private final AccountBookFinder accountBookFinder;

@PostMapping
public Long create(@RequestBody AccountBookCreateRequest accountWriteDto){
return accountBookService.create(accountWriteDto);
public Long create(@Auth LoginUser loginUser, @RequestBody AccountBookCreateRequest accountWriteDto){
return accountBookService.create(accountWriteDto, loginUser.getUserId());
}

@PutMapping("/{id}")
public void update(@PathVariable Long id, @RequestBody String name){
accountBookService.update(id, name);
public void update(@Auth LoginUser loginUser, @PathVariable Long id, @RequestBody String name){
accountBookService.update(id, name, loginUser.getUserId());
}

@DeleteMapping("/{id}")
public void delete(@PathVariable("id")Long id){
accountBookService.delete(id);
public void delete(@Auth LoginUser loginUser, @PathVariable("id")Long id){
accountBookService.delete(id, loginUser.getUserId());
}

@GetMapping
public List<AccountBookSimpleDto> get(){
return accountBookFinder.findByUser();
public List<AccountBookSimpleDto> get(@Auth LoginUser loginUser){
return accountBookFinder.findByUser(loginUser.getUserId());
}

@PostMapping("/{id}/invite")
public void invite(@PathVariable("id") Long id, @RequestBody AccountBookInviteRequest accountBookInviteRequest) {
accountBookService.invite(id, accountBookInviteRequest);
public void invite(@Auth LoginUser loginUser, @PathVariable("id") Long id, @RequestBody AccountBookInviteRequest accountBookInviteRequest) {
accountBookService.invite(id, accountBookInviteRequest, loginUser.getUserId());
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.account.yomankum.accountBook.controller;

import com.account.yomankum.accountBook.domain.tag.Tag;
import com.account.yomankum.accountBook.dto.request.MainTagRequest;
import com.account.yomankum.accountBook.dto.response.TagResponse;
import com.account.yomankum.accountBook.service.MainTagFinder;
import com.account.yomankum.accountBook.service.MainTagService;
import com.account.yomankum.statistics.service.impl.monthly.vo.MonthlyTotal;
import com.account.yomankum.auth.common.Auth;
import com.account.yomankum.auth.common.LoginUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -40,20 +40,20 @@ public List<TagResponse> getMainTags(@PathVariable Long accountBookId){

@PostMapping("/{accountBookId}")
@Operation(summary = "대분류 태그 등록")
public void registerMainTag(@PathVariable Long accountBookId, @RequestBody MainTagRequest mainTagRequest){
tagService.create(accountBookId, mainTagRequest);
public void registerMainTag(@PathVariable Long accountBookId, @RequestBody MainTagRequest mainTagRequest, @Auth LoginUser loginUser){
tagService.create(accountBookId, mainTagRequest, loginUser.getUserId());
}

@PutMapping("/{tagId}")
@Operation(summary = "태그 변경")
public void updateTag(@PathVariable Long tagId, @RequestBody MainTagRequest mainTagRequest){
tagService.update(tagId, mainTagRequest);
public void updateTag(@PathVariable Long tagId, @RequestBody MainTagRequest mainTagRequest, @Auth LoginUser loginUser){
tagService.update(tagId, mainTagRequest, loginUser.getUserId());
}

@DeleteMapping("/{tagId}")
@Operation(summary = "태그 삭제")
public void deleteTag(@PathVariable Long tagId){
tagService.delete(tagId);
public void deleteTag(@PathVariable Long tagId, @Auth LoginUser loginUser){
tagService.delete(tagId, loginUser.getUserId());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.account.yomankum.accountBook.dto.request.RecordUpdateRequest;
import com.account.yomankum.accountBook.service.RecordFinder;
import com.account.yomankum.accountBook.service.RecordService;
import com.account.yomankum.auth.common.Auth;
import com.account.yomankum.auth.common.LoginUser;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,23 +30,23 @@ public class RecordController {
private final RecordService recordService;

@GetMapping("/{accountBookId}")
public List<Record> searchRecords(@PathVariable Long accountBookId, RecordSearchCondition condition){
return recordFinder.searchRecords(accountBookId, condition);
public List<Record> searchRecords(@Auth LoginUser loginUser, @PathVariable Long accountBookId, RecordSearchCondition condition){
return recordFinder.searchRecords(accountBookId, condition, loginUser.getUserId());
}

@PostMapping("/{accountBookId}")
public void addRecord(@PathVariable Long accountBookId, @RequestBody RecordCreateRequest recordWriteDto){
recordService.addRecord(accountBookId, recordWriteDto);
public void addRecord(@Auth LoginUser loginUser, @PathVariable Long accountBookId, @RequestBody RecordCreateRequest recordWriteDto){
recordService.addRecord(accountBookId, recordWriteDto, loginUser.getUserId());
}

@PutMapping("/{recordId}")
public void updateRecord(@PathVariable Long recordId, @RequestBody RecordUpdateRequest request){
recordService.updateRecord(recordId, request);
public void updateRecord(@Auth LoginUser loginUser, @PathVariable Long recordId, @RequestBody RecordUpdateRequest request){
recordService.updateRecord(recordId, request, loginUser.getUserId());
}

@DeleteMapping("/{recordId}")
public void deleteRecord(@PathVariable Long recordId){
recordService.deleteRecord(recordId);
public void deleteRecord(@Auth LoginUser loginUser, @PathVariable Long recordId){
recordService.deleteRecord(recordId, loginUser.getUserId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.account.yomankum.accountBook.dto.response.AccountBookSimpleDto;
import com.account.yomankum.common.exception.BadRequestException;
import com.account.yomankum.common.exception.Exception;
import com.account.yomankum.common.service.SessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -18,11 +17,9 @@
public class AccountBookFinder {

private final AccountBookRepository accountBookRepository;
private final SessionService sessionService;

@Transactional(readOnly = true)
public List<AccountBookSimpleDto> findByUser() {
Long userId = sessionService.getSessionUserId();
public List<AccountBookSimpleDto> findByUser(Long userId) {
return accountBookRepository.findByCreateUser(userId.toString())
.stream().map(AccountBookSimpleDto::from).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import com.account.yomankum.accountBook.dto.request.AccountBookInviteRequest;
import com.account.yomankum.common.exception.BadRequestException;
import com.account.yomankum.common.exception.Exception;
import com.account.yomankum.common.service.SessionService;
import com.account.yomankum.notice.service.NoticeService;
import com.account.yomankum.user.domain.User;
import com.account.yomankum.user.service.UserFinder;
import com.account.yomankum.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -26,46 +24,43 @@ public class AccountBookService {
private final AccountBookRepository accountBookRepository;
private final AccountBookUserRepository accountBookUserRepository;
private final AccountBookFinder accountBookFinder;
private final SessionService sessionService;
private final NoticeService noticeService;
private final UserFinder userFinder;

public Long create(AccountBookCreateRequest accountBookWriteDto) {
// 가계부유저 추가
Long sessionUserId = sessionService.getSessionUserId();
User user = userFinder.findById(sessionUserId).orElseThrow(() -> new BadRequestException(Exception.USER_NOT_FOUND));
public Long create(AccountBookCreateRequest accountBookWriteDto, Long requesterId) {
User user = userFinder.findById(requesterId).orElseThrow(() -> new BadRequestException(Exception.USER_NOT_FOUND));

AccountBook accountBook = accountBookWriteDto.toAccountBookEntity();
addNewUser(accountBook, user);
accountBookRepository.save(accountBook);

List<Tag> defaultTags = DefaultTag.getDefaultMainTags();
accountBook.addTags(defaultTags, sessionUserId);
accountBook.addTags(defaultTags, requesterId);

return accountBook.getId();
}

public void update(Long id, String name) {
AccountBook accountBook = accountBookFinder.findById(id);
accountBook.updateName(name, sessionService.getSessionUserId());
public void update(Long accountBookId, String name, Long requesterId) {
AccountBook accountBook = accountBookFinder.findById(accountBookId);
accountBook.updateName(name, requesterId);
}

public void delete(Long id) {
AccountBook accountBook = accountBookFinder.findById(id);
Long sessionUserId = sessionService.getSessionUserId();
AccountBookRole accountBookRole = accountBook.getAccountBookRole(sessionUserId);
public void delete(Long accountBookId, Long requesterId) {
AccountBook accountBook = accountBookFinder.findById(accountBookId);
AccountBookRole accountBookRole = accountBook.getAccountBookRole(requesterId);

if (accountBookRole.equals(AccountBookRole.OWNER)) {
accountBookRepository.deleteById(id);
accountBookRepository.deleteById(accountBookId);
} else {
accountBook.delete(sessionUserId);
accountBookUserRepository.deleteByUserId(sessionUserId);
accountBook.delete(requesterId);
accountBookUserRepository.deleteByUserId(requesterId);
}
}

public void invite(Long id, AccountBookInviteRequest accountBookInviteRequest) {
AccountBook accountBook = accountBookFinder.findById(id);
accountBook.checkAuthorizedUser(sessionService.getSessionUserId());
// TODO 공유 가계부 초대 개발
public void invite(Long accountBookId, AccountBookInviteRequest accountBookInviteRequest, Long requesterId) {
AccountBook accountBook = accountBookFinder.findById(accountBookId);
accountBook.checkAuthorizedUser(requesterId);

User user = userFinder.findByEmail(accountBookInviteRequest.email()).orElseThrow(() -> new BadRequestException(Exception.USER_NOT_FOUND));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.account.yomankum.accountBook.dto.request.MainTagRequest;
import com.account.yomankum.common.exception.BadRequestException;
import com.account.yomankum.common.exception.Exception;
import com.account.yomankum.common.service.SessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -16,25 +15,24 @@ public class MainTagService {

private final AccountBookFinder accountBookFinder;
private final MainTagRepository mainTagRepository;
private final SessionService sessionService;

public Tag create(Long accountBookId, MainTagRequest mainTagCreateRequest) {
public Tag create(Long accountBookId, MainTagRequest mainTagCreateRequest, Long requesterId) {
Tag tag = mainTagCreateRequest.toEntity();
mainTagRepository.save(tag);
AccountBook accountBook = accountBookFinder.findById(accountBookId);
accountBook.addTag(tag, sessionService.getSessionUserId());
accountBook.addTag(tag, requesterId);
return tag;
}

public void delete(Long tagId) {
public void delete(Long tagId, Long requesterId) {
Tag tag = findTag(tagId);
tag.delete(sessionService.getSessionUserId());
tag.delete(requesterId);
mainTagRepository.delete(tag);
}

public Tag update(Long tagId, MainTagRequest mainTagRequest) {
public Tag update(Long tagId, MainTagRequest mainTagRequest, Long requesterId) {
Tag tag = findTag(tagId);
tag.update(mainTagRequest.tagName(), sessionService.getSessionUserId());
tag.update(mainTagRequest.tagName(), requesterId);
return tag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.account.yomankum.accountBook.domain.record.Record;
import com.account.yomankum.accountBook.domain.record.RecordRepository;
import com.account.yomankum.accountBook.domain.record.RecordSearchCondition;
import com.account.yomankum.common.service.SessionService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -17,11 +16,10 @@ public class RecordFinder {

private final RecordRepository repository;
private final AccountBookFinder accountBookFinder;
private final SessionService sessionService;

public List<Record> searchRecords(Long accountBookId, RecordSearchCondition condition) {
public List<Record> searchRecords(Long accountBookId, RecordSearchCondition condition, Long requesterId) {
AccountBook accountBook = accountBookFinder.findById(accountBookId);
accountBook.checkAuthorizedUser(sessionService.getSessionUserId());
accountBook.checkAuthorizedUser(requesterId);
return repository.searchRecords(accountBookId, condition);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.account.yomankum.accountBook.dto.request.RecordUpdateRequest;
import com.account.yomankum.common.exception.BadRequestException;
import com.account.yomankum.common.exception.Exception;
import com.account.yomankum.common.service.SessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -20,25 +19,24 @@ public class RecordService {

private final RecordRepository recordRepository;
private final AccountBookFinder accountBookFinder;
private final SessionService sessionService;
private final MainTagFinder mainTagFinder;

public void addRecord(Long accountBookId, RecordCreateRequest dto){
public void addRecord(Long accountBookId, RecordCreateRequest dto, Long requesterId){
Tag mainTag = mainTagFinder.findById(dto.mainTagId());
Record record = dto.toEntity(mainTag);
AccountBook accountBook = accountBookFinder.findById(accountBookId);
accountBook.addRecord(record, sessionService.getSessionUserId());
accountBook.addRecord(record, requesterId);
recordRepository.save(record);
}

public void updateRecord(Long recordId, RecordUpdateRequest request) {
public void updateRecord(Long recordId, RecordUpdateRequest request, Long requesterId){
Record record = recordRepository.findById(recordId).orElseThrow(()->new BadRequestException(Exception.RECORD_BOOK_NOT_FOUND));
Tag tag = mainTagFinder.findById(request.mainTagId());
record.update(request, tag, sessionService.getSessionUserId());
record.update(request, tag, requesterId);
}

public void deleteRecord(Long recordId){
public void deleteRecord(Long recordId, Long requesterId){
Record record = recordRepository.findById(recordId).orElseThrow(()->new BadRequestException(Exception.RECORD_BOOK_NOT_FOUND));
record.delete(sessionService.getSessionUserId());
record.delete(requesterId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.account.yomankum.statistics.controller;

import com.account.yomankum.auth.common.Auth;
import com.account.yomankum.auth.common.LoginUser;
import com.account.yomankum.statistics.dto.StatisticsResponse;
import com.account.yomankum.statistics.service.StatisticsService;
import com.account.yomankum.statistics.service.impl.monthly.MonthlyTotalStatisticRequest;
Expand Down Expand Up @@ -30,20 +32,20 @@ public class StatisticsController {

@GetMapping(value = "/monthly/total", produces = "application/json")
@Operation(summary = "월별 지출입 총합 통계", responses = {@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = MonthlyTotal.class))))})
public List<MonthlyTotal> getMonthlyTotalData(@Valid MonthlyTotalStatisticRequest request){
return statisticsService.getMonthlyTotalData(request);
public List<MonthlyTotal> getMonthlyTotalData(@Auth LoginUser loginUser, @Valid MonthlyTotalStatisticRequest request){
return statisticsService.getMonthlyTotalData(request, loginUser.getUserId());
}

@GetMapping(value = "/monthly/expenditure/mainTagRate", produces = "application/json")
@Operation(summary = "한 달 동안의 대분류 비율 통계", responses = {@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagRate.class))))})
public List<TagRate> getMonthlyExpenditureMainTagRate(@Valid MainTagRateStatisticsRequest request){
return statisticsService.getMonthlyMainTagRate(request);
public List<TagRate> getMonthlyExpenditureMainTagRate(@Auth LoginUser loginUser, @Valid MainTagRateStatisticsRequest request){
return statisticsService.getMonthlyMainTagRate(request, loginUser.getUserId());
}

@GetMapping(value = "/monthly/expenditure/subTagRate", produces = "application/json")
@Operation(summary = "(한 달 동안의) 하나의 대분류 내 소분류 비율", responses = {@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagRate.class))))})
public List<TagRate> getMonthlyExpenditureSubTagRate(@Valid SubTagRateStatisticsRequest request){
return statisticsService.getMonthlySubTagRate(request);
public List<TagRate> getMonthlyExpenditureSubTagRate(@Auth LoginUser loginUser, @Valid SubTagRateStatisticsRequest request){
return statisticsService.getMonthlySubTagRate(request, loginUser.getUserId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public interface StatisticsHandler {

StatisticsType getSupportType();
List<StatisticsResponse> getData(StatisticsRequest request);
List<StatisticsResponse> getData(StatisticsRequest request, Long requesterId);

}
Loading

0 comments on commit 5c0988b

Please sign in to comment.