Skip to content

Commit

Permalink
Merge pull request #29 from jjuuuunnii/main
Browse files Browse the repository at this point in the history
Fix: 아카이브 api 수정
  • Loading branch information
jjuuuunnii authored Jan 12, 2024
2 parents ef91446 + bdcac47 commit 27a4e85
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/snowthon/snowman/contrant/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Constants {
public static String AUTHORIZATION_HEADER = "Authorization";
public static String USER_ROLE = "ROLE_USER";
public static final String REGION_TYPE = "H";
public static final String USER_NICKNAME_PREFIX = "pengdolli_";


public static List<String> NO_NEED_AUTH_URLS = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ public class UserController {
* @return
*/
//4-1. 모아 보기
@GetMapping("/vote-history")
@Operation(summary = "아카이빙 모아보기", description = "유저의 투표 기록들을 가져옵니다")
public ResponseDto<?> archiving() {
Long userId = 1L;
return ResponseDto.ok(userService.getVoteHistoriesByUser(userId));
@GetMapping("/vote-history/{weatherId}")
@Operation(summary = "아카이빙 모아보기", description = "그 지역 모든 유저들의 투표 기록들을 가져옵니다")
public ResponseDto<?> archiving(@PathVariable("weatherId") Long regionId) {
return ResponseDto.ok(userService.getVoteHistoriesByUser(regionId));
}

//4-2. 모아 보기(상세)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/snowthon/snowman/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.snowthon.snowman.domain;


import com.snowthon.snowman.contrant.Constants;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,6 +23,9 @@ public class User {
@Column(name = "serial_id", nullable = false, unique = true)
private Long serialId;

@Column(name = "nickname", nullable = false)
private String nickname;

@Column(name = "refresh_token")
private String refreshToken;

Expand All @@ -37,6 +41,7 @@ public User(Long serialId) {
this.serialId = serialId;
this.isLogin = true;
this.createdAt = LocalDateTime.now();
this.nickname = Constants.USER_NICKNAME_PREFIX + serialId;
}

public static User signUp(Long serialId) {
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/snowthon/snowman/domain/VoteHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public class VoteHistory {
@Column(name = "id")
private Long id;

@Column(name="nickname", nullable = false)
private String nickname;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="user_id", nullable = false)
private User user;
@JoinColumn(name="region_id", nullable = false)
private Region region;

@Column(name = "location", nullable = false)
private String location;
Expand Down Expand Up @@ -64,8 +67,9 @@ public class VoteHistory {
private LocalDateTime voteTime;

@Builder
public VoteHistory(User user, String location, String code, ETopWear topWear, EOuterWear outerWear, EHeadWear headWear, ENeckWear neckWear, ESky sky, int temperature, LocalDateTime voteTime) {
this.user = user;
public VoteHistory(Region region,String nickname, String location, String code, ETopWear topWear, EOuterWear outerWear, EHeadWear headWear, ENeckWear neckWear, ESky sky, int temperature, LocalDateTime voteTime) {
this.region = region;
this.nickname = nickname;
this.location = location;
this.code = code;
this.topWear = topWear;
Expand All @@ -78,9 +82,10 @@ public VoteHistory(User user, String location, String code, ETopWear topWear, EO
}

//투표를 저장할 때 사용
public static VoteHistory createFrom(User user, Region region, Branch mainBranch, ETopWear topWear, EOuterWear outerWear, EHeadWear headWear, ENeckWear neckWear) {
public static VoteHistory createFrom(Region region, String nickname, Branch mainBranch, ETopWear topWear, EOuterWear outerWear, EHeadWear headWear, ENeckWear neckWear) {
return VoteHistory.builder()
.user(user)
.region(region)
.nickname(nickname)
.location(region.getLocation())
.code(region.getCode())
.temperature(mainBranch.getTemperature())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@

@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ArchivingDto{

@JsonProperty("voteHistoryList") @Schema(description = "투표 내역 리스트")
private List<ArchivingDetailDto> voteHistoryList;

@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class ArchivingDetailDto {
@JsonProperty("archive_id") @Schema(description = "아카이브 아이디", example = "1")
@NotNull(message = "이름은 필수입니다.")
private Long archiveId;

@JsonProperty("nickname") @Schema(description = "닉네임", example = "pengdolli_2310121")
@NotNull(message = "닉네임은 필수입니다.")
private String nickname;

@JsonProperty("topWear") @Schema(description = "상의 정보", example = "LONG_SLEEVE")
@NotNull(message = "topWear는 필수입니다.")
private ETopWear topWear;
Expand Down Expand Up @@ -67,8 +69,9 @@ public static class ArchivingDetailDto {
private String voteTime;

@Builder
public ArchivingDetailDto(Long archiveId, ETopWear topWear, EOuterWear outerWear, EHeadWear headWear, ENeckWear neckWear, ESky weatherStatus, int temperature, String location, String voteTime) {
public ArchivingDetailDto(Long archiveId, String nickname ,ETopWear topWear, EOuterWear outerWear, EHeadWear headWear, ENeckWear neckWear, ESky weatherStatus, int temperature, String location, String voteTime) {
this.archiveId = archiveId;
this.nickname = nickname;
this.topWear = topWear;
this.outerWear = outerWear;
this.headWear = headWear;
Expand All @@ -82,6 +85,7 @@ public ArchivingDetailDto(Long archiveId, ETopWear topWear, EOuterWear outerWear
public static ArchivingDetailDto fromEntity(VoteHistory voteHistory) {
return ArchivingDetailDto.builder()
.archiveId(voteHistory.getId())
.nickname(voteHistory.getNickname())
.topWear(voteHistory.getTopWear())
.outerWear(voteHistory.getOuterWear())
.headWear(voteHistory.getHeadWear())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
@Repository
public interface VoteHistoryRepository extends JpaRepository<VoteHistory, Long> {
List<VoteHistory> findByUserId(Long userId);

List<VoteHistory> findByRegionId(Long regionId);
}
6 changes: 3 additions & 3 deletions src/main/java/com/snowthon/snowman/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public User saveUser(User user) {
}

//4-1. 모아 보기
public ArchivingDto getVoteHistoriesByUser(Long userId) {
List<VoteHistory> voteHistories = voteHistoryRepository.findByUserId(userId);
return ArchivingDto.fromEntity(voteHistories.stream()
public ArchivingDto getVoteHistoriesByUser(Long regionId) {
List<VoteHistory> voteHistoryList = voteHistoryRepository.findByRegionId(regionId);
return ArchivingDto.fromEntity(voteHistoryList.stream()
.map(ArchivingDto.ArchivingDetailDto::fromEntity).collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void createVote(Long regionId, VoteRequestDto voteInfoDto, Long userId) {
);

VoteHistory voteHistory = VoteHistory.createFrom(
user, region, mainBranch,
region, user.getNickname(),mainBranch,
ETopWear.valueOf(voteInfoDto.topWear()),
EOuterWear.valueOf(voteInfoDto.outerWear()),
EHeadWear.valueOf(voteInfoDto.headWear()),
Expand Down

0 comments on commit 27a4e85

Please sign in to comment.