Skip to content

Commit

Permalink
Merge pull request #48 from Team-UMC/feature/#20/university
Browse files Browse the repository at this point in the history
[FEAT] 대학교 api 구현
  • Loading branch information
ShimFFF authored Feb 9, 2024
2 parents cb36c5c + ff6818c commit 0be174a
Show file tree
Hide file tree
Showing 27 changed files with 1,115 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public interface BranchUniversityRepository extends JpaRepository<BranchUniversi

void deleteByBranch(Branch branch);
Optional<BranchUniversity> findByUniversityAndBranch_Semester(University university, Semester branch_semester);
Optional<BranchUniversity> findByUniversityAndIsActive(University university, boolean isActive);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

public interface BranchUniversityService {
Branch findBranchByUniversityAndSemester(University university, Semester LastSemester);

Branch findBranchByUniversity(University university);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public Branch findBranchByUniversityAndSemester(University university, Semester

}


@Override
public Branch findBranchByUniversity(University university) {
return branchUniversityRepository.findByUniversityAndIsActive(university, true)
.orElseThrow(() -> new RestApiException(BranchErrorCode.BRANCH_NOT_FOUND))
.getBranch();
}

//지부, 대학 연결하기
@Transactional
public BranchResponse.ConnectBranch connectBranchUniversity(UUID branchId, List<UUID> universityIds) {
Expand Down Expand Up @@ -78,3 +86,4 @@ public BranchResponse.ConnectBranch disconnectBranchUniversity(UUID branchId, Li
.universityIds(universityIds).build();
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.umc.networkingService.domain.mascot.entity;

import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
Expand Down Expand Up @@ -29,6 +30,10 @@ public class Mascot extends BaseEntity {
@Column(nullable = false)
private int endLevel;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private MascotType type;

private String dialogue;

private String image;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.umc.networkingService.domain.mascot.entity;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum MascotType {
UU("마스코트 종류 U"),
MM("마스코트 종류 M"),
CC("마스코트 종류 C");

private final String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.umc.networkingService.domain.mascot.repository;

import com.umc.networkingService.domain.mascot.entity.Mascot;
import com.umc.networkingService.domain.mascot.entity.MascotType;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import java.util.UUID;

public interface MascotRepository extends JpaRepository<Mascot, UUID> {
Optional<Mascot> findByStartLevelAndType(int startLevel, MascotType type);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.umc.networkingService.domain.mascot.service;

import com.umc.networkingService.domain.mascot.entity.Mascot;
import com.umc.networkingService.domain.mascot.entity.MascotType;

public interface MascotService {
Mascot getMascotByStartLevel(int level, MascotType type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.umc.networkingService.domain.mascot.service;

import com.umc.networkingService.domain.mascot.entity.Mascot;
import com.umc.networkingService.domain.mascot.entity.MascotType;
import com.umc.networkingService.domain.mascot.repository.MascotRepository;
import com.umc.networkingService.global.common.exception.ErrorCode;
import com.umc.networkingService.global.common.exception.RestApiException;
import com.umc.networkingService.global.common.exception.code.MascotErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@RequiredArgsConstructor
public class MascotServiceImpl implements MascotService{

private final MascotRepository mascotRepository;

@Override
public Mascot getMascotByStartLevel(int level, MascotType type) {
Optional<Mascot> optionalMascot = mascotRepository.findByStartLevelAndType(level, type);
return optionalMascot.orElseThrow(() -> new RestApiException(MascotErrorCode.EMPTY_MASCOT_LEVEL));
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public class Member extends BaseEntity {
// 가장 최근 호출 시간
private LocalDateTime lastActiveTime;


//포인트 차감
public void usePoint(Long usedPoint) {
this.remainPoint -= usedPoint;
this.contributionPoint += usedPoint;
}

// 기본 정보 설정 함수
public void setMemberInfo(String name, String nickname, University university, Branch branch) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.umc.networkingService.domain.member.service;

import com.umc.networkingService.domain.member.entity.MemberPoint;

public interface MemberPointService {
MemberPoint saveEntity(MemberPoint memberPoint);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.umc.networkingService.domain.member.service;

import com.umc.networkingService.domain.member.entity.MemberPoint;
import com.umc.networkingService.domain.member.repository.MemberPointRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class MemberPointServiceImpl implements MemberPointService{
private final MemberPointRepository memberPointRepository;

@Override
@Transactional
public MemberPoint saveEntity(MemberPoint memberPoint) {
return memberPointRepository.save(memberPoint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.umc.networkingService.domain.member.dto.request.MemberUpdateProfileRequest;
import com.umc.networkingService.domain.member.dto.response.*;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.PointType;
import com.umc.networkingService.domain.member.entity.PositionType;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.base.EntityLoader;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -23,4 +25,10 @@ public interface MemberService extends EntityLoader<Member, UUID> {
void updateMemberActiveTime(UUID memberId);
List<String> getPositionNamesByType(Member member, PositionType type);
Member saveEntity(Member member);

List<Member> findContributionRankings(Member member);

Member usePoint (Member member, PointType pointType);

Member findByMemberId (UUID memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import com.umc.networkingService.domain.member.dto.request.MemberUpdateMyProfileRequest;
import com.umc.networkingService.domain.member.dto.request.MemberUpdateProfileRequest;
import com.umc.networkingService.domain.member.dto.response.*;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.MemberPoint;
import com.umc.networkingService.domain.member.entity.MemberPosition;
import com.umc.networkingService.domain.member.entity.PositionType;
import com.umc.networkingService.domain.member.entity.*;
import com.umc.networkingService.domain.member.mapper.MemberMapper;
import com.umc.networkingService.domain.member.repository.MemberPointRepository;
import com.umc.networkingService.domain.member.repository.MemberRepository;
Expand Down Expand Up @@ -285,5 +282,25 @@ public Member loadEntity(UUID id) {
.orElseThrow(() -> new RestApiException(MemberErrorCode.EMPTY_MEMBER));
}

@Override
public List<Member> findContributionRankings(Member member) {
return memberRepository.findAllByUniversityOrderByContributionPointDesc(member.getUniversity());
}

@Override
public Member findByMemberId (UUID memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new RestApiException(MemberErrorCode.EMPTY_MEMBER));
}

@Override
@Transactional
public Member usePoint(Member member, PointType pointType) {
Member loginMember = loadEntity(member.getId());

loginMember.usePoint(pointType.getPoint());

return memberRepository.save(loginMember);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.umc.networkingService.domain.university.controller;

import com.umc.networkingService.global.common.base.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.umc.networkingService.config.security.auth.CurrentMember;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.PointType;
import com.umc.networkingService.domain.university.dto.request.UniversityRequest;
import com.umc.networkingService.domain.university.dto.response.UniversityResponse;
import com.umc.networkingService.domain.university.service.UniversityServiceImpl;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@Slf4j
@Tag(name = "운영진 대학교 API", description = "운영진용 대학교 관련 API")
@RestController
@Validated
@RequestMapping("/staff/universities")
@RequiredArgsConstructor
public class StaffUniversityController {

private final UniversityServiceImpl universityService;

@Operation(summary = "학교 생성하기 API",description = "학교 생성하기 API")
@PostMapping("")
public BaseResponse<UniversityResponse.UniversityId>
createUniversity(
@CurrentMember Member member,
@RequestBody @Valid UniversityRequest.universityInfo request
)
{
return BaseResponse.onSuccess(universityService.createUniversity(request));
}

@Operation(summary = "학교 삭제하기 API",description = "학교 삭제하기 API")
@DeleteMapping("/{universityId}")
public BaseResponse<UniversityResponse.UniversityId>
deleteUniversity(
@CurrentMember Member member,
@PathVariable @Valid UUID universityId
){
return BaseResponse.onSuccess(universityService.deleteUniversity(universityId));
}

@Operation(summary = "학교 정보 수정하기 API",description = "학교 정보 수정하기 API")
@PatchMapping("/{universityId}")
public BaseResponse<UniversityResponse.UniversityId>
patchUniversity(
@CurrentMember Member member,
@PathVariable @Valid UUID universityId,
@RequestBody @Valid UniversityRequest.universityInfo request
){
return BaseResponse.onSuccess(universityService.patchUniversity(request, universityId));
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.umc.networkingService.domain.university.controller;

import com.umc.networkingService.config.security.auth.CurrentMember;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.PointType;
import com.umc.networkingService.domain.university.dto.request.UniversityRequest;
import com.umc.networkingService.domain.university.dto.response.UniversityResponse;
import com.umc.networkingService.domain.university.service.UniversityServiceImpl;
import com.umc.networkingService.global.common.base.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@Slf4j
@Tag(name = "대학교 API", description = "일반 유저용 대학교 관련 API")
@RestController
@Validated
@RequestMapping("/universities")
@RequiredArgsConstructor
public class UniversityController {

private final UniversityServiceImpl universityService;

@Operation(summary = "전체 학교 조회 API",description = "전체 학교 조회 API")
@GetMapping("")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "성공")
})
public BaseResponse<UniversityResponse.JoinUniversities>
joinUniversityList(
@CurrentMember Member member //학교 많으면 추후에 페이징 처리하기
){
return BaseResponse.onSuccess(universityService.joinUniversityList());
}

@Operation(summary = "우리 학교 세부 정보 조회 API",description = "우리 학교 정보 조회 API")
@GetMapping("/details")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "성공")
})
public BaseResponse<UniversityResponse.joinUniversityDetail>
joinUniversityDetail(
@CurrentMember Member member
){
return BaseResponse.onSuccess(universityService.joinUniversityDetail(member));
}

@Operation(summary = "전체 학교 랭킹 조회 API",description = "전체 학교 랭킹 조회 API")
@GetMapping("/ranks")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "성공")
})
public BaseResponse<UniversityResponse.JoinUniversityRanks>
joinUniversityRanking(
){
return BaseResponse.onSuccess(universityService.joinUniversityRankingList());
}

@Operation(summary = "우리 학교 전체 기여도 랭킹 조회 API",description = "학교 전체 기여도 조회 API")
@GetMapping("/members")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "성공")
})
public BaseResponse<UniversityResponse.JoinContributionRanks>
joinUniversityContribution(
@CurrentMember Member member
){
return BaseResponse.onSuccess(universityService.joinContributionRankingList(member));
}

@Operation(summary = "우리 학교 마스코트 조회 API",description = "학교 마스코트 조회 API")
@GetMapping("/mascot")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "성공"),
@ApiResponse(responseCode = "BRANCH001", description = "지부가 존재하지 않음")
})
public BaseResponse<UniversityResponse.joinUniversityMascot>
joinUniversityMascot(
@CurrentMember Member member
){
return BaseResponse.onSuccess(universityService.joinUniversityMascot(member));
}

@Operation(summary = "우리 학교 마스코트 먹이주기 API",description = "학교 마스코트 먹이주기 API")
@PostMapping("/mascot")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "성공"),
@ApiResponse(responseCode = "MEMBER008", description = "마스코트에 줄 포인트가 충분하지 않음")
})
public BaseResponse<UniversityResponse.JoinUniversityMascotFeed>
postMascotPoint(
@CurrentMember Member member,
@RequestParam @Valid PointType pointType
){
return BaseResponse.onSuccess(universityService.feedUniversityMascot(member, pointType)); //현재 대학 포인트
}

}

Loading

0 comments on commit 0be174a

Please sign in to comment.