Skip to content

Commit

Permalink
Merge pull request #35 from Happy-New-Here/feature-#34
Browse files Browse the repository at this point in the history
feat: account 관련 수정사항
  • Loading branch information
kwonssshyeon authored Dec 23, 2023
2 parents 2f615e7 + 4da6ef7 commit 3db00d4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.HappyNewHere.dto.request.AccountRequestDto;
import com.example.HappyNewHere.service.AccountService;
import com.example.HappyNewHere.service.KakaoService;
import com.example.HappyNewHere.utils.AuthenticateUtils;
import com.example.HappyNewHere.utils.JwtUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -21,7 +22,7 @@
@RequiredArgsConstructor
@CrossOrigin
public class AccountController {

private final AuthenticateUtils authenticateUtils;
private final AccountService accountService;
private final KakaoService kakaoService;

Expand All @@ -39,7 +40,8 @@ public ResponseEntity<?> login(
@GetMapping("/userInfo")
public ResponseEntity<?> personalInfo(Authentication authentication
) {
return ResponseEntity.ok().body(accountService.findAccount(Long.parseLong(authentication.getName())));
Long accountId = authenticateUtils.getLongId(authentication);
return ResponseEntity.ok().body(accountService.findAccount(accountId));
}

// 유저 id 뿐만 아니라 발급한 토큰 또한 필요함.
Expand All @@ -49,8 +51,9 @@ public ResponseEntity<?> personalInfo(
@RequestParam String userId,
@RequestParam String stateMsg
) {
accountService.addUserId(Long.parseLong(authentication.getName()), userId);
accountService.addStateMsg(Long.parseLong(authentication.getName()), stateMsg);
Long accountId = authenticateUtils.getLongId(authentication);
accountService.addUserId(accountId, userId);
accountService.addStateMsg(accountId, stateMsg);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
import com.example.HappyNewHere.utils.AuthenticateUtils;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value="/message")
@CrossOrigin
@RequiredArgsConstructor
public class MessageController {
private final MessageService messageService;
private final AuthenticateUtils authenticateUtils;

// 권한들 넣어주셈요
public MessageController(MessageService messageService, AuthenticateUtils authenticateUtils) {
this.messageService = messageService;
this.authenticateUtils = authenticateUtils;
}

@PostMapping("/create")
public MessageDto createMessage(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/HappyNewHere/domain/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public Account(Long accountId, String nickname, String userId, String profileImg
this.stateMsg = stateMsg;
}

public static Account of(Long accountId, AccountRequestDto accountRequestDto) {
return new Account(accountId, accountRequestDto.nickname(), accountRequestDto.userId(), accountRequestDto.profileImg(), accountRequestDto.stateMsg());
public static Account of(Long accountId, AccountRequestDto accountRequestDto, String profileImg) {
return new Account(accountId, accountRequestDto.nickname(), accountRequestDto.userId(), profileImg, accountRequestDto.stateMsg());
}

public Account(Long accountId) {
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/example/HappyNewHere/dto/MessageDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class MessageDto {
private Long messageId;
private LocalDateTime createdDate;
private String context;
private Long sender; // kakaoI
private Long receiver; //
private String sender;
private String receiver;
private int paperNum;
private boolean anonymous;

public MessageDto(Long messageId, LocalDateTime createdDate, String context, Long sender, Long receiver,
public MessageDto(Long messageId, LocalDateTime createdDate, String context, String sender, String receiver,
int paperNum, boolean anonymous) {
this.messageId = messageId;
this.createdDate = createdDate;
Expand All @@ -27,7 +27,15 @@ public MessageDto(Long messageId, LocalDateTime createdDate, String context, Lon
this.anonymous = anonymous;
}

public static MessageDto from(Messages messages) {
return new MessageDto(messages.getMessageId(), messages.getCreatedDate(), messages.getContext(), messages.getSender(), messages.getReceiver(), messages.getPaperNum(), messages.isAnonymous());
public static MessageDto from(Messages messages,String sender,String receiver) {
return new MessageDto(
messages.getMessageId(),
messages.getCreatedDate(),
messages.getContext(),
sender,
receiver,
messages.getPaperNum(),
messages.isAnonymous()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public AccountDto updateAccount(Long accountId, AccountRequestDto accountRequest
if(!checkUserId(accountRequestDto.userId(),account.get()))
throw new HappyException(ErrorCode.DUPLICATED_USER_NAME);

return AccountDto.from(accountRepository.save(Account.of(accountId, accountRequestDto)));
return AccountDto.from(accountRepository.save(Account.of(accountId, accountRequestDto, account.get().getProfileImg())));
}

//수정될userId 중복체크
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public CalenderDto showCalender(Long accountId, String userId){
else calenderDto.setOwner(false);

//3. 메세지 목록 담기(일치하는 멤버가 아니거나 25일이 아니면 null로 두기)
LocalDateTime now = LocalDateTime.now();
if(calenderDto.isOwner()
// && now.getYear()==2024
// && LocalDateTime.now().getYear()==2024
){
List<Messages> messages = messageRepository.findByReceiver(viewer.get().getAccountId());
for(Messages msg : messages){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MessageDto createMessage(String userId, MessageRequestDto messageRequestD
messageRequestDto.isAnonymous()
);
messageRepository.save(messages);
return MessageDto.from(messages);
return MessageDto.from(messages,userId,messageRequestDto.getReceiver());
}

// 내가 받은 메세지들 가져오기 (Read)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import com.example.HappyNewHere.exception.HappyException;
import com.example.HappyNewHere.repository.AccountRepository;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.Transient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -30,7 +27,7 @@ public String getUserId(Authentication authentication){
public Long getLongId(Authentication authentication){
if (authentication==null) throw new HappyException(ErrorCode.USER_NOT_FOUND);
Long accountId = Long.parseLong(authentication.getName());
System.out.println(accountId);

return accountId;
}

Expand Down

0 comments on commit 3db00d4

Please sign in to comment.