Skip to content

Commit

Permalink
Merge pull request #98 from Team-UMC/feature/#94/album-api-refactoring
Browse files Browse the repository at this point in the history
[FEAT] Album ๊ด€๋ จ ๋ฆฌํŽ™ํ† ๋ง ๋ฐ ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ ๋กœ์ง ๊ตฌํ˜„
  • Loading branch information
junseokkim authored Mar 24, 2024
2 parents 6f7d74d + 8d2d4c7 commit 56717c9
Show file tree
Hide file tree
Showing 67 changed files with 698 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class SwaggerConfig {

@Value("${server.url}")
private String serverUrl;
@Bean
public OpenAPI openAPI() {

Expand All @@ -28,7 +32,7 @@ public OpenAPI openAPI() {
.scheme("Bearer"));

Server server = new Server();
server.setUrl("https://umcservice.shop");
server.setUrl(serverUrl);

return new OpenAPI()
.addSecurityItem(securityRequirement)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.umc.networkingService.config.initial;

import com.umc.networkingService.global.common.enums.Semester;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

@Getter
@RequiredArgsConstructor
public enum AlbumInfo {

// 4๊ธฐ
FOURTH_INHA_MT("222222", Semester.FOURTH, "์ธํ•˜๋Œ€ํ•™๊ต 4๊ธฐ MT", "OB์™€ YB๊ฐ€ ํ•จ๊ป˜ํ•˜๋Š” ์ธํ•˜๋Œ€ํ•™๊ต 4๊ธฐ MT๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ๋ฌด๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค.",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/MT.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/MT+(2).jpg")),
FOURTH_DEMO_DAY("222222", Semester.FOURTH, "UMC 4๊ธฐ ๋ฐ๋ชจ๋ฐ์ด ํ–‰์‚ฌ", "UMC 4๊ธฐ ๋ฐ๋ชจ๋ฐ์ด ํ–‰์‚ฌ 3์ผ๊ฐ„ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ๋ฌด๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค.",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/%EB%8D%B0%EB%AA%A8%EB%8D%B0%EC%9D%B41.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/%EB%8D%B0%EB%AA%A8%EB%8D%B0%EC%9D%B42.jpg")),

// 5๊ธฐ
FIFTH_OT("333333", Semester.FIFTH, "UMC 5๊ธฐ OT", "UMC 5๊ธฐ ์—ฐํ•ฉ ๋ฐ ๊ต๋‚ด OT๋ฅผ ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/OT1.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/OT2.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/OT3.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/OT4.jpg")),
FIFTH_NETWORKING("333333", Semester.FIFTH, "UMC 5๊ธฐ GACI ์ง€๋ถ€ ๋„คํŠธ์›Œํ‚น ๋ฐ์ด", "UMC 5๊ธฐ GACI ์ง€๋ถ€ ๋„คํŠธ์›Œํ‚น ๋ฐ์ด ํ–‰์‚ฌ๋ฅผ ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/NETWORKING1.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/NETWORKING2.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/NETWORKING3.jpg")),
FIFTH_INHA_MT("333333", Semester.FIFTH, "์ธํ•˜๋Œ€ํ•™๊ต 5๊ธฐ MT", "OB์™€ YB๊ฐ€ ํ•จ๊ป˜ํ•˜๋Š” ์ธํ•˜๋Œ€ํ•™๊ต 5๊ธฐ MT๋ฅผ ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/MT1.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/MT2.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/MT3.jpg")),
FIFTH_GRDUATION("333333", Semester.FIFTH, "์ธํ•˜๋Œ€ํ•™๊ต UMC ์กธ์—…์‹ ํ–‰์‚ฌ", "์ธํ•˜๋Œ€ํ•™๊ต UMC ์ฑŒ๋ฆฐ์ € ์กธ์—…์ž๋ฅผ ์ถ•ํ•˜ํ•˜๋Š” ํ–‰์‚ฌ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/G1.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/G2.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/G3.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/G4.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/G5.jpg")),
FIFTH_DEMO_DAY("333333", Semester.FIFTH, "UMC 5๊ธฐ ๋ฐ๋ชจ๋ฐ์ด ํ–‰์‚ฌ", "UMC 5๊ธฐ ๋ฐ๋ชจ๋ฐ์ด ํ–‰์‚ฌ๋ฅผ 3์ผ๊ฐ„ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ๋ฌด๋ฆฌํ–ˆ๊ณ , UMC ๋„คํŠธ์›Œํ‚น ๋ฐ์ด ์„œ๋น„์Šค ํŒ€์ด 1๋“ฑํ–ˆ์Šต๋‹ˆ๋‹ค!!~~",
List.of("https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/DEMO.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/DEMO1.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/DEMO2.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/DEMO3.jpg",
"https://umc-service-bucket.s3.ap-northeast-2.amazonaws.com/album/inha/DEMO4.jpg")),

;

private final String clientId;
private final Semester semester;
private final String title;
private final String content;
private final List<String> images;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package com.umc.networkingService.config.initial;

import com.umc.networkingService.domain.album.entity.Album;
import com.umc.networkingService.domain.album.entity.AlbumImage;
import com.umc.networkingService.domain.album.repository.AlbumImageRepository;
import com.umc.networkingService.domain.album.repository.AlbumRepository;
import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.branch.entity.BranchUniversity;
import com.umc.networkingService.domain.branch.repository.BranchRepository;
import com.umc.networkingService.domain.branch.repository.BranchUniversityRepository;
import com.umc.networkingService.domain.mascot.entity.Mascot;
import com.umc.networkingService.domain.mascot.repository.MascotRepository;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.MemberPosition;
import com.umc.networkingService.domain.member.entity.PositionType;
import com.umc.networkingService.domain.member.entity.SocialType;
import com.umc.networkingService.domain.member.repository.MemberPositionRepository;
import com.umc.networkingService.domain.member.repository.MemberRepository;
import com.umc.networkingService.domain.project.entity.Project;
import com.umc.networkingService.domain.project.entity.ProjectMember;
import com.umc.networkingService.domain.project.repository.ProjectMemberRepository;
Expand All @@ -14,6 +24,7 @@
import com.umc.networkingService.domain.university.repository.UniversityRepository;
import com.umc.networkingService.global.common.enums.Semester;
import com.umc.networkingService.global.common.exception.RestApiException;
import com.umc.networkingService.global.common.exception.code.MemberErrorCode;
import com.umc.networkingService.global.common.exception.code.ProjectErrorCode;
import com.umc.networkingService.global.common.exception.code.UniversityErrorCode;
import lombok.RequiredArgsConstructor;
Expand All @@ -33,14 +44,22 @@ public class DataLoader implements ApplicationListener<ContextRefreshedEvent> {
private final UniversityRepository universityRepository;
private final BranchRepository branchRepository;
private final BranchUniversityRepository branchUniversityRepository;

private final ProjectRepository projectRepository;
private final ProjectMemberRepository projectMemberRepository;

private final MemberRepository memberRepository;
private final MemberPositionRepository memberPositionRepository;
private final AlbumRepository albumRepository;
private final AlbumImageRepository albumImageRepository;

private List<MascotInfo> mascots = Arrays.stream(MascotInfo.values()).toList();
private List<UniversityInfo> universities = Arrays.stream(UniversityInfo.values()).toList();
private List<BranchInfo> branches = Arrays.stream(BranchInfo.values()).toList();
private List<ProjectInfo> projects = Arrays.stream(ProjectInfo.values()).toList();
private List<ProjectMemberInfo> projectMembers = Arrays.stream(ProjectMemberInfo.values()).toList();
private List<MemberInfo> albumMembers = Arrays.stream(MemberInfo.values()).toList();
private List<AlbumInfo> albums = Arrays.stream(AlbumInfo.values()).toList();

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
Expand All @@ -60,6 +79,12 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
// ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
List<Project> newProjects = insertNewProjects();
if (!newProjects.isEmpty()) insertProjectMembers(newProjects);

// ์•จ๋ฒ” ์ž‘์„ฑ์ž ์ƒ์„ฑ
insertAlbumWriters();

// ์•จ๋ฒ” ๋ฐ์ดํ„ฐ ์ƒ์„ฑ
insertNewAlbums();
}

// ์ƒˆ๋กœ์šด ๋งˆ์Šค์ฝ”ํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
Expand Down Expand Up @@ -180,6 +205,71 @@ private Project findProject(List<Project> newProjects, String projectName) {
.orElseThrow(() -> new RestApiException(ProjectErrorCode.EMPTY_PROJECT));
}

// ์•จ๋ฒ” ์ž‘์„ฑ์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
private void insertAlbumWriters() {
albumMembers.stream()
.filter(albumMember -> !memberRepository.existsByClientIdAndSocialType(
albumMember.getClientId(), albumMember.getType()))
.forEach(this::saveAlbumMember);
}

private void saveAlbumMember(MemberInfo albumMember) {
Member member = Member.builder()
.clientId(albumMember.getClientId())
.socialType(albumMember.getType())
.university(universityRepository.findByName(albumMember.getUniversity())
.orElseThrow(() -> new RestApiException(UniversityErrorCode.EMPTY_UNIVERSITY)))
.nickname(albumMember.getNickname())
.name(albumMember.getName())
.role(albumMember.getRole())
.build();

insertMemberPosition(memberRepository.save(member), albumMember.getPosition());
}

// ์•จ๋ฒ” ์ž‘์„ฑ์ž ์ง์ฑ…์„ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
private void insertMemberPosition(Member member, String position) {
MemberPosition memberPosition = MemberPosition.builder()
.member(member)
.name(position)
.type(PositionType.CAMPUS)
.build();

memberPositionRepository.save(memberPosition);
}

// ์ƒˆ๋กœ์šด ์•จ๋ฒ”์„ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
private void insertNewAlbums() {
albums.stream()
.filter(album -> !albumRepository.existsByTitle(album.getTitle()))
.forEach(this::saveAlbum);
}

// ์ƒˆ๋กœ์šด ์•จ๋ฒ”์„ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
private void saveAlbum(AlbumInfo albumInfo) {
Album album = Album.builder()
.writer(memberRepository.findByClientIdAndSocialType(
albumInfo.getClientId(), SocialType.KAKAO)
.orElseThrow(() -> new RestApiException(MemberErrorCode.EMPTY_MEMBER)))
.semester(albumInfo.getSemester())
.title(albumInfo.getTitle())
.content(albumInfo.getContent())
.build();

insertAlbumImages(
albumRepository.save(album),
albumInfo.getImages()
);
}

// ์•จ๋ฒ” ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
private void insertAlbumImages(Album album, List<String> images) {
images.stream()
.map(image -> AlbumImage.builder()
.album(album).url(image).build())
.forEach(albumImageRepository::save);
}

@Override
public boolean supportsAsyncExecution() {
return ApplicationListener.super.supportsAsyncExecution();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.umc.networkingService.config.initial;

import com.umc.networkingService.domain.member.entity.SocialType;
import com.umc.networkingService.global.common.enums.Part;
import com.umc.networkingService.global.common.enums.Role;
import com.umc.networkingService.global.common.enums.Semester;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum MemberInfo {

// 4๊ธฐ ํšŒ์žฅ
BORA("222222", "์ธํ•˜๋Œ€ํ•™๊ต", "๋ณด๋ผ", "์œ ์ง€์ˆ˜", SocialType.KAKAO, Role.CAMPUS_STAFF, "ํšŒ์žฅ", Semester.FOURTH, Part.SPRING),

// 5๊ธฐ ํšŒ์žฅ
BEX("333333", "์ธํ•˜๋Œ€ํ•™๊ต", "๋ฒก์Šค", "๊น€์ค€์„", SocialType.KAKAO, Role.CAMPUS_STAFF, "ํšŒ์žฅ", Semester.FIFTH, Part.SPRING),
;

private final String clientId;
private final String university;
private final String nickname;
private final String name;
private final SocialType type;
private final Role role;
private final String position;
private final Semester semester;
private final Part part;


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.umc.networkingService.config.security.auth.CurrentMember;
import com.umc.networkingService.domain.album.dto.request.AlbumCommentCreateRequest;
import com.umc.networkingService.domain.album.dto.request.AlbumCommentUpdateRequest;
import com.umc.networkingService.domain.album.dto.response.AlbumCommentIdResponse;
import com.umc.networkingService.domain.album.dto.response.AlbumCommentResponse;
import com.umc.networkingService.domain.album.service.AlbumCommentService;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.base.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -30,10 +32,15 @@ public class AlbumCommentController {
@ApiResponse(responseCode = "COMMON200", description = "์„ฑ๊ณต"),
@ApiResponse(responseCode = "ALBUM001", description = "์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ์ง„์ฒฉ์ž…๋‹ˆ๋‹ค.")
})
@Parameters(value = {
@Parameter(name = "commentId", description = "๋Œ€๋Œ“๊ธ€์ผ ๊ฒฝ์šฐ ์ƒ์œ„ ๋Œ“๊ธ€ id๊ฐ’์ž…๋‹ˆ๋‹ค.(๋Œ€๋Œ“๊ธ€์ด ์•„๋‹ ๊ฒฝ์šฐ, ๋ฏธํฌํ•จ)"),
})
@PostMapping
public BaseResponse<AlbumCommentIdResponse> createAlbumComment(@CurrentMember Member member,
@Valid @RequestBody AlbumCommentCreateRequest request) {
return BaseResponse.onSuccess(albumCommentService.createAlbumComment(member, request));
public BaseResponse<AlbumCommentResponse> createAlbumComment(
@CurrentMember Member member,
@RequestParam(required = false) UUID commentId,
@Valid @RequestBody AlbumCommentCreateRequest request) {
return BaseResponse.onSuccess(albumCommentService.createAlbumComment(member, commentId, request));
}

@Operation(summary = "๋Œ“๊ธ€ ์ˆ˜์ • API", description = "๋Œ“๊ธ€์„ ์ˆ˜์ •ํ•˜๋Š” API์ž…๋‹ˆ๋‹ค.")
Expand All @@ -43,9 +50,10 @@ public BaseResponse<AlbumCommentIdResponse> createAlbumComment(@CurrentMember Me
@ApiResponse(responseCode = "COMMENT002", description = "๋Œ“๊ธ€ ์ˆ˜์ • ๊ถŒํ•œ์ด ์—†์„ ๊ฒฝ์šฐ ๋ฐœ์ƒ")
})
@PatchMapping("/{commentId}")
public BaseResponse<AlbumCommentIdResponse> updateAlbumComment(@CurrentMember Member member,
@PathVariable(value = "commentId") UUID commentId,
@Valid @RequestBody AlbumCommentUpdateRequest request) {
public BaseResponse<AlbumCommentResponse> updateAlbumComment(
@CurrentMember Member member,
@PathVariable(value = "commentId") UUID commentId,
@Valid @RequestBody AlbumCommentUpdateRequest request) {
return BaseResponse.onSuccess(albumCommentService.updateAlbumComment(member, commentId, request));
}

Expand All @@ -56,8 +64,8 @@ public BaseResponse<AlbumCommentIdResponse> updateAlbumComment(@CurrentMember Me
@ApiResponse(responseCode = "COMMENT002", description = "๋Œ“๊ธ€ ์ˆ˜์ • ๊ถŒํ•œ์ด ์—†์„ ๊ฒฝ์šฐ ๋ฐœ์ƒ")
})
@DeleteMapping("/{commentId}")
public BaseResponse<AlbumCommentIdResponse> deleteAlbumComment(@CurrentMember Member member,
@PathVariable(value = "commentId") UUID commentId) {
public BaseResponse<AlbumCommentResponse> deleteAlbumComment(@CurrentMember Member member,
@PathVariable(value = "commentId") UUID commentId) {
return BaseResponse.onSuccess(albumCommentService.deleteAlbumComment(member, commentId));
}
}
Loading

0 comments on commit 56717c9

Please sign in to comment.