Skip to content

Commit

Permalink
[feat] add user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
minaamim committed Sep 5, 2023
1 parent 66d99ef commit e1ee603
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public AuthTokens generate(JwtUser jwtUser) {
String accessToken = Jwts.builder()
.setSubject(jwtUser.getId().toString())
.claim("nickname", jwtUser.getNickname())
.claim("profile", jwtUser.getProfile())
.claim("role", jwtUser.getRole())
.setExpiration(accessTokenExpiredAt)
.signWith(key, SignatureAlgorithm.HS512)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Post extends BaseEntity {
private UUID userId;

private String nickname;
private String profile;

@NotNull(message = "제목을 입력해주세요.")
private String title;
Expand Down Expand Up @@ -74,6 +75,7 @@ private Post(JwtUser user, CreatePostReq dto, List<PollItem> pollItems) {
private Post(JwtUser user, FromArchive dto, List<PollItem> pollItems) {
this.userId = user.getId();
this.nickname = user.getNickname();
this.profile = user.getProfile();
this.title = dto.getTitle();
this.content = dto.getContent();
this.publicStatus = dto.getPublicStatus();
Expand All @@ -100,7 +102,7 @@ public PostResponse newPostResponse() {
PollItemResponse response = pollItem.newPollItemResponse();
pollItemResponseList.add(response);
}
return new PostResponse(id, userId.toString(), nickname, title, content, publicStatus, isPublished, pollStatus, pollItemResponseList, getUpdatedAt());
return new PostResponse(id, userId.toString(), nickname, profile, title, content, publicStatus, isPublished, pollStatus, pollItemResponseList, getUpdatedAt());
}

public Long getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public User(String name, String gender, String email, String nickname, String pr
}

public JwtUser toJwtUser() {
return JwtUser.fromUser(id, nickname, role.getValue());
return JwtUser.fromUser(id, nickname, role.getValue(), profile);
}

public User(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ public class JwtUser implements Serializable {

private UUID id;
private String nickname;
private String profile;
private String role = "NON_MEMBER";

public static JwtUser newJwtUser(Claims claims) {
return builder()
.id(UUID.fromString(claims.getSubject()))
.nickname(String.valueOf(claims.get("nickname")))
.profile(String.valueOf(claims.get("profile")))
.role(String.valueOf(claims.get("role")))
.build();
}

public static JwtUser fromUser(UUID id, String nickname, String role) {
public static JwtUser fromUser(UUID id, String nickname, String role, String profile) {
return JwtUser.builder()
.id(id)
.nickname(nickname)
.profile(profile)
.role(role)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ class ArchiveControllerTest {
@Autowired
ArchiveController archiveController;

private static final String PROFILE = "src/main/resources/모자.png";

@Test
@Transactional
void likeArchive() {
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
ArchiveResponse creation = archiveController.fromWeb(user, "https://www.musinsa.com/app/goods/2028329").getBody().getResult();

assertThat(creation.isLiked()).isEqualTo(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class ArchiveServiceTest {
@Autowired
PostRepository postRepository;

private static final String PROFILE = "src/main/resources/모자.png";

@Test
@Transactional
void 웹에서_저장() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
String url = "https://www.musinsa.com/app/goods/2028329";

//when
Expand All @@ -60,7 +62,7 @@ class ArchiveServiceTest {
@Transactional
void 게시물에서_저장() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);

List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
Expand All @@ -81,7 +83,7 @@ class ArchiveServiceTest {
@Rollback(value = false)
void 좋아요() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
ArchiveResponse archive = archiveService.saveFromWeb(user, "https://www.musinsa.com/app/goods/2028329");

//when
Expand All @@ -98,7 +100,7 @@ class ArchiveServiceTest {
@Transactional
void 아카이브_리스트() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);

ArchiveResponse archiveResponse1 = archiveService.saveFromWeb(user, "https://www.musinsa.com/app/goods/2028329");
ArchiveResponse archiveResponse2 = archiveService.saveFromWeb(user, "https://zigzag.kr/catalog/products/113607837");
Expand Down Expand Up @@ -131,7 +133,7 @@ class ArchiveServiceTest {
@Transactional
void 아카이브_삭제() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
ArchiveResponse archiveResponse1 = archiveService.saveFromWeb(user, "https://www.musinsa.com/app/goods/2028329");
ArchiveResponse archiveResponse2 = archiveService.saveFromWeb(user, "https://zigzag.kr/catalog/products/113607837");
List<Long> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class PollServiceTest {
@Autowired
private PostService postService;
static final Long UNRECOMMENDED = 0L;

private static final String PROFILE = "src/main/resources/모자.png";
@BeforeEach
void set() {
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);

List<String> item = new ArrayList<>() {
{
Expand Down Expand Up @@ -74,7 +74,7 @@ void set() {
@Test
@Transactional
void 회원_중복_투표() {
JwtUser member = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser member = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);

Post post = postRepository.findByTitle("poll test");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class PostServiceTest {
private PostRepository postRepository;
@Autowired
private ArchiveService archiveService;
private static final String PROFILE = "src/main/resources/모자.png";

@Test
@Transactional
void_작성() {
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);

List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
Expand All @@ -61,7 +62,7 @@ class PostServiceTest {
@Test
@Transactional
void 메인화면() {
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);

List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
Expand All @@ -88,7 +89,7 @@ class PostServiceTest {
void get_temporaries() {

//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand All @@ -109,7 +110,7 @@ void get_temporaries() {
void update_post() {

//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand All @@ -135,7 +136,7 @@ void update_post() {
@Transactional
public void delete() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand All @@ -155,7 +156,7 @@ public void delete() {
@Transactional
public void 아카이브에서_글작성() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
ArchiveResponse archiveResponse1 = archiveService.saveFromWeb(user, "https://www.musinsa.com/app/goods/2028329");
ArchiveResponse archiveResponse2 = archiveService.saveFromWeb(user, "https://zigzag.kr/catalog/products/113607837");
FromArchive dto = new FromArchive("아카이브 글 작성 테스트", "테스트", PublicStatus.PUBLIC, true);
Expand All @@ -172,7 +173,7 @@ public void delete() {
@Transactional
public void 투표_종료() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand All @@ -191,7 +192,7 @@ public void delete() {
@Transactional
public void__목록() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand Down Expand Up @@ -222,7 +223,7 @@ public void delete() {
@Test
@Transactional
public void 임시저장_개수_초과() {
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand All @@ -246,7 +247,7 @@ public void delete() {
@Transactional
public void 임시저장_출간() {
//given
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina");
JwtUser user = JwtUser.fromUser(UUID.randomUUID(), "mina", "mina", PROFILE);
List<String> urls = new ArrayList<>();
urls.add("https://zigzag.kr/catalog/products/113607837");
urls.add("https://www.musinsa.com/app/goods/3404788?loc=goods_rank");
Expand Down

0 comments on commit e1ee603

Please sign in to comment.