Skip to content

Commit

Permalink
Merge pull request #129 from TeamPINGLE/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
tkdwns414 authored Mar 15, 2024
2 parents eb5632d + 30e3e75 commit 741f5a0
Show file tree
Hide file tree
Showing 31 changed files with 449 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import org.pingle.pingleserver.controller.swagger.MeetingApi;
import org.pingle.pingleserver.domain.Meeting;
import org.pingle.pingleserver.domain.Pin;
import org.pingle.pingleserver.domain.enums.MCategory;
import org.pingle.pingleserver.domain.enums.SearchOrder;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.request.MeetingRequest;
import org.pingle.pingleserver.dto.response.ParticipantsResponse;
import org.pingle.pingleserver.dto.response.SearchResponse;
import org.pingle.pingleserver.dto.type.SuccessMessage;
import org.pingle.pingleserver.service.MeetingService;
import org.pingle.pingleserver.service.PinService;
Expand Down Expand Up @@ -60,4 +63,14 @@ public ApiResponse<?> deleteMeeting(@UserId Long userId, @PathVariable("meetingI
meetingService.deleteMeeting(userId, meetingId);
return ApiResponse.success(SuccessMessage.OK);
}

@GetMapping("/search")
public ApiResponse<SearchResponse> getSearchResult(@UserId Long userId,
@RequestParam(required = false) String q,
@RequestParam(required = false) MCategory category,
@RequestParam Long teamId,
@RequestParam SearchOrder order) {
return ApiResponse.success(SuccessMessage.OK, meetingService.searchMeetings(userId , q, category, teamId, order));
}
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.pingle.pingleserver.controller;

import jakarta.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import org.pingle.pingleserver.annotation.UserId;
import org.pingle.pingleserver.controller.swagger.PinApi;
import org.pingle.pingleserver.domain.enums.MCategory;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.reponse.MeetingResponse;
import org.pingle.pingleserver.dto.reponse.PinResponse;
import org.pingle.pingleserver.dto.response.RankingResponse;
import org.pingle.pingleserver.dto.type.SuccessMessage;
import org.pingle.pingleserver.service.PinService;
import org.springframework.web.bind.annotation.*;
Expand All @@ -22,16 +22,23 @@ public class PinController implements PinApi {
private final PinService pinService;

@GetMapping
public ApiResponse<List<PinResponse>> getPins (@PathVariable("teamId") Long teamId,
@Nullable @RequestParam("category")MCategory category) {
return ApiResponse.success(SuccessMessage.OK, pinService.getPins(teamId, category));
public ApiResponse<List<PinResponse>> getPins (@PathVariable Long teamId,
@RequestParam(required = false)MCategory category,
@RequestParam(required = false)String q) {
return ApiResponse.success(SuccessMessage.OK, pinService.getPins(teamId, category, q));
}

@GetMapping("/{pinId}/meetings")
public ApiResponse<List<MeetingResponse>> getMeetings(@UserId Long userId,
@PathVariable String teamId,
@PathVariable Long pinId,
@Nullable @RequestParam MCategory category) {
@RequestParam(required = false) MCategory category) {
return ApiResponse.success(SuccessMessage.OK, pinService.getMeetings(pinId, userId, category));
}

@GetMapping("/ranking")
public ApiResponse<RankingResponse> getRankings(@PathVariable Long teamId) {
return ApiResponse.success(SuccessMessage.OK, pinService.getRankings(teamId));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import org.pingle.pingleserver.annotation.UserId;
import org.pingle.pingleserver.controller.swagger.TeamApi;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.reponse.KeywordResponse;
import org.pingle.pingleserver.dto.reponse.TeamCreationResponse;
import org.pingle.pingleserver.dto.reponse.TeamNameDuplicatedResponse;
import org.pingle.pingleserver.dto.request.TeamCreationRequest;
import org.pingle.pingleserver.dto.request.TeamRegisterRequest;
import org.pingle.pingleserver.dto.response.SelectedTeamResponse;
import org.pingle.pingleserver.dto.response.TeamRegisterResponse;
Expand Down Expand Up @@ -40,4 +44,20 @@ public ApiResponse<TeamRegisterResponse> registerTeam(
@Valid @RequestBody TeamRegisterRequest request){
return ApiResponse.success(SuccessMessage.OK, teamService.registerTeam(userId, teamId, request));
}

@GetMapping("/check-name")
public ApiResponse<TeamNameDuplicatedResponse> checkTeamName(@NotBlank @RequestParam String name){
return ApiResponse.success(SuccessMessage.OK, teamService.checkTeamName(name));
}

@PostMapping
public ApiResponse<TeamCreationResponse> createTeam(@UserId Long userId, @Valid @RequestBody TeamCreationRequest request){
return ApiResponse.success(SuccessMessage.OK, teamService.createTeam(userId, request));
}

@GetMapping("/keywords")
public ApiResponse<List<KeywordResponse>> getKeywords(){
return ApiResponse.success(SuccessMessage.OK, teamService.getKeywords());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.pingle.pingleserver.controller;

import lombok.RequiredArgsConstructor;
import org.pingle.pingleserver.domain.enums.URole;
import org.pingle.pingleserver.repository.UserRepository;
import org.pingle.pingleserver.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Profile({"local", "dev"})
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {
private final JwtUtil jwtUtil;
private final UserRepository userRepository;

@Value("${token-test.key}")
private String key;

@GetMapping("/token/{userId}")
public ResponseEntity<?> getToken(@PathVariable("userId") Long userId,
@RequestHeader(value = "Test-Key", required = false) String testKey){
if (!key.isBlank() && !key.equals(testKey)) {
return ResponseEntity.badRequest().body("Invalid test key");
}
userRepository.findByIdOrThrow(userId);
return ResponseEntity.ok(jwtUtil.generateTokens(userId, URole.USER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import org.pingle.pingleserver.controller.swagger.UserApi;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.response.MyPingleResponse;
import org.pingle.pingleserver.dto.response.MyTeamResponse;
import org.pingle.pingleserver.dto.response.UserInfoResponse;
import org.pingle.pingleserver.dto.type.SuccessMessage;
import org.pingle.pingleserver.service.MeetingService;
import org.pingle.pingleserver.service.TeamService;
import org.pingle.pingleserver.service.UserService;
import org.springframework.web.bind.annotation.*;

Expand All @@ -24,6 +26,7 @@ public class UserController implements UserApi {

private final MeetingService meetingService;
private final UserService userService;
private final TeamService teamService;

@GetMapping("/me")
public ApiResponse<UserInfoResponse> getLoginUserInfo(@UserId Long userId){
Expand All @@ -41,4 +44,9 @@ public ApiResponse<Void> leave(@UserId Long userId, @Nullable @RequestHeader(Con
userService.leave(userId, code);
return ApiResponse.success(SuccessMessage.OK);
}

@GetMapping("/me/teams")
public ApiResponse<List<MyTeamResponse>> getMyTeams(@UserId Long userId) {
return ApiResponse.success(SuccessMessage.OK, teamService.getMyTeams(userId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public interface PinApi {

@Operation(summary = "핀 목록 조회", description = "핀 목록을 조회한다.")
ApiResponse<List<PinResponse>> getPins(Long teamId, MCategory category);
ApiResponse<List<PinResponse>> getPins(Long teamId, MCategory category, String q);

@Operation(summary = "핀에 속한 미팅 목록 조회", description = "핀에 속한 미팅 목록을 조회한다.")
ApiResponse<List<MeetingResponse>> getMeetings(@UserId Long userId,
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/pingle/pingleserver/domain/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.pingle.pingleserver.domain.enums.TKeyword;

import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -21,6 +24,19 @@ public class Team extends BaseTimeEntity {

private String code;

private String email;

@Enumerated(EnumType.STRING)
private TKeyword keyword;

@OneToMany(mappedBy = "team")
private List<UserTeam> userTeams;

@Builder
public Team(String name, String email, String code, TKeyword keyword) {
this.name = name;
this.email = email;
this.code = code;
this.keyword = keyword;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.pingle.pingleserver.domain.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum SearchOrder {
NEW("new"), UPCOMING("upcoming");
private final String value;
}
17 changes: 10 additions & 7 deletions src/main/java/org/pingle/pingleserver/domain/enums/TKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum TKeyword {
CIRCLE("연합 동아리"),
CIRCLE("연합동아리"),
SCHOOL_CLUB("교내동아리"),
STUDENT_COUNCIL("학생회"),
UNIVERSITY("대학교"),
SCHOOL_CLUB("교내 동아리");
HIGH_SCHOOL("고등학교"),
MIDDLE_SCHOOL("중학교"),
LECTURE("강의"),
STUDY_GROUP("스터디"),
PRIVATE_MEETING("사모임"),
CLUB("동호회"),
ETC("기타");

private final String value;

@Override
public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.pingle.pingleserver.dto.reponse;

import lombok.Builder;
import org.pingle.pingleserver.domain.enums.TKeyword;

@Builder
public record KeywordResponse (String name, String value){

public static KeywordResponse of(TKeyword keyword){
return KeywordResponse.builder()
.name(keyword.toString())
.value(keyword.getValue())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
package org.pingle.pingleserver.dto.reponse;

import org.pingle.pingleserver.domain.Meeting;
import org.pingle.pingleserver.domain.Pin;
import org.pingle.pingleserver.domain.enums.MCategory;

import java.util.Comparator;
import java.util.List;

public record PinResponse(Long id, Double x, Double y, MCategory category, int meetingCount) {
public static PinResponse of(Pin pin, MCategory category, int count) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
category, count);
}
public static PinResponse ofWithNoFilter(Pin pin) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
getMostRecentMeetingCategoryOfPin(pin), getMeetingCount(pin));
}
public static PinResponse ofWithFilter(Pin pin, MCategory mCategory) {
return new PinResponse(pin.getId(),pin.getPoint().getX(), pin.getPoint().getY(),
mCategory, getMeetingCountWithFilter(pin, mCategory));

}
private static MCategory getMostRecentMeetingCategoryOfPin (Pin pin) {
Comparator<Meeting> comparator = Comparator.comparing(Meeting::getStartAt);
List<Meeting> meetingList = pin.getMeetingList();
meetingList.sort(comparator);
return meetingList.get(0).getCategory();
}

private static int getMeetingCount(Pin pin) {
return pin.getMeetingList().size();
}
private static int getMeetingCountWithFilter(Pin pin, MCategory category) {
int count = 0;
List<Meeting> meetings = pin.getMeetingList();
for(Meeting meeting : meetings) {
if(meeting.getCategory().getValue().equals(category.getValue()))
count++;
}

return count;
}

public record PinResponse(Long id, Double x, Double y, MCategory category) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.pingle.pingleserver.dto.reponse;

import org.pingle.pingleserver.domain.Team;
import org.pingle.pingleserver.domain.enums.TKeyword;

public record TeamCreationResponse (
Long id,
String name,
String email,
String code,
TKeyword keyword
) {
public static TeamCreationResponse of(Team team) {
return new TeamCreationResponse(team.getId(), team.getName(), team.getEmail(), team.getCode(), team.getKeyword());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.pingle.pingleserver.dto.reponse;

public record TeamNameDuplicatedResponse (boolean result){
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.pingle.pingleserver.dto.request;

import org.pingle.pingleserver.domain.enums.TKeyword;

public record TeamCreationRequest (
String name,
String email,
TKeyword keyword
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.pingle.pingleserver.dto.response;

import org.pingle.pingleserver.domain.Team;

public record MyTeamResponse (
Long id, String keyword, String name, Long meetingCount, Long participantCount, boolean isOwner, String code) {
public static MyTeamResponse of(Team team, Long meetingCount, Long participantCount, boolean isOwner) {
return new MyTeamResponse(
team.getId(),
team.getKeyword().getValue(),
team.getName(),
meetingCount,
participantCount,
isOwner,
team.getCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.pingle.pingleserver.dto.response;

import java.time.LocalDateTime;

public record RankingIndividualResponse (String name, LocalDateTime latestVisitedDate, Long locationCount) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.pingle.pingleserver.dto.response;

import java.util.List;

public record RankingResponse (int meetingCount, List<RankingIndividualResponse> locations) {
public static RankingResponse of (List<RankingIndividualResponse> responses) {
return new RankingResponse(getSumOfMeetings(responses), responses);
}

private static int getSumOfMeetings (List<RankingIndividualResponse> responses) {
int sum = 0;
for (RankingIndividualResponse response : responses) {
sum += response.locationCount();
}
return sum;
}
}
Loading

0 comments on commit 741f5a0

Please sign in to comment.