release-音乐人-成员 绑定/解绑接口

release-2024-08-08
pikaqiudeshujia 9 months ago
parent 29bb05994a
commit 74b530fedb

@ -2,6 +2,7 @@ package com.luoo.user.controller;
import api.Result;
import com.luoo.user.dto.ArtistRegisterDto;
import com.luoo.user.dto.ArtistUserBindDto;
import com.luoo.user.service.ArtistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -37,4 +38,16 @@ public class ArtistController {
return Result.success();
}
@ApiOperation(value = "音乐人-成员绑定", notes = "音乐人-成员绑定")
public Result<Void> memberBind(@ApiParam(value = "绑定对象",required = true) @Valid @RequestBody ArtistUserBindDto artistUserBindDto) {
artistService.bindArtistAndMember(artistUserBindDto);
return Result.success();
}
@ApiOperation(value = "音乐人-成员解绑", notes = "音乐人-成员解绑")
public Result<Void> memberUnBind(@ApiParam(value = "解绑对象",required = true) @Valid @RequestBody ArtistUserBindDto artistUserBindDto) {
artistService.unBindArtistAndMember(artistUserBindDto);
return Result.success();
}
}

@ -0,0 +1,19 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.ArtistUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dao
* @Project: luoo_parent
* @Date: 2024/4/25 16:02
* @Filename: ArtistUserDao
* @Describe:
*/
public interface ArtistUserDao extends JpaRepository<ArtistUser,String>, JpaSpecificationExecutor<ArtistUser> {
public ArtistUser findArtistUserByArtistIdAndUserId(String artist, String userId);
}

@ -0,0 +1,28 @@
package com.luoo.user.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dto
* @Project: luoo_parent
* @Date: 2024/4/25 16:06
* @Filename: ArtistUserBindDto
* @Describe: /
*/
@Data
public class ArtistUserBindDto implements Serializable {
@ApiModelProperty(name = "音乐人id")
@NotNull(message = "音乐人id必填")
private String artistId;
@ApiModelProperty(name = "成员id")
@NotNull(message = "成员id必填")
private String UserId;
}

@ -0,0 +1,37 @@
package com.luoo.user.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.pojo
* @Project: luoo_parent
* @Date: 2024/4/25 15:53
* @Filename: ArtistUser
* @Describe:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Builder
@Entity
@Table(name="tb_artist_user")
public class ArtistUser implements Serializable {
@Id
@ApiModelProperty("id")
private String id;
@ApiModelProperty("音乐人id")
private String artistId;
@ApiModelProperty("成员id")
private String userId;
}

@ -1,11 +1,11 @@
package com.luoo.user.service;
import com.luoo.user.dao.ArtistInfoDao;
import com.luoo.user.dao.ArtistResponsibleDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dao.*;
import com.luoo.user.dto.ArtistRegisterDto;
import com.luoo.user.dto.ArtistUserBindDto;
import com.luoo.user.pojo.ArtistInfo;
import com.luoo.user.pojo.ArtistResponsible;
import com.luoo.user.pojo.ArtistUser;
import com.luoo.user.pojo.UserInfo;
import constants.Constants;
import enums.UserStatusEnum;
@ -48,6 +48,9 @@ public class ArtistService {
@Autowired
private BCryptPasswordEncoder encoder;
@Autowired
private ArtistUserDao artistUserDao;
/**
*
*
@ -97,5 +100,40 @@ public class ArtistService {
}
/**
* -
*
* @param artistUserBindDto
*/
@Transactional(rollbackFor = Exception.class)
public void bindArtistAndMember(ArtistUserBindDto artistUserBindDto) {
ArtistUser artistUser = artistUserDao.findArtistUserByArtistIdAndUserId(artistUserBindDto.getArtistId(), artistUserBindDto.getUserId());
if(artistUser == null) {
ArtistUser build = ArtistUser.builder()
.id(String.valueOf(idWorker.nextId()))
.artistId(artistUserBindDto.getArtistId())
.userId(artistUser.getUserId())
.build();
artistUserDao.save(build);
} else {
throw new RuntimeException("请勿重复绑定!");
}
}
/**
* -
* @param artistUserBindDto
*/
public void unBindArtistAndMember(ArtistUserBindDto artistUserBindDto) {
ArtistUser artistUser = artistUserDao.findArtistUserByArtistIdAndUserId(artistUserBindDto.getArtistId(), artistUserBindDto.getUserId());
if(artistUser != null) {
artistUserDao.delete(artistUser);
} else {
throw new RuntimeException("没有绑定关系!");
}
}
}

Loading…
Cancel
Save