-
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 #27 from Happy-New-Here/feature-#27
Feature #27
- Loading branch information
Showing
11 changed files
with
172 additions
and
42 deletions.
There are no files selected for viewing
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
15 changes: 12 additions & 3 deletions
15
src/main/java/com/example/HappyNewHere/controller/MessageController.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
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/HappyNewHere/dto/request/MessageRequestDto.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,29 @@ | ||
package com.example.HappyNewHere.dto.request; | ||
|
||
import com.example.HappyNewHere.domain.Messages; | ||
import java.time.LocalDateTime; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class MessageRequestDto { | ||
private String context; | ||
private String receiver; | ||
private int paperNum; | ||
private boolean anonymous; | ||
|
||
// entity -> dto | ||
public MessageRequestDto(Messages messages) { | ||
this.context = messages.getContext(); | ||
this.receiver = messages.getReceiver(); | ||
this.paperNum = messages.getPaperNum(); | ||
this.anonymous = messages.isAnonymous(); | ||
} | ||
|
||
public MessageRequestDto(String context, String receiver, | ||
int paperNum, boolean anonymous) { | ||
this.context = context; | ||
this.receiver = receiver; | ||
this.paperNum = paperNum; | ||
this.anonymous = anonymous; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/HappyNewHere/dto/response/MsgResponseDto.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,26 @@ | ||
package com.example.HappyNewHere.dto.response; | ||
|
||
import com.example.HappyNewHere.domain.Messages; | ||
import com.example.HappyNewHere.dto.MessageDto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record MsgResponseDto( | ||
String context, | ||
String senderId, | ||
String senderNickname, | ||
int paperNum, | ||
boolean anonymous, | ||
LocalDateTime day | ||
) { | ||
public static MsgResponseDto of(Messages messages, String senderNickname){ | ||
return new MsgResponseDto( | ||
messages.getContext(), | ||
messages.getSender(), | ||
senderNickname, | ||
messages.getPaperNum(), | ||
messages.isAnonymous(), | ||
messages.getCreatedDate() | ||
); | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/example/HappyNewHere/utils/AuthenticateUtils.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,37 @@ | ||
package com.example.HappyNewHere.utils; | ||
|
||
import com.example.HappyNewHere.domain.Account; | ||
import com.example.HappyNewHere.exception.ErrorCode; | ||
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 | ||
@RequiredArgsConstructor | ||
public class AuthenticateUtils { | ||
private final AccountRepository accountRepository; | ||
|
||
public String getUserId(Authentication authentication){ | ||
if (authentication==null) throw new HappyException(ErrorCode.USER_NOT_FOUND); | ||
Long accountId = Long.parseLong(authentication.getName()); | ||
Optional<Account> account = accountRepository.findById(accountId); | ||
if (account.isEmpty()) | ||
throw new HappyException(ErrorCode.USER_NOT_FOUND); | ||
|
||
return account.get().getUserId(); | ||
} | ||
|
||
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; | ||
} | ||
|
||
} |