Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OING-62] feat: 가족 구성원 Profile 조회 API 설계 #29

Merged
merged 9 commits into from
Dec 9, 2023
36 changes: 28 additions & 8 deletions member/src/main/java/com/oing/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package com.oing.controller;

import com.oing.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.oing.dto.response.FamilyMemberProfileResponse;
import com.oing.dto.response.PaginationResponse;
import com.oing.restapi.MemberApi;
import org.springframework.stereotype.Controller;

@RestController
@RequiredArgsConstructor
public class MemberController {
import java.util.ArrayList;
import java.util.List;

private final MemberService memberService;
@Controller
public class MemberController implements MemberApi {

@Override
public PaginationResponse<FamilyMemberProfileResponse> getFamilyMemberProfile(Integer page, Integer size) {
String memberIdBase = "01HGW2N7EHJVJ4CJ999RRS2E";
String memberNameBase = "디프만";

List<FamilyMemberProfileResponse> mockResponses = new ArrayList<>();
for(int i = 0; i < size; i++) {
int currentIndex = i + ((page - 1) * size);
String suffix = String.format("%02d", currentIndex);
mockResponses.add(
new FamilyMemberProfileResponse(
memberIdBase + suffix,
memberNameBase + suffix,
"https://picsum.photos/200/300?random=" + currentIndex
)
);
}

return new PaginationResponse<>(page, 3, size, mockResponses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.oing.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "가족 구성원 프로필 응답")
public record FamilyMemberProfileResponse(
@Schema(description = "구성원 ID", example = "1")
String memberId,

@Schema(description = "구성원 이름", example = "디프만")
String name,

@Schema(description = "구성원 프로필 이미지 주소", example = "https://asset.no5ing.kr/post/01HGW2N7EHJVJ4CJ999RRS2E97")
String imageUrl
) {
}
36 changes: 24 additions & 12 deletions member/src/main/java/com/oing/restapi/MemberApi.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
package com.oing.restapi;

import com.oing.dto.response.MemberResponse;
import com.oing.dto.response.FamilyMemberProfileResponse;
import com.oing.dto.response.PaginationResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.web.bind.annotation.*;
import com.oing.dto.response.MemberResponse;

/**
* no5ing-server
* User: CChuYong
* Date: 12/7/23
* Time: 6:01 PM
*/
@Tag(name = "멤버 API", description = "멤버(사용자) 관련 API")
@Tag(name = "회원 API", description = "회원 관련 API")
@RestController
@Valid
@RequestMapping("/v1/members")
public interface MemberApi {
@Operation(summary = "가족 구성원 프로필 조회", description = "가족 구성원 프로필을 조회합니다.")
@GetMapping(value = "/profile", params = {"type=FAMILY"})
PaginationResponse<FamilyMemberProfileResponse> getFamilyMemberProfile(
@RequestParam(required = false, defaultValue = "1")
@Parameter(description = "가져올 현재 페이지", example = "1")
@Min(value = 1)
Integer page,

@RequestParam(required = false, defaultValue = "10")
@Parameter(description = "가져올 페이지당 크기", example = "10")
@Min(value = 1)
Integer size
);

@GetMapping("/{memberId}")
MemberResponse getMember(@PathVariable String memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.oing.dto.response;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class FamilyMemberProfileResponseTest {
@DisplayName("FamilyMemberProfileResponse 생성 테스트")
@Test
void testFamilyMemberProfileResponse() {
// given
String memberId = "1";
String name = "디프만";
String imageUrl = "https://asset.no5ing.kr/post/01HGW2N7EHJVJ4CJ999RRS2E97";

// when
FamilyMemberProfileResponse response = new FamilyMemberProfileResponse(memberId, name, imageUrl);

// then
assertEquals(response.memberId(), memberId);
assertEquals(response.name(), name);
assertEquals(response.imageUrl(), imageUrl);
}

}
Loading